mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
Add typings for circular-json
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/// <reference path="circular-json.d.ts" />
|
||||
|
||||
import CircularJSON = require('circular-json');
|
||||
|
||||
var replacer = (key: any, val: any) => {
|
||||
return val;
|
||||
}
|
||||
|
||||
var replacerArray = ['a', 'x'];
|
||||
|
||||
// implements JSON interface
|
||||
var json_obj: JSON = CircularJSON;
|
||||
|
||||
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);
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// Type definitions for circular-json v0.1.6
|
||||
// Project: https://github.com/WebReflection/circular-json
|
||||
// Definitions by: Jonathan Pevarnek <https://github.com/jpevarnek/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module 'circular-json' {
|
||||
interface ICircularJSON extends JSON {
|
||||
parse(text: string, reviver?: (key: any, value: any) => any): any;
|
||||
stringify(value: any, replacer?: ((key: string, value: any) => any) | any[], space?: any, placeholder?: boolean): string;
|
||||
}
|
||||
|
||||
var CircularJSON: ICircularJSON;
|
||||
|
||||
export = CircularJSON;
|
||||
}
|
||||
Reference in New Issue
Block a user