Documentation
¶
Overview ¶
SPDX-License-Identifier: Apache-2.0 Deterministic JSON that is byte-identical to the Node reference implementation.
src/core/util.mjs writes every record with stableStringify: JSON.stringify of a value whose object keys have been sorted, two-space indent, trailing newline. Matching that exactly is what lets a .fridge/ written by this binary be read, rewritten and diffed by the Node CLI without churn, so this file reimplements JSON.stringify's number formatting and string escaping rather than leaning on encoding/json, whose HTML escaping and float formatting differ.
Index ¶
- func Compact(v any) string
- func FormatNumber(f float64) string
- func Indent(v any, ord Ordering) string
- func LessUTF16(a, b string) bool
- func Normalize(v any) any
- func Parse(data []byte) (any, error)
- func Stable(v any) string
- type Arr
- type Obj
- func (o Obj) ArrAt(dotted string) Arr
- func (o Obj) Bool(dotted string) bool
- func (o Obj) Clone() Obj
- func (o Obj) Get(dotted string) any
- func (o Obj) Int(dotted string) int
- func (o Obj) Num(dotted string) float64
- func (o Obj) ObjAt(dotted string) Obj
- func (o Obj) Set(dotted string, value any) error
- func (o Obj) Str(dotted string) string
- func (o Obj) Strings(dotted string) []string
- func (o Obj) With(fields Obj) Obj
- type Ordering
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compact ¶
Compact renders a value with no indentation and no trailing newline, the equivalent of JSON.stringify(value) after key sorting.
func FormatNumber ¶
FormatNumber implements the ECMAScript Number::toString algorithm, which is what JSON.stringify uses. Go's %g would print 1e+21 as 1e+21 but 100000 as 100000 with different thresholds, so the rules are spelled out here.
func Indent ¶
Indent renders a value the way JSON.stringify(value, null, 2) does, with no trailing newline and with the key order the Ordering supplies. It exists so that human-facing text can reproduce the Node writer's insertion order.
func LessUTF16 ¶
LessUTF16 orders strings the way Array.prototype.sort does, by UTF-16 code unit. For the ASCII keys this protocol uses it is plain byte order; the slow path only runs when a record carries a non-ASCII key.
func Normalize ¶
Normalize converts ordinary Go values into the small JSON value model, so callers can write Obj{"pid": 42, "include": []string{"src/**"}} directly.
Types ¶
type Obj ¶
Obj is a JSON object. Keys are sorted on the way out, never on the way in.
func DeepMerge ¶
DeepMerge layers `over` on top of `base`, recursing into objects and replacing arrays wholesale. It matches the deepMerge in src/core/store.mjs.
func (Obj) Set ¶
Set writes a value at a dotted path. It reports an error when an intermediate hop is missing or is not an object, which is what `fridge config a.b c` surfaces as E_NOT_FOUND.