Default prefix for anchors.
Default: 'a'
, resulting in anchors a1
, a2
, etc.
Force the top-level collection node to use flow style.
Keep undefined
object values when creating mappings, rather than
discarding them.
Default: false
Specify the top-level collection type, e.g. "!!omap"
. Note that this
requires the corresponding tag to be available in this document's schema.
Control the logging level during parsing
Default: 'warn'
The YAML version used by documents without a %YAML
directive.
Default: "1.2"
Whether integers should be parsed into BigInt rather than number values.
Include a srcToken
value on each parsed Node
, containing the CST token
that was composed into this node.
Default: false
If set, newlines will be tracked, to allow for lineCounter.linePos(offset)
to provide the { line, col }
positions within the input.
Include line/col position & node type directly in parse errors.
Default: true
Detect and report errors that are required by the YAML 1.2 spec, but are caused by unambiguous content.
Default: true
YAML requires map keys to be unique. By default, this is checked by
comparing scalar values with ===
; deep equality is not checked for
aliases or collections. If merge keys are enabled by the schema,
multiple <<
keys are allowed.
Set false
to disable, or provide your own comparator function to
customise. The comparator will be passed two ParsedNode
values, and
is expected to return a boolean
indicating their equality.
Default: true
When parsing, warn about compatibility issues with the given schema.
When stringifying, use scalar styles that are parsed correctly
by the compat
schema as well as the actual schema.
Default: null
Array of additional tags to include in the schema, or a function that may modify the schema's base tag array.
Enable support for <<
merge keys.
Default: false
for YAML 1.2, true
for earlier versions
When using the 'core'
schema, support parsing values with these
explicit YAML 1.1 tags:
!!binary
, !!omap
, !!pairs
, !!set
, !!timestamp
.
Default true
The base schema to use.
The core library has built-in support for the following:
'failsafe'
: A minimal schema that parses all scalars as strings'core'
: The YAML 1.2 core schema'json'
: The YAML 1.2 JSON schema, with minimal rules for JSON compatibility'yaml-1.1'
: The YAML 1.1 schemaIf using another (custom) schema, the customTags
array needs to
fully define the schema's tags.
Default: 'core'
for YAML 1.2, 'yaml-1.1'
for earlier versions
When adding to or stringifying a map, sort the entries.
If true
, sort by comparing key values with <
.
Does not affect item order when parsing.
Default: false
Override default values for toString()
options.
Use Map rather than Object to represent mappings.
Default: false
Prevent exponential entity expansion attacks by limiting data aliasing count;
set to -1
to disable checks; 0
disallows all alias nodes.
Default: 100
Optional function that may filter or modify the output JS value
If defined, called with the resolved value
and reference count
for
each anchor in the document.
Use block quote styles for scalar values where applicable.
Set to false
to disable block quotes completely.
Default: true
Enforce 'block'
or 'flow'
style on maps and sequences.
Empty collections will always be stringified as {}
or []
.
Default: 'any'
, allowing each node to set its style separately
with its flow: boolean
(default false
) property.
The default type of string literal used to stringify implicit key values. Output may use other types if required to fully represent the value.
If null
, the value of defaultStringType
is used.
Default: null
The default type of string literal used to stringify values in general. Output may use other types if required to fully represent the value.
Default: 'PLAIN'
Include directives in the output.
true
, at least the document-start marker ---
is always included.
This does not force the %YAML
directive to be included. To do that,
set doc.directives.yaml.explicit = true
.false
, no directives or marker is ever included. If using the %TAG
directive, you are expected to include it manually in the stream before
its use.null
, directives and marker may be included if required.Default: null
Restrict double-quoted strings to use JSON-compatible syntax.
Default: false
Minimum length for double-quoted strings to use multiple lines to
represent the value. Ignored if doubleQuotedAsJSON
is set.
Default: 40
String representation for false
.
With the core schema, use 'false'
, 'False'
, or 'FALSE'
.
Default: 'false'
When true, a single space of padding will be added inside the delimiters of non-empty single-line flow collections.
Default: true
The number of spaces to use when indenting code.
Default: 2
Whether block sequences should be indented.
Default: true
Maximum line width (set to 0
to disable folding).
This is a soft limit, as only double-quoted semantics allow for inserting
a line break in the middle of a word, as well as being influenced by the
minContentWidth
option.
Default: 80
Minimum line width for highly-indented content (set to 0
to disable).
Default: 20
String representation for null
.
With the core schema, use 'null'
, 'Null'
, 'NULL'
, '~'
, or an empty
string ''
.
Default: 'null'
Require keys to be scalars and to use implicit rather than explicit notation.
Default: false
Use 'single quote' rather than "double quote" where applicable.
Set to false
to disable single quotes completely.
Default: null
String representation for true
.
With the core schema, use 'true'
, 'True'
, or 'TRUE'
.
Default: 'true'
The anchor used by an alias must be defined before the alias node. As it's possible for the document to be modified manually, the order may be verified during stringification.
Default: 'true'
Comment stringifier. Output should be valid for the current schema.
By default, empty comment lines are left empty,
lines consisting of a single space are replaced by #
,
and all other lines are prefixed with a #
.
Parse an input string into JavaScript.
Only supports input consisting of a single YAML document; for multi-document
support you should use YAML.parseAllDocuments
. May throw on error, and may
log warnings using console.warn
.
The value will match the type of the root value of the parsed YAML document, so Maps become objects, Sequences arrays, and scalars result in nulls, booleans, numbers and strings.
Parse the input as a stream of YAML documents.
Documents should be separated from each other by ...
or ---
marker lines.
If an empty docs
array is returned, it will be of type
EmptyStream and contain additional stream information. In
TypeScript, you should use 'empty' in docs
as a type guard for it.
Parse an input string into a single YAML.Document
Stringify a value as a YAML document.
Will always include \n
as the last character, as is expected of YAML documents.
Apply a visitor to an AST node or document.
Walks through the tree (depth-first) starting from node
, calling a
visitor
function with three arguments:
key
: For sequence values and map Pair
, the node's index in the
collection. Within a Pair
, 'key'
or 'value'
, correspondingly.
null
for the root node.node
: The current node.path
: The ancestry of the current node.The return value of the visitor may be used to control the traversal:
undefined
(default): Do nothing and continuevisit.SKIP
: Do not visit the children of this node, continue with next
siblingvisit.BREAK
: Terminate traversal completelyvisit.REMOVE
: Remove the current node, then continue with the next oneNode
: Replace the current node, then continue by visiting itnumber
: While iterating the items of a sequence or map, set the index
of the next step. This is useful especially if the index of the current
node has changed.If visitor
is a single function, it will be called with all values
encountered in the tree, including e.g. null
values. Alternatively,
separate visitor functions may be defined for each Map
, Pair
, Seq
,
Alias
and Scalar
node. To define the same visitor function for more than
one node type, use the Collection
(map and seq), Value
(map, seq & scalar)
and Node
(alias, map, seq & scalar) targets. Of all these, only the most
specific defined one will be used for each node.
Apply an async visitor to an AST node or document.
Walks through the tree (depth-first) starting from node
, calling a
visitor
function with three arguments:
key
: For sequence values and map Pair
, the node's index in the
collection. Within a Pair
, 'key'
or 'value'
, correspondingly.
null
for the root node.node
: The current node.path
: The ancestry of the current node.The return value of the visitor may be used to control the traversal:
Promise
: Must resolve to one of the following valuesundefined
(default): Do nothing and continuevisit.SKIP
: Do not visit the children of this node, continue with next
siblingvisit.BREAK
: Terminate traversal completelyvisit.REMOVE
: Remove the current node, then continue with the next oneNode
: Replace the current node, then continue by visiting itnumber
: While iterating the items of a sequence or map, set the index
of the next step. This is useful especially if the index of the current
node has changed.If visitor
is a single function, it will be called with all values
encountered in the tree, including e.g. null
values. Alternatively,
separate visitor functions may be defined for each Map
, Pair
, Seq
,
Alias
and Scalar
node. To define the same visitor function for more than
one node type, use the Collection
(map and seq), Value
(map, seq & scalar)
and Node
(alias, map, seq & scalar) targets. Of all these, only the most
specific defined one will be used for each node.
Generated using TypeDoc
During node construction, use anchors and aliases to keep strictly equal non-null objects as equivalent in YAML.
Default:
true