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
valueas an object, if it is one.- canonical
- The canonical form two JSON documents are compared in: numbers through
number(so2.0 == 2),-0 == 0, objects and arrays recursively. - clone_
value - A deep clone through
Value(the TSJSON.parse(JSON.stringify(x))). - equal
truewhen both documents are the same in canonical form.- number
- A JS-style number: integral doubles become JSON integers (
1, not1.0), everything else stays a float.NaN/±∞becomenulllikeJSON.stringify. - number_
to_ string - JavaScript’s
String(number)(ECMAScriptNumber::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
kas 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 throughnumber_to_string, booleanstrue/false,null, arrays comma-joined, objects[object Object]. - to_
number - JavaScript’s
Number(value) || 0.