From 224c116dd730b76c71d936b2b0e61267cccce122 Mon Sep 17 00:00:00 2001 From: Sam Saint-Pettersen Date: Tue, 14 Jul 2015 10:59:31 +0100 Subject: [PATCH] Type definition and tests for node cson module --- cson/cson-test.cson | 1 + cson/cson-test.json | 1 + cson/cson-tests.ts | 36 ++++++++++++++++++++++++++++++++++++ cson/cson.d.ts | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 cson/cson-test.cson create mode 100644 cson/cson-test.json create mode 100644 cson/cson-tests.ts create mode 100644 cson/cson.d.ts diff --git a/cson/cson-test.cson b/cson/cson-test.cson new file mode 100644 index 000000000..a69eb2ef5 --- /dev/null +++ b/cson/cson-test.cson @@ -0,0 +1 @@ +hello: 'world' diff --git a/cson/cson-test.json b/cson/cson-test.json new file mode 100644 index 000000000..56c8e2803 --- /dev/null +++ b/cson/cson-test.json @@ -0,0 +1 @@ +{"hello": "world"} diff --git a/cson/cson-tests.ts b/cson/cson-tests.ts new file mode 100644 index 000000000..62e7f064d --- /dev/null +++ b/cson/cson-tests.ts @@ -0,0 +1,36 @@ +/// + +import cson = require('cson'); + +var data: string = cson.stringify({hello: 'world'}); +console.log('cson.stringify => %s', data); + +data = cson.createString({hello: 'world'}); +console.log('cson.createString => %s', data); + +data = cson.createJSONString({hello: 'world'}); +console.log('cson.createJSONString => %s', data); + +data = cson.createCSONString({hello: 'world'}); +console.log('cson.createCSONString => %s', data); + +var obj: Object = cson.parse(data); +console.log('cson.parse => %s', JSON.stringify(obj)); + +obj = cson.parseCSONString(data); +console.log('cson.parseCSONString => %s', JSON.stringify(obj)); + +obj = cson.parseJSONString('{"hello": "world"}'); +console.log('cson.parseJSONString => %s', JSON.stringify(obj)); + +obj = cson.parseString("hello: 'world'"); +console.log('cson.parseString => %s', JSON.stringify(obj)); + +obj = cson.load('cson-test.cson'); +console.log('cson.load => %s', JSON.stringify(obj)); + +obj = cson.parseCSONFile('cson-test.cson'); +console.log('cson.parseCSONFile => %s', JSON.stringify(obj)); + +obj = cson.parseJSONFile('cson-test.json'); +console.log('cson.parseJSONFile => %s', JSON.stringify(obj)); diff --git a/cson/cson.d.ts b/cson/cson.d.ts new file mode 100644 index 000000000..ca7d2faed --- /dev/null +++ b/cson/cson.d.ts @@ -0,0 +1,32 @@ +// Type definitions for CSON +// Project: https://github.com/bevry/cson +// Definitions by: Sam Saint-Pettersen +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "cson" { + // Create Strings + export function stringify(data: Object, opts?: Object, indent?: any): string; + export function createCSONString(data: Object, opts?: Object, next?: any): string; + export function createJSONString(data: Object, opts?: Object, next?: any): string; + export function createString(data: Object, opts?: Object, next?: any): string; + + // Parse Strings + export function parse(data: string, opts?: Object, next?: any): Object; + export function parseCSONString(data: string, opts?: Object, next?: any): Object; + export function parseJSONString(data: string, opts?: Object, next?: any): Object; + export function parseCSString(data: string, opts?: Object, next?: any): Object; + export function parseJSString(data: string, opts?: Object, next?: any): Object; + export function parseString(data: string, opts?: Object, next?:any): Object; + + // Parse Files + export function load(filePath: string, opts?: Object, next?: any): Object; + export function parseCSONFile(filePath: string, opts?: Object, next?: any): Object; + export function parseJSONFile(filePath: string, opts?: Object, next?: any): Object; + export function parseCSFile(filePath: string, opts?: Object, next?: any): Object; + export function parseJSFile(filePath: string, opts?: Object, next?: any): Object; + + // Require Files + export function requireCSFile(filePath: string, opts?: Object, next?: any): Object; + export function requireJSFile(filePath: string, opts?: Object, next?: any): Object; + export function requireFile(filePath: string, opts?: Object, next?: any): Object; +}