From 870a8af6495d1c7cf75c906148a7005972cad819 Mon Sep 17 00:00:00 2001 From: Shantanu Bhadoria Date: Wed, 12 Oct 2016 16:58:46 +0800 Subject: [PATCH 1/3] Adding my first EJSON d.ts file, Will test against my own setup first before creating a merge request --- ejson/ejson-tests.ts | 0 ejson/ejson.d.ts | 8 ++++++++ 2 files changed, 8 insertions(+) create mode 100644 ejson/ejson-tests.ts create mode 100644 ejson/ejson.d.ts diff --git a/ejson/ejson-tests.ts b/ejson/ejson-tests.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ejson/ejson.d.ts b/ejson/ejson.d.ts new file mode 100644 index 0000000000..66a42b824b --- /dev/null +++ b/ejson/ejson.d.ts @@ -0,0 +1,8 @@ +// Type definitions for ejson v2.1.2 +// Project: https://www.npmjs.com/package/ejson +// Definitions by: Shantanu Bhadoria +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "EJSON" { + function stringify(): string; +} From 38b0ab033953b92635364f23ab03f9598d48fbc2 Mon Sep 17 00:00:00 2001 From: Shantanu Bhadoria Date: Wed, 12 Oct 2016 18:21:37 +0800 Subject: [PATCH 2/3] Finished tests, pre-merge-request commit for EJSON types --- ejson/ejson-tests.ts | 57 ++++++++++++++++++++++++++++++++++++++++++++ ejson/ejson.d.ts | 20 ++++++++++++++-- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/ejson/ejson-tests.ts b/ejson/ejson-tests.ts index e69de29bb2..ef9b940bb8 100644 --- a/ejson/ejson-tests.ts +++ b/ejson/ejson-tests.ts @@ -0,0 +1,57 @@ +/// + +import { + clone as importedClone, + parse as importedParse, + stringify as importedStringify, + toJSONValue as importedToJSONValue, + fromJSONValue as importedFromJSONValue, + isBinary as importedIsBinary, + newBinary as importedNewBinary, + equals as importedEquals +} from "ejson"; + +function testImportedClone() { + var obj: Object = { + a: "a" + }; + var retval: Object = importedClone(obj); + + var str: string = "as"; + var retval2: string = importedClone(str); +} + +function testParse() { + var str: string = '{a:"a"}'; + importedParse(str); +} + +function testStringify() { + var obj: any = {a:"a"}; + var retval: string = importedStringify(obj); +} + +function testToJSONValue() { + var obj: any = {a:"a"}; + var retval: string = importedToJSONValue(obj); +} + +function testFromJSONValue() { + var str: string = '{a:"a"}'; + importedFromJSONValue(str); +} + +function testIsBinary() { + var val: any = 'sasda'; + var retval: boolean = importedIsBinary(val); +} + +function testNewBinary() { + var retval: Uint8Array = importedNewBinary(3); +} + +function testEquals() { + var a: any; + var b: any; + var retval: boolean = importedEquals(a,b); +} \ No newline at end of file diff --git a/ejson/ejson.d.ts b/ejson/ejson.d.ts index 66a42b824b..51e54b7503 100644 --- a/ejson/ejson.d.ts +++ b/ejson/ejson.d.ts @@ -3,6 +3,22 @@ // Definitions by: Shantanu Bhadoria // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module "EJSON" { - function stringify(): string; +declare interface IStringifyOptions { + canonical: boolean; + indent: boolean|number|string; +} +declare interface ICloneOptions { + keyOrderSensitive: boolean; +} + +declare module "ejson" { + function clone(obj: T): T; + function parse(str: string): any; + function stringify(obj: any, options?: IStringifyOptions): string; + + function toJSONValue(obj: any): string; + function fromJSONValue(obj: string): any; + function isBinary(value: any): boolean; + function newBinary(len: number): Uint8Array; + function equals(a: any, b: any, options?: ICloneOptions): boolean; } From 0ffa9c0f32fba32f61a2516dd2438fad537ba577 Mon Sep 17 00:00:00 2001 From: Shantanu Bhadoria Date: Fri, 14 Oct 2016 12:41:30 +0800 Subject: [PATCH 3/3] refactored as per best practices --- ejson/ejson.d.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ejson/ejson.d.ts b/ejson/ejson.d.ts index 51e54b7503..029222239c 100644 --- a/ejson/ejson.d.ts +++ b/ejson/ejson.d.ts @@ -3,22 +3,24 @@ // Definitions by: Shantanu Bhadoria // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare interface IStringifyOptions { - canonical: boolean; - indent: boolean|number|string; -} -declare interface ICloneOptions { - keyOrderSensitive: boolean; -} declare module "ejson" { + interface StringifyOptions { + canonical: boolean; + indent: boolean|number|string; + } + + interface CloneOptions { + keyOrderSensitive: boolean; + } + function clone(obj: T): T; function parse(str: string): any; - function stringify(obj: any, options?: IStringifyOptions): string; + function stringify(obj: any, options?: StringifyOptions): string; function toJSONValue(obj: any): string; function fromJSONValue(obj: string): any; function isBinary(value: any): boolean; function newBinary(len: number): Uint8Array; - function equals(a: any, b: any, options?: ICloneOptions): boolean; + function equals(a: any, b: any, options?: CloneOptions): boolean; }