/** * vapor-chamber - the text a key or a hash is made of. Two entries, two * meanings, so neither name says more than its text does. * * `keyTextFor(outside)` - a runtime key: one text for equal values, in one * process. It returns the writer, which a caller builds once. JSON.stringify * with every object rebuilt with its keys sorted, at every level, arrays in * their order. A value JSON cannot carry exactly (a NaN, an Infinity, a * BigInt) is written as what the caller's `outside` returns: JSON.stringify * wrote NaN and Infinity as `null`, so they keyed with null * (tests/commandkey-collisions.test.ts). It is NOT RFC 8785: an object lists * keys that look like integers first, so `{ "10", "9" }` comes out as 9, 10. * That is still one text per value, which is all a key needs, and it costs * 340 B less than the exact writer in the core bundle (log 36.25). * commandKey and the HTTP client's dedupe and cache key each build one. * * `canonical(value)` - RFC 8785, the JSON Canonicalization Scheme, exactly: * for a text that crosses sides (a hash another party computes). ECMAScript's * own JSON output with these rules: no whitespace, object members sorted by * UTF-16 code units at every level (the default `sort()`), arrays in their * order, and a refusal of what I-JSON cannot carry: NaN and Infinity * (3.2.2.3), lone surrogates (3.2.2.2), BigInt. Written member by member, as * the RFC's Appendix A sample does, so "10" sorts before "9". It runs at * build time, and no bundle imports it. tests/canonical.test.ts runs the * RFC's own examples and its Appendix B number table. * * Both, as JSON.stringify: `toJSON` is honoured, a value JSON has no text for * (undefined, a function, a symbol) is left out of an object, `null` in an * array and `undefined` at the top, a Number, String, Boolean or BigInt * object is written as its value (by keyTextFor only when it has no fields of * its own, log 36.41), and a cycle throws. */ /** A caller's own text for a value JSON cannot carry exactly: a NaN, an Infinity, a BigInt. */ export type Outside = (value: number | bigint) => unknown; /** * The runtime key writer for one `outside`: one text per value, keys sorted. * Not RFC 8785 (see the module doc). Built once per caller, at module load, * so a key allocates no function (docs/V8-RULES.md rule 4). Undefined for a * value JSON has no text for (a function, a symbol). */ export declare function keyTextFor(outside: Outside): (value: unknown) => string | undefined; /** RFC 8785 exactly. Throws on NaN, Infinity, BigInt, a lone surrogate and a cycle. */ export declare function canonical(value: unknown): string; //# sourceMappingURL=canonical.d.ts.map