UNPKG

1.26 kBTypeScriptView Raw
1// Type definitions for json-stable-stringify 1.0
2// Project: https://github.com/substack/json-stable-stringify
3// Definitions by: Matt Frantz <https://github.com/mhfrantz>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6/**
7 * Deterministic version of JSON.stringify() so you can get a consistent hash from stringified results.
8 *
9 * @returns Deterministic json result.
10 */
11declare function stringify(obj: any, opts?: stringify.Comparator | stringify.Options): string;
12
13declare namespace stringify {
14 interface Element {
15 key: string;
16 value: any;
17 }
18
19 type Comparator = (a: Element, b: Element) => number;
20
21 type Replacer = (key: string, value: any) => any;
22
23 interface Options {
24 /**
25 * Custom comparator for key
26 */
27 cmp?: Comparator;
28
29 /**
30 * Indent the output for pretty-printing.
31 *
32 * Supported is either a string or a number of spaces.
33 */
34 space?: string | number;
35
36 /**
37 * Option to replace values to simpler values
38 */
39 replacer?: Replacer;
40
41 /**
42 * true to allow cycles, by marking the entries as __cycle__.
43 */
44 cycles?: boolean;
45 }
46}
47
48export = stringify;