js-yaml

  • Version 5.4.1
  • Published
  • 1.57 MB
  • 1 dependency
  • MIT license

Install

npm i js-yaml
yarn add js-yaml
pnpm add js-yaml

Overview

YAML 1.2 parser and serializer

Index

Variables

Functions

Classes

Interfaces

Type Aliases

Variables

variable binaryTag

const binaryTag: ScalarTagDefinition<any>;
  • The !!binary tag, represented as a Uint8Array.

    Tags

variable boolCoreTag

const boolCoreTag: ScalarTagDefinition<boolean>;
  • Tags

variable boolJsonTag

const boolJsonTag: ScalarTagDefinition<boolean>;
  • Tags

variable boolYaml11Tag

const boolYaml11Tag: ScalarTagDefinition<boolean>;
  • Tags

variable CHOMPING_MODE

const CHOMPING_MODE: { readonly CLIP: 1; readonly STRIP: 2; readonly KEEP: 3 };
  • Nodes

variable COLLECTION_STYLE

const COLLECTION_STYLE: { readonly BLOCK: 1; readonly FLOW: 2 };
  • Nodes

variable CORE_SCHEMA

const CORE_SCHEMA: Schema;
  • The default schema for the loaders. Note, CORE_SCHEMA comes without the !!merge tag. You can easily enable it if needed.

    Example 1

    Enable mergeTag:

    import { load, CORE_SCHEMA, mergeTag } from 'js-yaml'
    try {
    load(data, { schema: CORE_SCHEMA.withTags(mergeTag) })
    } catch (e) {
    console.error(e)
    }

    Schemas

variable DEFAULT_SCALAR_STYLE_RULES

const DEFAULT_SCALAR_STYLE_RULES: {
readonly applyQuoteFlowKeysOption: typeof applyQuoteFlowKeysOption;
readonly doubleQuoteForInvisibles: typeof doubleQuoteForInvisibles;
readonly doubleQuoteWhitespaceOnly: typeof doubleQuoteWhitespaceOnly;
readonly applyForceQuotesOption: typeof applyForceQuotesOption;
readonly tryLongOrMultilineAsBlock: typeof tryLongOrMultilineAsBlock;
readonly quoteInvalidPlain: typeof quoteInvalidPlain;
readonly fallbackToDoubleQuoted: typeof fallbackToDoubleQuoted;
};
  • Default scalar styling rules in application order. See [Scalar styling](../../docs/scalar_styling.md) for usage details.

    AST

variable DUMP_SCHEMA

const DUMP_SCHEMA: Schema;
  • The dumper schema for maximum compatibility. It combines all supported type variants from YAML 1.1 and YAML 1.2 so strings matching any of them are quoted. This makes the generated YAML more compatible with other parsers.

    The schema is based on YAML 1.1, but extends !!int and !!float to accept both YAML 1.1 and Core Schema forms, since Core Schema supports some forms that YAML 1.1 does not.

    Schemas

variable EVENT_ID

const EVENT_ID: {
readonly DOCUMENT: 1;
readonly SEQUENCE: 2;
readonly MAPPING: 3;
readonly SCALAR: 4;
readonly ALIAS: 5;
readonly POP: 6;
};
  • Events

variable FAILSAFE_SCHEMA

const FAILSAFE_SCHEMA: Schema;
  • The YAML 1.2 Failsafe Schema: strings, sequences, and mappings.

    Schemas

variable floatCoreTag

const floatCoreTag: ScalarTagDefinition<number>;
  • Tags

variable floatJsonTag

const floatJsonTag: ScalarTagDefinition<number>;
  • Tags

variable floatYaml11Tag

const floatYaml11Tag: ScalarTagDefinition<number>;
  • Tags

variable intCoreTag

const intCoreTag: ScalarTagDefinition<number>;
  • Tags

variable intJsonTag

const intJsonTag: ScalarTagDefinition<number>;
  • Tags

variable intYaml11Tag

const intYaml11Tag: ScalarTagDefinition<number>;
  • Tags

variable JSON_SCHEMA

const JSON_SCHEMA: Schema;
  • The YAML 1.2 JSON Schema. It uses JSON scalar forms while retaining YAML collection syntax.

    Schemas

variable legacyMapTag

const legacyMapTag: MappingTagDefinition<
Record<string, unknown>,
Record<string, unknown>
>;
  • This implementation exists solely to reproduce v4 behavior exactly. Its use is strongly discouraged. If complex or non-string keys are needed, use realMapTag instead.

    Tags

variable mapTag

const mapTag: MappingTagDefinition<Record<string, unknown>, Record<string, unknown>>;
  • This is the default mapping implementation. It uses {} objects and has only partial functionality due to language limitations. This choice was made because users expect to get JavaScript objects, and it was left unchanged to avoid too many breaking changes in the v5 release.

    Side effects:

    - Object.hasOwn() checks or for...of loops are required for safe use (to avoid falling through to prototypes). - Only scalar string keys are supported properly. - Other scalar keys, such as null and numbers, are converted to strings. This is historical behaviour, and it can cause side effects such as problems with !!merge.

    Note that non-string scalar keys may be deprecated in future versions.

    Ideally, use realMapTag instead.

    Tags

variable mergeTag

const mergeTag: ScalarTagDefinition<'<<'>;

variable NOT_RESOLVED

const NOT_RESOLVED: Symbol;
  • Returned by a scalar resolver when the source does not match its tag.

    Tags

variable nullCoreTag

const nullCoreTag: ScalarTagDefinition<null>;
  • Tags

variable nullJsonTag

const nullJsonTag: ScalarTagDefinition<null>;
  • Tags

variable nullYaml11Tag

const nullYaml11Tag: ScalarTagDefinition<null>;
  • Tags

variable omapTag

const omapTag: SequenceTagDefinition<
{ list: unknown[]; seen: Set<unknown> },
unknown[]
>;
  • Provided only for YAML 1.1 compatibility and supported by the loader only. JavaScript has no dedicated class to represent this type, so it cannot be identified and dumped.

    !!omap
    - one: 1
    - two: 2

    is loaded as

    [
    { one: 1 },
    { two: 2 }
    ]

    Tags

variable pairsTag

const pairsTag: SequenceTagDefinition<[unknown, unknown][], [unknown, unknown][]>;
  • Provided only for YAML 1.1 compatibility and supported by the loader only. JavaScript has no dedicated class to represent this type, so it cannot be identified and dumped.

    !!pairs
    - one: 1
    - two: 2

    is loaded as

    [
    ['one', 1],
    ['two', 2]
    ]

    Tags

variable realMapTag

const realMapTag: MappingTagDefinition<Map<unknown, unknown>, Map<unknown, unknown>>;
  • Recommended when non-string keys are actually needed. It uses native JavaScript Map objects, so keys keep their constructed types instead of being converted to strings.

    It is not the default to avoid widespread breaking changes in existing projects. Map has a different access API and does not pass deep equality checks against {}-based fixtures. Alongside the other changes in v5, making it the default was considered too disruptive.

    If these differences are acceptable for your project, we recommend using realMapTag to guarantee the absence of problems and side effects.

    Example 1

    Enable realMapTag:

    import { load, CORE_SCHEMA, realMapTag } from 'js-yaml'
    try {
    load(data, { schema: CORE_SCHEMA.withTags(realMapTag) })
    } catch (e) {
    console.error(e)
    }

    Tags

variable SCALAR_STYLE

const SCALAR_STYLE: {
readonly PLAIN: 1;
readonly SINGLE_QUOTED: 2;
readonly DOUBLE_QUOTED: 3;
readonly LITERAL_BLOCK: 4;
readonly FOLDED_BLOCK: 5;
};
  • Nodes

variable seqTag

const seqTag: SequenceTagDefinition<unknown[], unknown[]>;
  • Tags

variable setTag

const setTag: MappingTagDefinition<Set<unknown>, Set<unknown>>;
  • The YAML 1.1 !!set tag, represented as a JavaScript Set.

    Tags

variable strTag

const strTag: ScalarTagDefinition<string>;
  • Tags

variable timestampTag

const timestampTag: ScalarTagDefinition<Date>;
  • The YAML 1.1 !!timestamp tag, represented as a JavaScript Date.

    Tags

variable VISIT_BREAK

const VISIT_BREAK: Symbol;
  • Return from a visitor to stop the whole traversal.

    AST

variable VISIT_SKIP

const VISIT_SKIP: Symbol;
  • Return from a visitor to skip the current node's children.

    AST

variable YAML11_SCHEMA

const YAML11_SCHEMA: Schema;
  • YAML 1.1-compatible schema.

    Schemas

Functions

function applyForceQuotesOption

applyForceQuotesOption: (layout: ScalarLayout) => void;

    function applyQuoteFlowKeysOption

    applyQuoteFlowKeysOption: (layout: ScalarLayout) => void;

      function constructFromEvents

      constructFromEvents: (events: Event[], options: ConstructorOptions) => unknown[];
      • Constructs JavaScript documents directly from parser events, without an intermediate AST.

        Events

      function defineMappingTag

      defineMappingTag: <Carrier, Result = Carrier>(
      tagName: string,
      options: MappingTagOptions<Carrier, Result>
      ) => MappingTagDefinition<Carrier, Result>;
      • Create a normalized mapping tag definition.

        Tags

      function defineScalarTag

      defineScalarTag: <Result>(
      tagName: string,
      options: ScalarTagOptions<Result>
      ) => ScalarTagDefinition<Result>;
      • Create a normalized scalar tag definition.

        Tags

      function defineSequenceTag

      defineSequenceTag: <Carrier, Result = Carrier>(
      tagName: string,
      options: SequenceTagOptions<Carrier, Result>
      ) => SequenceTagDefinition<Carrier, Result>;
      • Create a normalized sequence tag definition.

        Tags

      function doubleQuoteForInvisibles

      doubleQuoteForInvisibles: (layout: ScalarLayout) => void;

        function doubleQuoteWhitespaceOnly

        doubleQuoteWhitespaceOnly: (layout: ScalarLayout) => void;

          function dump

          dump: (input: any, options?: DumpOptions) => string;
          • Serializes JS object as a YAML document. By default it can dump every supported YAML type, so it throws an exception if you try to dump regexps or functions. However, you can disable exceptions by setting the DumpOptions.skipInvalid option to true.

            Main

          function eventsToAst

          eventsToAst: (events: Event[], options: FromEventsOptions) => Document[];
          • Builds an AST from parser events

            AST

          function fallbackToDoubleQuoted

          fallbackToDoubleQuoted: (layout: ScalarLayout) => void;

            function getScalarValue

            getScalarValue: (input: string, scalar: ScalarEvent) => string;
            • Decodes the scalar referenced by event offsets in input.

              Events

            function jsToAst

            jsToAst: (input: unknown, schema: Schema, options?: FromJsOptions) => Document[];
            • Convert JS object to AST. A JS value is one YAML document. An unrepresentable root becomes an empty document, which the presenter renders as an empty string.

              AST

            function load

            load: (input: string, options?: LoadOptions) => unknown;
            • Parses string as a single YAML document. Throws YAMLException on error. This function does not understand multi-document or empty sources; it throws an exception on those.

              > [!NOTE] > 1. When processing untrusted input, see the > [security considerations](../docs/safety.md). > 2. All exceptions MUST be caught, not just YAMLException. > 3. The default CORE_SCHEMA comes without the !!merge tag. You can > easily enable it if needed. > 4. The default mapTag is {}-object based, with known limitations > (see description). For full compatibility use realMapTag > instead (it uses native JS Map).

              Example 1

              Enable mergeTag and realMapTag:

              import { load, CORE_SCHEMA, mergeTag, realMapTag } from 'js-yaml'
              try {
              load(data, { schema: CORE_SCHEMA.withTags(mergeTag, realMapTag) })
              } catch (e) {
              console.error(e)
              }

              Main

            function loadAll

            loadAll: {
            (input: string, options?: LoadOptions): unknown[];
            (input: string, iterator: null, options?: LoadOptions): unknown[];
            (input: string, iterator: LoadAllIterator, options?: LoadOptions): void;
            };
            • Same as load, but understands multi-document sources. Returns an array of documents.

              Main

            • Deprecated

              Iterator is not supported.

            function parseEvents

            parseEvents: (input: string, options: ParserOptions) => Event[];
            • Parses YAML into a flat event stream referencing source text by offsets.

              Events

            function present

            present: (documents: Document[], options: PresenterOptions) => string;
            • Build YAML from AST.

              AST

            function quoteInvalidPlain

            quoteInvalidPlain: (layout: ScalarLayout) => void;

              function tryLongOrMultilineAsBlock

              tryLongOrMultilineAsBlock: (layout: ScalarLayout) => void;

                function visit

                visit: (documents: Document[], visitor: Visitor) => void;
                • Walk every node in the documents, calling Visitor once per node (pre-order).

                  AST

                Classes

                class Schema

                class Schema {}
                • Controls tag resolution when loading and type selection when dumping.

                  Schemas

                constructor

                constructor(tags: readonly TagDefinition[]);

                  property tags

                  readonly tags: readonly TagDefinition[];

                    method withTags

                    withTags: (...tags: Array<TagDefinition | readonly TagDefinition[]>) => Schema;
                    • Creates a new schema with the specified tags added. If a tag already exists, it is replaced by the specified tag.

                      Example 1

                      import { CORE_SCHEMA, mergeTag, realMapTag } from 'js-yaml'
                      const schema = CORE_SCHEMA.withTags(mergeTag, realMapTag)

                    class YAMLException

                    class YAMLException extends Error {}
                    • A YAML error. Unlike an ordinary Error, it adds a source snippet showing the location of the problem to the error message, when available.

                      Main

                    constructor

                    constructor(reason: string, mark?: SnippetMark);
                    • Optional mark contains source snippet data. Usually, use YAMLException.throwAt instead of passing it directly.

                    property mark

                    mark?: SnippetMark;

                      property reason

                      reason: string;

                        method throwAt

                        static throwAt: (
                        source: string,
                        position: number,
                        message: string,
                        filename?: string
                        ) => never;
                        • Builds a YAMLException with a source snippet and throws it. source is the raw input text; position is an offset into it.

                        method toString

                        toString: (compact?: boolean) => string;
                        • Returns the formatted error, omitting the source snippet in compact mode.

                        Interfaces

                        interface AliasEvent

                        interface AliasEvent {}
                        • Events

                        property anchorEnd

                        anchorEnd: number;

                          property anchorStart

                          anchorStart: number;

                            property type

                            type: typeof EVENT_ID.ALIAS;

                              interface AliasNode

                              interface AliasNode {}
                              • Nodes

                              property anchor

                              anchor: string;
                              • The anchor name this alias points at (*name).

                              property kind

                              kind: 'alias';

                                interface ConstructorOptions

                                interface ConstructorOptions {}
                                • Events

                                property filename

                                filename?: string;

                                  property json

                                  json?: boolean;
                                  • Enables compatibility with JSON.parse behavior. Duplicate keys in a mapping override values instead of throwing an error.

                                  property maxAliases

                                  maxAliases?: number;
                                  • Maximum number of alias nodes (*ref) per document. Set to 0 to reject all aliases, or to -1 for no limit.

                                  property maxTotalMergeKeys

                                  maxTotalMergeKeys?: number;
                                  • Maximum total number of keys processed by merge (<<) across one load call. Each member of a merge sequence also counts as one key. Set to -1 to disable the limit.

                                  property schema

                                  schema?: Schema;
                                  • Schema to use.

                                  property source

                                  source: string;
                                  • Source text referenced by offsets in events.

                                  interface Document

                                  interface Document {}
                                  • The layer above Node: each document wraps one content node plus its own markers/directives. Not a member of Node — the fields differ. Document directives are ordered presentation data.

                                    Nodes

                                  property contents

                                  contents: Node | null;
                                  • null = empty document

                                  property directives

                                  directives: DocumentDirective[];

                                    property explicitEnd

                                    explicitEnd?: boolean;
                                    • print '...'

                                    property explicitStart

                                    explicitStart?: boolean;
                                    • print '---'

                                    interface DocumentEvent

                                    interface DocumentEvent {}
                                    • Events

                                    property directives

                                    directives: DocumentDirective[];

                                      property explicitEnd

                                      explicitEnd: boolean;

                                        property explicitStart

                                        explicitStart: boolean;

                                          property type

                                          type: typeof EVENT_ID.DOCUMENT;

                                            interface DumpOptions

                                            interface DumpOptions extends Omit<PresenterOptions, 'schema'> {}
                                            • Main

                                            property flowLevel

                                            flowLevel?: number;
                                            • Nesting level at which collections switch from block to flow style. Set to -1 to never switch automatically.

                                            property noRefs

                                            noRefs?: boolean;
                                            • Inlines duplicate objects instead of converting them into references.

                                            property schema

                                            schema?: Schema;
                                            • Schema to use.

                                            property skipInvalid

                                            skipInvalid?: boolean;
                                            • Skips invalid types instead of throwing. Invalid mapping pairs and sequence items are skipped; undefined sequence items are serialized as null.

                                            property sortKeys

                                            sortKeys?: boolean | ((a: any, b: any) => number);
                                            • Sorts mapping keys when true. A function can be provided to define the sort order.

                                              Deprecated

                                              Use transform to reorder mapping items.

                                            property transform

                                            transform?: (documents: Document[]) => void;
                                            • Mutates the generated AST before it is rendered.

                                              Example 1

                                              Sort mapping keys:

                                              import { dump, visit } from 'js-yaml'
                                              dump(value, {
                                              transform: documents => visit(documents, node => {
                                              if (node.kind === 'mapping') node.items.sort((a, b) => {
                                              const x = a.key.kind === 'scalar' ? a.key.value : ''
                                              const y = b.key.kind === 'scalar' ? b.key.value : ''
                                              return x.localeCompare(y)
                                              })
                                              })
                                              })

                                            interface FromEventsOptions

                                            interface FromEventsOptions {}
                                            • AST

                                            property schema

                                            schema: Schema;
                                            • Schema used to resolve implicit scalar tags.

                                            property source

                                            source: string;
                                            • Source text referenced by offsets in events.

                                            interface FromJsOptions

                                            interface FromJsOptions {}
                                            • AST

                                            property noRefs

                                            noRefs?: boolean;
                                            • Inlines duplicate objects instead of converting them into references.

                                            property skipInvalid

                                            skipInvalid?: boolean;
                                            • Skips unrepresentable values instead of throwing. Invalid mapping pairs and sequence items are skipped; undefined sequence items become null.

                                            interface LoadOptions

                                            interface LoadOptions extends ParserOptions, Omit<ConstructorOptions, 'source'> {}
                                            • Main

                                            interface MappingEvent

                                            interface MappingEvent {}
                                            • Events

                                            property anchorEnd

                                            anchorEnd: number;

                                              property anchorStart

                                              anchorStart: number;

                                                property start

                                                start: number;

                                                  property style

                                                  style: CollectionStyle;

                                                    property tagEnd

                                                    tagEnd: number;

                                                      property tagStart

                                                      tagStart: number;

                                                        property type

                                                        type: typeof EVENT_ID.MAPPING;

                                                          interface MappingNode

                                                          interface MappingNode extends NodeBase {}
                                                          • Nodes

                                                          property items

                                                          items: Array<{
                                                          key: Node;
                                                          value: Node;
                                                          }>;

                                                            property kind

                                                            kind: 'mapping';

                                                              property style

                                                              style: CollectionStyle;

                                                                interface MappingTagDefinition

                                                                interface MappingTagDefinition<Carrier = unknown, Result = Carrier>
                                                                extends Required<MappingTagOptions<Carrier, Result>> {}

                                                                property carrierIsResult

                                                                carrierIsResult: boolean;
                                                                • Whether the carrier is also the final result (finalize was omitted).

                                                                property implicit

                                                                implicit: false;
                                                                • Mapping tags do not participate in implicit scalar resolution.

                                                                property nodeKind

                                                                nodeKind: 'mapping';
                                                                • YAML node kind handled by this tag.

                                                                property tagName

                                                                tagName: string;
                                                                • Tag name used for schema lookup.

                                                                interface MappingTagOptions

                                                                interface MappingTagOptions<Carrier, Result = Carrier> {}

                                                                property addPair

                                                                addPair: (carrier: Carrier, key: unknown, value: unknown) => string;
                                                                • Writes a pair. Returns '' on success, a non-empty error message otherwise (key does not fit the representation, value rejected, ...). Always a string so the hot path never allocates an exception wrapper.

                                                                property create

                                                                create: (tagName: string) => Carrier;
                                                                • Create the carrier used while constructing a mapping.

                                                                property finalize

                                                                finalize?: (carrier: Carrier) => Result;
                                                                • Convert the completed carrier to the result. Defaults to the identity function.

                                                                property get

                                                                get: (result: Result, key: unknown) => unknown;
                                                                • Return a value from a completed result for YAML merge processing.

                                                                property has

                                                                has: (carrier: Carrier, key: unknown) => boolean;
                                                                • Return whether the carrier contains a key, for duplicate and merge checks.

                                                                property identify

                                                                identify: (data: any) => boolean;
                                                                • Selects this tag for a JavaScript value when dumping. Use () => false for load-only tags.

                                                                property keys

                                                                keys: (result: Result) => Iterable<unknown>;
                                                                • Return the keys of a completed result for YAML merge processing.

                                                                property matchByTagPrefix

                                                                matchByTagPrefix?: boolean;
                                                                • Whether explicit tag names are matched by prefix instead of exact equality. Default: false.

                                                                property represent

                                                                represent?: (data: any) => Map<unknown, unknown>;
                                                                • Return the mapping entries to dump. Defaults to the identity function.

                                                                property representTagName

                                                                representTagName?: (data: any) => string;
                                                                • Return the tag name to emit for a prefix-matching tag. Defaults to tagName.

                                                                interface NodeBase

                                                                interface NodeBase {}
                                                                • Nodes

                                                                property anchor

                                                                anchor?: string;

                                                                  property blankBefore

                                                                  blankBefore?: number;

                                                                    property comment

                                                                    comment?: string;

                                                                      property commentAfter

                                                                      commentAfter?: string;

                                                                        property commentBefore

                                                                        commentBefore?: string;
                                                                        • Reserved for the formatting layer; not populated by the dumper yet.

                                                                        property tag

                                                                        tag: string;
                                                                        • YAML tag. Untagged nodes carry the semantic resolved tag; tagged nodes carry the printable/verbatim tag spelling.

                                                                        property tagged

                                                                        tagged: boolean;
                                                                        • Whether to print the node's tag explicitly.

                                                                        interface ParserOptions

                                                                        interface ParserOptions {}
                                                                        • Events

                                                                        property filename

                                                                        filename?: string;
                                                                        • File path used in error messages.

                                                                        property maxDepth

                                                                        maxDepth?: number;
                                                                        • Maximum nesting depth for collections. Aliases are not taken into account.

                                                                        interface PopEvent

                                                                        interface PopEvent {}
                                                                        • Closes the most recently opened document, sequence, or mapping.

                                                                          Events

                                                                        property type

                                                                        type: typeof EVENT_ID.POP;

                                                                          interface PresenterOptions

                                                                          interface PresenterOptions {}
                                                                          • AST

                                                                          property flowBracketPadding

                                                                          flowBracketPadding?: boolean;
                                                                          • Adds spaces inside flow collection brackets: {a: 1} becomes { a: 1 }.

                                                                          property flowSkipColonSpace

                                                                          flowSkipColonSpace?: boolean;
                                                                          • Omits the space after : in flow mappings: {"a": 1} becomes {"a":1}.

                                                                            This forces quoteFlowKeys; otherwise a:1 would be parsed as a single plain scalar instead of a mapping entry.

                                                                          property flowSkipCommaSpace

                                                                          flowSkipCommaSpace?: boolean;
                                                                          • Omits the space after commas in flow collections: [1, 2] becomes [1,2].

                                                                          property forceQuotes

                                                                          forceQuotes?: boolean;

                                                                          property indent

                                                                          indent?: number;
                                                                          • Indentation width in spaces.

                                                                          property lineWidth

                                                                          lineWidth?: number;
                                                                          • Preferred line width for folding. Unbreakable and more-indented lines may exceed it. Set to -1 for unlimited width.

                                                                          property quoteFlowKeys

                                                                          quoteFlowKeys?: boolean;
                                                                          • Quotes flow mapping keys: {a: 1} becomes {"a": 1}.

                                                                          property quoteStyle

                                                                          quoteStyle?: 'single' | 'double';
                                                                          • Quoting style to use when a string needs quotes.

                                                                          property scalarStyleRules

                                                                          scalarStyleRules?: readonly ScalarStyleRule[];
                                                                          • Customizes how strings are rendered as plain, quoted, literal, or folded scalars. Rules are applied in array order; providing this option replaces the .

                                                                          property schema

                                                                          schema: Schema;
                                                                          • Schema used when selecting a safe scalar style.

                                                                          property seqInlineFirst

                                                                          seqInlineFirst?: boolean;
                                                                          • Allows a nested collection to start on the same line after -.

                                                                          property seqNoIndent

                                                                          seqNoIndent?: boolean;
                                                                          • Does not add an indentation level to array elements when enabled.

                                                                          property tagBeforeAnchor

                                                                          tagBeforeAnchor?: boolean;
                                                                          • Prints an explicit tag before an anchor: &ref_0 !!set becomes !!set &ref_0.

                                                                          interface ScalarEvent

                                                                          interface ScalarEvent {}

                                                                          property anchorEnd

                                                                          anchorEnd: number;

                                                                            property anchorStart

                                                                            anchorStart: number;

                                                                              property chomping

                                                                              chomping: ChompingMode;

                                                                                property fast

                                                                                fast: boolean;

                                                                                  property indent

                                                                                  indent: number;

                                                                                    property style

                                                                                    style: ScalarStyle;

                                                                                      property tagEnd

                                                                                      tagEnd: number;

                                                                                        property tagStart

                                                                                        tagStart: number;

                                                                                          property type

                                                                                          type: typeof EVENT_ID.SCALAR;

                                                                                            property valueEnd

                                                                                            valueEnd: number;

                                                                                              property valueStart

                                                                                              valueStart: number;

                                                                                                interface ScalarLayout

                                                                                                interface ScalarLayout {}
                                                                                                • Scalar presentation state passed to styling rules. AST

                                                                                                property allowedStylesMask

                                                                                                allowedStylesMask: number;
                                                                                                • Bit mask of allowed styles; each bit corresponds to a SCALAR_STYLE value.

                                                                                                property flowOnly

                                                                                                readonly flowOnly: boolean;

                                                                                                  property isKey

                                                                                                  readonly isKey: boolean;

                                                                                                    property level

                                                                                                    readonly level: number;

                                                                                                      property node

                                                                                                      readonly node: Readonly<ScalarNode>;

                                                                                                        property parent

                                                                                                        readonly parent: Readonly<Node> | null;

                                                                                                          property presenterOptions

                                                                                                          readonly presenterOptions: Readonly<Required<PresenterOptions>>;

                                                                                                            property shiftOfContent

                                                                                                            readonly shiftOfContent: number;

                                                                                                              property shiftOfFirstLine

                                                                                                              readonly shiftOfFirstLine: number;

                                                                                                                property shiftOfParent

                                                                                                                readonly shiftOfParent: number;

                                                                                                                  property style

                                                                                                                  style: ScalarStyle;
                                                                                                                  • Selected output style, which styling rules may modify. To avoid overriding earlier decisions, a rule should normally modify it only while it is SCALAR_STYLE.PLAIN.

                                                                                                                  interface ScalarNode

                                                                                                                  interface ScalarNode extends NodeBase {}
                                                                                                                  • Nodes

                                                                                                                  property kind

                                                                                                                  kind: 'scalar';

                                                                                                                    property style

                                                                                                                    style: ScalarStyle;
                                                                                                                    • Preferred scalar style; the presenter may fall back when necessary.

                                                                                                                    property value

                                                                                                                    value: string;

                                                                                                                      interface ScalarTagDefinition

                                                                                                                      interface ScalarTagDefinition<Result = unknown>
                                                                                                                      extends Required<ScalarTagOptions<Result>> {}

                                                                                                                      property nodeKind

                                                                                                                      nodeKind: 'scalar';
                                                                                                                      • YAML node kind handled by this tag.

                                                                                                                      property tagName

                                                                                                                      tagName: string;
                                                                                                                      • Tag name used for schema lookup.

                                                                                                                      interface ScalarTagOptions

                                                                                                                      interface ScalarTagOptions<Result> {}

                                                                                                                      property identify

                                                                                                                      identify: (data: any) => boolean;
                                                                                                                      • Selects this tag for a JavaScript value when dumping. Use () => false for load-only tags.

                                                                                                                      property implicit

                                                                                                                      implicit?: boolean;
                                                                                                                      • Whether this tag participates in resolving plain scalars without an explicit tag. Default: false.

                                                                                                                      property implicitFirstChars

                                                                                                                      implicitFirstChars?: readonly string[] | null;
                                                                                                                      • Set of source.charAt(0) keys for which resolve may succeed (a superset of what it really matches). A key is either a single character or '' (empty source). null means "no constraint, always try". Used by the composer to dispatch implicit scalars by first character without running every resolver.

                                                                                                                      property matchByTagPrefix

                                                                                                                      matchByTagPrefix?: boolean;
                                                                                                                      • Whether explicit tag names are matched by prefix instead of exact equality. Default: false.

                                                                                                                      property represent

                                                                                                                      represent?: (data: any) => string;
                                                                                                                      • A scalar's printed form is text, so represent always yields a string. The factory supplies a String(data) default when a tag omits it.

                                                                                                                      property representTagName

                                                                                                                      representTagName?: (data: any) => string;
                                                                                                                      • Return the tag name to emit for a prefix-matching tag. Defaults to tagName.

                                                                                                                      property resolve

                                                                                                                      resolve: (
                                                                                                                      source: string,
                                                                                                                      isExplicit: boolean,
                                                                                                                      tagName: string
                                                                                                                      ) => Result | typeof NOT_RESOLVED;
                                                                                                                      • Construct a value from scalar text, or return NOT_RESOLVED when it is invalid for this tag. isExplicit is true for an explicit tag and tagName is the actual matched name.

                                                                                                                      interface SequenceEvent

                                                                                                                      interface SequenceEvent {}
                                                                                                                      • Events

                                                                                                                      property anchorEnd

                                                                                                                      anchorEnd: number;

                                                                                                                        property anchorStart

                                                                                                                        anchorStart: number;

                                                                                                                          property start

                                                                                                                          start: number;

                                                                                                                            property style

                                                                                                                            style: CollectionStyle;

                                                                                                                              property tagEnd

                                                                                                                              tagEnd: number;

                                                                                                                                property tagStart

                                                                                                                                tagStart: number;

                                                                                                                                  property type

                                                                                                                                  type: typeof EVENT_ID.SEQUENCE;

                                                                                                                                    interface SequenceNode

                                                                                                                                    interface SequenceNode extends NodeBase {}
                                                                                                                                    • Nodes

                                                                                                                                    property items

                                                                                                                                    items: Node[];

                                                                                                                                      property kind

                                                                                                                                      kind: 'sequence';

                                                                                                                                        property style

                                                                                                                                        style: CollectionStyle;

                                                                                                                                          interface SequenceTagDefinition

                                                                                                                                          interface SequenceTagDefinition<Carrier = unknown, Result = Carrier>
                                                                                                                                          extends Required<SequenceTagOptions<Carrier, Result>> {}

                                                                                                                                          property carrierIsResult

                                                                                                                                          carrierIsResult: boolean;
                                                                                                                                          • Whether the carrier is also the final result (finalize was omitted).

                                                                                                                                          property implicit

                                                                                                                                          implicit: false;
                                                                                                                                          • Sequence tags do not participate in implicit scalar resolution.

                                                                                                                                          property nodeKind

                                                                                                                                          nodeKind: 'sequence';
                                                                                                                                          • YAML node kind handled by this tag.

                                                                                                                                          property tagName

                                                                                                                                          tagName: string;
                                                                                                                                          • Tag name used for schema lookup.

                                                                                                                                          interface SequenceTagOptions

                                                                                                                                          interface SequenceTagOptions<Carrier, Result = Carrier> {}

                                                                                                                                          property addItem

                                                                                                                                          addItem: (carrier: Carrier, item: unknown, index: number) => void | string;
                                                                                                                                          • Add an item to the carrier. Return a non-empty error message to reject it.

                                                                                                                                          property create

                                                                                                                                          create: (tagName: string) => Carrier;
                                                                                                                                          • Create the carrier used while constructing a sequence.

                                                                                                                                          property finalize

                                                                                                                                          finalize?: (carrier: Carrier) => Result;
                                                                                                                                          • Convert the completed carrier to the result. Defaults to the identity function.

                                                                                                                                          property identify

                                                                                                                                          identify: (data: any) => boolean;
                                                                                                                                          • Selects this tag for a JavaScript value when dumping. Use () => false for load-only tags.

                                                                                                                                          property matchByTagPrefix

                                                                                                                                          matchByTagPrefix?: boolean;
                                                                                                                                          • Whether explicit tag names are matched by prefix instead of exact equality. Default: false.

                                                                                                                                          property represent

                                                                                                                                          represent?: (data: any) => ArrayLike<unknown>;
                                                                                                                                          • Return the array-like contents to dump. Defaults to the identity function.

                                                                                                                                          property representTagName

                                                                                                                                          representTagName?: (data: any) => string;
                                                                                                                                          • Return the tag name to emit for a prefix-matching tag. Defaults to tagName.

                                                                                                                                          interface VisitContext

                                                                                                                                          interface VisitContext {}
                                                                                                                                          • Traversal-derived position of the current node. Kept off the node itself: a node may sit in several places (alias/dedup reuse), so depth/role belong to the walk, not the node. VisitContext.parent kind + VisitContext.isKey pin the exact slot.

                                                                                                                                            AST

                                                                                                                                          property depth

                                                                                                                                          depth: number;
                                                                                                                                          • 0 = document content root

                                                                                                                                          property isKey

                                                                                                                                          isKey: boolean;
                                                                                                                                          • Node sits in a mapping key position

                                                                                                                                          property parent

                                                                                                                                          parent: Node | null;
                                                                                                                                          • Enclosing sequence/mapping, null at the root

                                                                                                                                          Type Aliases

                                                                                                                                          type ChompingMode

                                                                                                                                          type ChompingMode = (typeof CHOMPING_MODE)[keyof typeof CHOMPING_MODE];
                                                                                                                                          • Nodes

                                                                                                                                          type CollectionStyle

                                                                                                                                          type CollectionStyle = (typeof COLLECTION_STYLE)[keyof typeof COLLECTION_STYLE];
                                                                                                                                          • Nodes

                                                                                                                                          type DocumentDirective

                                                                                                                                          type DocumentDirective =
                                                                                                                                          | {
                                                                                                                                          kind: 'yaml';
                                                                                                                                          version: string;
                                                                                                                                          }
                                                                                                                                          | {
                                                                                                                                          kind: 'tag';
                                                                                                                                          handle: string;
                                                                                                                                          prefix: string;
                                                                                                                                          };
                                                                                                                                          • Events

                                                                                                                                          type Event

                                                                                                                                          type Event =
                                                                                                                                          | DocumentEvent
                                                                                                                                          | SequenceEvent
                                                                                                                                          | MappingEvent
                                                                                                                                          | ScalarEvent
                                                                                                                                          | AliasEvent
                                                                                                                                          | PopEvent;
                                                                                                                                          • Source ranges are zero-based and end-exclusive; -1 means absent.

                                                                                                                                            Events

                                                                                                                                          type EventId

                                                                                                                                          type EventId = (typeof EVENT_ID)[keyof typeof EVENT_ID];
                                                                                                                                          • Events

                                                                                                                                          type Node

                                                                                                                                          type Node = ScalarNode | SequenceNode | MappingNode | AliasNode;
                                                                                                                                          • Nodes

                                                                                                                                          type ScalarStyle

                                                                                                                                          type ScalarStyle = (typeof SCALAR_STYLE)[keyof typeof SCALAR_STYLE];
                                                                                                                                          • Nodes

                                                                                                                                          type ScalarStyleRule

                                                                                                                                          type ScalarStyleRule = (layout: ScalarLayout) => void;
                                                                                                                                          • Function signature for scalar styling rules. AST

                                                                                                                                          type TagDefinition

                                                                                                                                          type TagDefinition =
                                                                                                                                          | ScalarTagDefinition<any>
                                                                                                                                          | SequenceTagDefinition<any, any>
                                                                                                                                          | MappingTagDefinition<any, any>;
                                                                                                                                          • Any normalized tag definition accepted by Schema.

                                                                                                                                            Tags

                                                                                                                                          type Visitor

                                                                                                                                          type Visitor = (node: Node, ctx: VisitContext) => VisitControl;
                                                                                                                                          • AST

                                                                                                                                          Package Files (1)

                                                                                                                                          Dependencies (1)

                                                                                                                                          Dev Dependencies (17)

                                                                                                                                          Peer Dependencies (0)

                                                                                                                                          No peer dependencies.

                                                                                                                                          Badge

                                                                                                                                          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/js-yaml.

                                                                                                                                          • Markdown
                                                                                                                                            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/js-yaml)
                                                                                                                                          • HTML
                                                                                                                                            <a href="https://www.jsdocs.io/package/js-yaml"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>