Corbie

Plugins

yaml

This plugin parses a YAML document into data and writes data as YAML.

yaml.parse(document)returns the document's data yaml.write(data)returns the data as a YAML document

document is text, bytes or a blob, and holds one YAML document.

  • parse gives maps, lists, text, numbers, true or false, and null.
  • A value YAML would read as a date or a time stays the text written.
  • An alias gives a copy of what its anchor marks. A merge key, <<, is an ordinary key.
  • write writes a map's keys in order, with an indent of two spaces, and puts text in quotes where it would otherwise read as another value.

Errors:

  bad_input   the document is not YAML (the message gives the line), it holds
              more than one document, or a key is a map, a list or written
              twice; or write was given something that is not plain data

Needs nothing.

This script reads a document and writes another.

const part = yaml.parse("does: The weather.\ntools:\n  forecast: { args: {} }\n")
part.does                    // gives "The weather."
Object.keys(part.tools)      // gives ["forecast"]

yaml.write({ name: "tea", sizes: [1, 2], hot: "true" })
// gives "hot: \"true\"\nname: tea\nsizes:\n  - 1\n  - 2\n"