json-stable-stringify
Version:
deterministic JSON.stringify() with custom sorting to get deterministic hashes from stringified results
25 lines (18 loc) • 757 B
TypeScript
declare namespace stableStringify {
type Key = string | number;
type NonArrayNode = Record<Key, unknown>;
type Node = unknown[] | NonArrayNode;
type Getter = { get(key: Key): unknown };
type Comparator = (a: { key: string, value: unknown }, b: { key: string, value: unknown }, getter: Getter) => number;
type StableStringifyOptions = {
cmp?: Comparator;
cycles?: boolean;
replacer?: (this: Node, key: Key, value: unknown) => unknown;
space?: string | number;
};
}
declare function stableStringify(
obj: unknown,
options?: (stableStringify.Comparator & stableStringify.StableStringifyOptions) | stableStringify.StableStringifyOptions,
): string | undefined;
export = stableStringify;