DefinitelyTyped/types/macaca-circular-json/macaca-circular-json-tests.ts
zivyangll 24b24fa197 add types for 'macaca-circular-json' (#36256)
* feat: add macaca-circular-json types

* doc: update info
2019-06-21 23:53:57 -07:00

27 lines
718 B
TypeScript

import CircularJSON = require('macaca-circular-json');
const replacer = (key: any, val: any) => {
return val;
};
const replacerArray = ['a', 'x'];
CircularJSON.parse('{"a":"b"}');
CircularJSON.parse('{"a":"b"}', replacer);
// just stringify a value
CircularJSON.stringify({a: 'b'});
// do replacements for part of the object
CircularJSON.stringify({a: 'b'}, replacer);
CircularJSON.stringify({a: 'b'}, replacerArray);
// add whitespace to the output
CircularJSON.stringify({a: 'b'}, replacer, 5);
CircularJSON.stringify({a: 'b'}, replacerArray, 5);
// do not actually set up a re-parseable object
CircularJSON.stringify({a: 'b'}, replacer, 5, true);
CircularJSON.stringify({a: 'b'}, replacerArray, 5, true);