From de5a2b86403114053c926ec03e2d6e4bbdad5e35 Mon Sep 17 00:00:00 2001 From: Jonathan Pevarnek Date: Mon, 6 Apr 2015 18:24:43 -0400 Subject: [PATCH] Add typings for circular-json --- circular-json/circular-json-tests.ts | 31 ++++++++++++++++++++++++++++ circular-json/circular-json.d.ts | 15 ++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 circular-json/circular-json-tests.ts create mode 100644 circular-json/circular-json.d.ts diff --git a/circular-json/circular-json-tests.ts b/circular-json/circular-json-tests.ts new file mode 100644 index 0000000000..d3f2e0951c --- /dev/null +++ b/circular-json/circular-json-tests.ts @@ -0,0 +1,31 @@ +/// + +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); diff --git a/circular-json/circular-json.d.ts b/circular-json/circular-json.d.ts new file mode 100644 index 0000000000..2aa27e947a --- /dev/null +++ b/circular-json/circular-json.d.ts @@ -0,0 +1,15 @@ +// Type definitions for circular-json v0.1.6 +// Project: https://github.com/WebReflection/circular-json +// Definitions by: Jonathan Pevarnek +// 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; +}