Docs → Helper Functions
🧰
TOON Helper Functions
Complete reference for runtime and utility helpers.
safeParse()
safeParse(value: string)Parses valid JSON and returns the original string unchanged when the input is not valid JSON.
safeParse()
safeParse('{"ok":true}') // { ok: true }
safeParse('plain text') // 'plain text'toon.toToon()
toon.toToon(value)Serializes a tagged runtime value or ordinary JavaScript object into canonical TOON text.
toon.toToon()
const output = toon.toToon(employees);
toJSON()
value.toJSON() or toon.toJSON(value)Returns a plain JavaScript clone without runtime metadata, suitable for storage or JSON.stringify.
toJSON()
const plain = employees.toJSON(); const copy = toon.toJSON(employees);
toon.clone()
toon.clone(value)Creates an independent deep clone. Changes to the clone do not modify the original value.
toon.clone()
const copy = toon.clone(employees); copy[0].salary = 1;
toon.equals()
toon.equals(a, b)Compares arrays, objects, and primitive values using structural equality.
toon.equals()
toon.equals({ id: 1 }, { id: 1 }); // true