Skip to content

parse

parse(text): unknown

Defined in: src/index.ts:515

Parse a single YAML document into a JavaScript value.

Reads exactly one document — like JSON.parse and js-yaml’s load. If text contains more than one ----separated document (or any trailing content after the first), parse throws rather than silently returning the first; use parseAll for multi-document streams. Plain scalars are typed per the YAML 1.2 core schema (1 is a number, true a boolean, null/~/empty a null); an empty document is null.

string

The YAML source text.

unknown

The document’s value: an object, array, string, number, boolean, or null.

YAMLParseError if text is not well-formed YAML, or contains more than one document.

parse("dish: pancakes\nserves: 4")
// { dish: "pancakes", serves: 4 }