[fast-json-stable-stringify] Add types

This commit is contained in:
Dimitri Benin
2018-12-24 16:18:24 +01:00
parent 42e3741a35
commit 72b9ecabd9
4 changed files with 66 additions and 0 deletions

View File

@@ -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

View File

@@ -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 <https://github.com/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;
}
}

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }