std/data/toon

Standard Library documentation

Pure-Zuzu TOON codec.

Module

Name
std/data/toon
Area
Standard Library
Source
modules/std/data/toon.zzm

NAME

std/data/toon - Pure-Zuzu TOON codec.

SYNOPSIS

  from std/data/toon import TOON;

  let codec := new TOON( indent: 2 );
  let text := codec.encode({ answer: 42 });
  let data := codec.decode(text);

IMPLEMENTATION SUPPORT

This module is supported by zuzu.pl, zuzu-rust, and zuzu-js on Node and Electron. It is partially supported by zuzu-js in the browser: in-memory TOON parsing and serialization coverage passes, but fixture and load/dump coverage is unsupported because browser filesystem capability is unavailable.

DESCRIPTION

A pure ZuzuScript TOON codec with encode, decode, load, and dump.

The implementation supports:

  • object and array roots
  • inline primitive arrays and tabular/list arrays
  • delimiter declarations (comma, tab, pipe)
  • strict-mode validation for required colons

Object decoding defaults to PairLists so key order is kept.

EXPORTS

Classes

  • TOON({ indent?: Number, strict?: Boolean, delimiter?: String, pairlists?: Boolean, expandPaths?, keyFolding?, flattenDepth? })

    Constructs a TOON codec. Returns: TOON.

    • codec.decode(String text)

      Parameters: text is TOON text. Returns: value. Decodes TOON text into ZuzuScript data.

    • codec.decode_binarystring(BinaryString bytes)

      Parameters: bytes is UTF-8 TOON bytes. Returns: value. Decodes TOON bytes into ZuzuScript data.

    • codec.encode(value)

      Parameters: value is a TOON-encodable value. Returns: String. Encodes value as TOON text.

    • codec.encode_binarystring(value)

      Parameters: value is a TOON-encodable value. Returns: BinaryString. Encodes value as UTF-8 TOON bytes.

    • codec.load(Path path)

      Parameters: path is a std/io Path. Returns: value. Reads TOON text from path and decodes it.

    • codec.dump(Path path, value)

      Parameters: path is a std/io Path and value is a TOON-encodable value. Returns: null. Encodes value and writes TOON text to path.

OPTIONS

  • indent (default 2)
  • strict (default true)
  • delimiter (default comma)
  • pairlists (default true)

    Decode objects as PairLists (preserves key order). Set false to decode as Dict.

  • expandPaths, keyFolding, flattenDepth

    Accepted for API compatibility.

COPYRIGHT AND LICENCE

std/data/toon is copyright Toby Inkster.

It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.