Skip to main content

Module json

Module json 

Source
Expand description

JSON helpers shared by the reducer, the expander and the theme resolver: the JavaScript number model (one double; integral values print without a fraction) and a canonical form for byte-for-byte fixture comparisons.

Functions§

as_f64
Every number as f64.
as_obj
value as an object, if it is one.
canonical
The canonical form two JSON documents are compared in: numbers through number (so 2.0 == 2), -0 == 0, objects and arrays recursively.
clone_value
A deep clone through Value (the TS JSON.parse(JSON.stringify(x))).
equal
true when both documents are the same in canonical form.
number
A JS-style number: integral doubles become JSON integers (1, not 1.0), everything else stays a float. NaN/±∞ become null like JSON.stringify.
number_to_string
JavaScript’s String(number) (ECMAScript Number::toString): the shortest round-trip digits, plain from 1e-6 up to 1e21, exponent form (1e-7, 1e+21) outside; -0 → 0, NaN, Infinity.
obj
The empty object.
str_of
The object’s key k as a &str.
strict_eq
JavaScript === over JSON values (numbers by value, no coercion).
to_js_string
JavaScript’s String(value) for the scalar values a template may interpolate: strings verbatim, numbers through number_to_string, booleans true/false, null, arrays comma-joined, objects [object Object].
to_number
JavaScript’s Number(value) || 0.