Skip to content

Formats

How each format maps to the Document model, and what it adjusts on the way in or out. Every writer accepts a strict option (throw on any adjustment) and reports adjustments through a WriteReport (checkFoo(node) reports without writing).

FormatPageZero-adjustment?Notes
OMLOmnist's own formatYesThe only format that round-trips every Document shape exactly.
JSONformats/json.tsNoNo native date/time/datetime or NaN/Infinity -- both get adjusted on write.
YAMLformats/yaml.tsMostlyCloser to the Document model than JSON (native dates), but still has JSON-like array/scalar limits.
TOMLformats/toml.tsMostlyNo top-level scalar root; a document must be table-shaped.
XMLformats/xml.tsNoAlways single-rooted (one document element); attributes vs. elements is a modeling choice on the way in.

The shared contract

Every format module exports the same three functions:

  • readFoo(text, opts?) -- parses into a Node. Pass { schema } to upgrade value-exact leaves (ISO strings to real Dates, integer-looking numbers to the schema's declared kind) to match the schema, when the conversion is unambiguous -- see deserialize.ts's materialize.
  • writeFoo(node, opts?) -- serializes a Node to text. Pass { strict: true } to throw instead of silently adjusting; otherwise adjustments are applied and (with { report }) collected into a WriteReport.
  • checkFoo(node) -- returns the WriteReport a write would produce, without writing anything.

See the API reference for exact signatures.