File: index.d.ts

package info (click to toggle)
node-json-stable-stringify 1.0.2%2B~cs5.2.34-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 312 kB
  • sloc: javascript: 505; makefile: 5
file content (48 lines) | stat: -rwxr-xr-x 1,258 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Type definitions for json-stable-stringify 1.0
// Project: https://github.com/substack/json-stable-stringify
// Definitions by: Matt Frantz <https://github.com/mhfrantz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/**
 * Deterministic version of JSON.stringify() so you can get a consistent hash from stringified results.
 *
 * @returns Deterministic json result.
 */
declare function stringify(obj: any, opts?: stringify.Comparator | stringify.Options): string;

declare namespace stringify {
    interface Element {
        key: string;
        value: any;
    }

    type Comparator = (a: Element, b: Element) => number;

    type Replacer = (key: string, value: any) => any;

    interface Options {
        /**
         * Custom comparator for key
         */
        cmp?: Comparator;

        /**
         * Indent the output for pretty-printing.
         *
         * Supported is either a string or a number of spaces.
         */
        space?: string | number;

        /**
         * Option to replace values to simpler values
         */
        replacer?: Replacer;

        /**
         * true to allow cycles, by marking the entries as __cycle__.
         */
        cycles?: boolean;
    }
}

export = stringify;