From 72b9ecabd9c949fa2b2a2dd76ab80417783774cc Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Mon, 24 Dec 2018 16:18:24 +0100 Subject: [PATCH] [fast-json-stable-stringify] Add types --- .../fast-json-stable-stringify-tests.ts | 20 ++++++++++++++++ types/fast-json-stable-stringify/index.d.ts | 22 ++++++++++++++++++ .../fast-json-stable-stringify/tsconfig.json | 23 +++++++++++++++++++ types/fast-json-stable-stringify/tslint.json | 1 + 4 files changed, 66 insertions(+) create mode 100644 types/fast-json-stable-stringify/fast-json-stable-stringify-tests.ts create mode 100644 types/fast-json-stable-stringify/index.d.ts create mode 100644 types/fast-json-stable-stringify/tsconfig.json create mode 100644 types/fast-json-stable-stringify/tslint.json diff --git a/types/fast-json-stable-stringify/fast-json-stable-stringify-tests.ts b/types/fast-json-stable-stringify/fast-json-stable-stringify-tests.ts new file mode 100644 index 0000000000..72aa054cf1 --- /dev/null +++ b/types/fast-json-stable-stringify/fast-json-stable-stringify-tests.ts @@ -0,0 +1,20 @@ +import stringify = require('fast-json-stable-stringify'); + +const obj = { c: 8, b: [{ z: 6, y: 5, x: 4 }, 7], a: 3 }; + +stringify(obj); // $ExpectType string +// $ExpectType string +stringify(obj, (a, b) => { + a; // $ExpectType CompareDescriptor + b; // $ExpectType CompareDescriptor + return a.key < b.key ? 1 : -1; +}); +// $ExpectType string +stringify(obj, { + cmp(a, b) { + a; // $ExpectType CompareDescriptor + b; // $ExpectType CompareDescriptor + return a.key < b.key ? 1 : -1; + }, +}); +stringify(obj, { cycles: true }); // $ExpectType string diff --git a/types/fast-json-stable-stringify/index.d.ts b/types/fast-json-stable-stringify/index.d.ts new file mode 100644 index 0000000000..be89dd7567 --- /dev/null +++ b/types/fast-json-stable-stringify/index.d.ts @@ -0,0 +1,22 @@ +// Type definitions for fast-json-stable-stringify 2.0 +// Project: https://github.com/epoberezkin/fast-json-stable-stringify +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = stringify; + +declare function stringify(obj: any, options?: stringify.Options | stringify.Comparator): string; + +declare namespace stringify { + interface Options { + cmp?: (a: CompareDescriptor, b: CompareDescriptor) => number; + cycles?: boolean; + } + + type Comparator = (a: CompareDescriptor, b: CompareDescriptor) => number; + + interface CompareDescriptor { + key: string; + value: any; + } +} diff --git a/types/fast-json-stable-stringify/tsconfig.json b/types/fast-json-stable-stringify/tsconfig.json new file mode 100644 index 0000000000..09bc433bc5 --- /dev/null +++ b/types/fast-json-stable-stringify/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "fast-json-stable-stringify-tests.ts" + ] +} diff --git a/types/fast-json-stable-stringify/tslint.json b/types/fast-json-stable-stringify/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/fast-json-stable-stringify/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }