mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-06 06:19:58 +08:00
[json-stringify-safe] add typings (#19026)
This commit is contained in:
committed by
Mohamed Hegazy
parent
e395189807
commit
b7b8a3650b
14
types/json-stringify-safe/index.d.ts
vendored
Normal file
14
types/json-stringify-safe/index.d.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// Type definitions for json-stringify-safe 5.0
|
||||
// Project: https://github.com/isaacs/json-stringify-safe
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export = stringify;
|
||||
|
||||
declare function stringify(obj: any, serializer?: stringify.EntryProcessor | null, indent?: string | number | null, decycler?: stringify.EntryProcessor): string;
|
||||
|
||||
declare namespace stringify {
|
||||
function getSerialize(serializer: EntryProcessor | null, decycler?: EntryProcessor): EntryProcessor;
|
||||
|
||||
type EntryProcessor = (key: string, value: any) => any;
|
||||
}
|
||||
39
types/json-stringify-safe/json-stringify-safe-tests.ts
Normal file
39
types/json-stringify-safe/json-stringify-safe-tests.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import stringify = require('json-stringify-safe');
|
||||
|
||||
interface CircularObj {
|
||||
circularRef?: CircularObj;
|
||||
list?: CircularObj[];
|
||||
}
|
||||
|
||||
const circularObj: CircularObj = {};
|
||||
circularObj.circularRef = circularObj;
|
||||
circularObj.list = [circularObj, circularObj];
|
||||
|
||||
stringify(circularObj);
|
||||
stringify(circularObj, null);
|
||||
stringify(circularObj, null, 2);
|
||||
stringify(circularObj, null, null, () => {});
|
||||
stringify(circularObj, (key, val) => {
|
||||
key; // $ExpectType string
|
||||
val; // $ExpectType any
|
||||
}, null, (key, val) => {
|
||||
key; // $ExpectType string
|
||||
val; // $ExpectType any
|
||||
});
|
||||
|
||||
// $ExpectType EntryProcessor
|
||||
stringify.getSerialize(null, (key, val) => {
|
||||
key; // $ExpectType string
|
||||
val; // $ExpectType any
|
||||
});
|
||||
stringify.getSerialize((key, val) => {
|
||||
key; // $ExpectType string
|
||||
val; // $ExpectType any
|
||||
});
|
||||
stringify.getSerialize((key, val) => {
|
||||
key; // $ExpectType string
|
||||
val; // $ExpectType any
|
||||
}, (key, val) => {
|
||||
key; // $ExpectType string
|
||||
val; // $ExpectType any
|
||||
});
|
||||
22
types/json-stringify-safe/tsconfig.json
Normal file
22
types/json-stringify-safe/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"json-stringify-safe-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/json-stringify-safe/tslint.json
Normal file
1
types/json-stringify-safe/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user