Add typings for circular-json

This commit is contained in:
Jonathan Pevarnek
2015-04-07 11:55:17 -04:00
parent 65ea56c919
commit de5a2b8640
2 changed files with 46 additions and 0 deletions
+31
View File
@@ -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);
+15
View File
@@ -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;
}