std/data/yaml

Standard Library documentation

YAML encoding and decoding for ZuzuScript.

Module

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

NAME

std/data/yaml - YAML encoding and decoding for ZuzuScript.

SYNOPSIS

  from std/data/yaml import YAML;

  let codec := new YAML( pretty: true, canonical: true );
  let text := codec.encode({ answer: 42, ok: true });
  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 YAML encode/decode coverage passes, but file-backed load/dump coverage is unsupported because browser filesystem capability is unavailable.

DESCRIPTION

This module provides a YAML class for turning ZuzuScript values into YAML text and parsing YAML text back into ZuzuScript values.

EXPORTS

Classes

  • YAML({ utf8?: Bool, pretty?: Bool, canonical?: Bool })

    Constructs a YAML codec. Returns: YAML.

    The constructor accepts named options:

    • utf8 (default true)

      Accepted for API compatibility with std/data/json and std/data/toml.

    • pretty (default false)

      Keep the final trailing newline generated by the emitter.

    • canonical (default false)

      Accepted for API compatibility with std/data/json and std/data/toml.

  • codec.encode(value)

    Parameters: value is any YAML-encodable ZuzuScript value. Returns: String. Encodes value as YAML text.

  • codec.encode_binarystring(value)

    Parameters: value is any YAML-encodable ZuzuScript value. Returns: BinaryString. Encodes value as UTF-8 YAML bytes.

  • codec.decode(String yaml)

    Parameters: yaml is YAML text. Returns: value. Decodes YAML into the equivalent ZuzuScript value.

  • codec.decode_binarystring(BinaryString yaml)

    Parameters: yaml is UTF-8 YAML bytes. Returns: value. Decodes YAML into the equivalent ZuzuScript value.

  • codec.load(Path path)

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

  • codec.dump(Path path, value)

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

COPYRIGHT AND LICENCE

std/data/yaml 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.