Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Type aliases

CollectionItem

CollectionItem: { key?: Token | null; sep?: SourceToken[]; start: SourceToken[]; value?: Token }

Type declaration

Token

TokenType

VisitPath

VisitPath: readonly ["key" | "value", number][]

Visitor

Visitor: (item: CollectionItem, path: VisitPath) => number | symbol | Visitor | void

Type declaration

Variables

BOM

BOM: "" = "\uFEFF"

The byte order mark

DOCUMENT

DOCUMENT: "\u0002" = "\u0002"

Start of doc-mode

FLOW_END

FLOW_END: "\u0018" = "\u0018"

Unexpected end of flow-mode

SCALAR

SCALAR: "\u001f" = "\u001F"

Next token is a scalar value

Functions

createScalarToken

  • Create a new scalar token with value

    Values that represent an actual string but may be parsed as a different type should use a type other than 'PLAIN', as this function does not support any schema operations and won't check for such conflicts.

    Parameters

    • value: string

      The string representation of the value, which will have its content properly indented.

    • context: { end?: SourceToken[]; implicitKey?: boolean; inFlow?: boolean; indent: number; offset?: number; type?: Type }
      • Optional end?: SourceToken[]

        Comments and whitespace after the end of the value, or after the block scalar header. If undefined, a newline will be added.

      • Optional implicitKey?: boolean

        Being within an implicit key may affect the resolved type of the token's value.

      • Optional inFlow?: boolean

        Is this scalar within a flow collection? This may affect the resolved type of the token's value.

      • indent: number

        The indent level of the token.

      • Optional offset?: number

        The offset position of the token.

      • Optional type?: Type

        The preferred type of the scalar token. If undefined, the previous type of the token will be used, defaulting to 'PLAIN'.

    Returns BlockScalar | FlowScalar

Const isCollection

Const isScalar

  • Parameters

    • token: undefined | null | Token

    Returns token is FlowScalar | BlockScalar

    true if token is a flow or block scalar; not an alias

prettyToken

  • prettyToken(token: string): string
  • Get a printable representation of a lexer token

    Parameters

    • token: string

    Returns string

resolveAsScalar

  • resolveAsScalar(token: FlowScalar | BlockScalar, strict?: boolean, onError?: (offset: number, code: ErrorCode, message: string) => void): { comment: string; range: Range; type: Type | null; value: string }
  • resolveAsScalar(token: undefined | null | Token, strict?: boolean, onError?: (offset: number, code: ErrorCode, message: string) => void): { comment: string; range: Range; type: Type | null; value: string } | null
  • If token is a CST flow or block scalar, determine its string value and a few other attributes. Otherwise, return null.

    Parameters

    • token: FlowScalar | BlockScalar
    • Optional strict: boolean
    • Optional onError: (offset: number, code: ErrorCode, message: string) => void
        • (offset: number, code: ErrorCode, message: string): void
        • Parameters

          Returns void

    Returns { comment: string; range: Range; type: Type | null; value: string }

    • comment: string
    • range: Range
    • type: Type | null
    • value: string
  • Parameters

    • token: undefined | null | Token
    • Optional strict: boolean
    • Optional onError: (offset: number, code: ErrorCode, message: string) => void
        • (offset: number, code: ErrorCode, message: string): void
        • Parameters

          Returns void

    Returns { comment: string; range: Range; type: Type | null; value: string } | null

setScalarValue

  • setScalarValue(token: Token, value: string, context?: { afterKey?: boolean; implicitKey?: boolean; inFlow?: boolean; type?: Type }): void
  • Set the value of token to the given string value, overwriting any previous contents and type that it may have.

    Best efforts are made to retain any comments previously associated with the token, though all contents within a collection's items will be overwritten.

    Values that represent an actual string but may be parsed as a different type should use a type other than 'PLAIN', as this function does not support any schema operations and won't check for such conflicts.

    Parameters

    • token: Token

      Any token. If it does not include an indent value, the value will be stringified as if it were an implicit key.

    • value: string

      The string representation of the value, which will have its content properly indented.

    • Optional context: { afterKey?: boolean; implicitKey?: boolean; inFlow?: boolean; type?: Type }
      • Optional afterKey?: boolean

        In most cases, values after a key should have an additional level of indentation.

      • Optional implicitKey?: boolean

        Being within an implicit key may affect the resolved type of the token's value.

      • Optional inFlow?: boolean

        Being within a flow collection may affect the resolved type of the token's value.

      • Optional type?: Type

        The preferred type of the scalar token. If undefined, the previous type of the token will be used, defaulting to 'PLAIN'.

    Returns void

Const stringify

  • Stringify a CST document, token, or collection item

    Fair warning: This applies no validation whatsoever, and simply concatenates the sources in their logical order.

    Parameters

    Returns string

tokenType

  • Identify the type of a lexer token. May return null for unknown tokens.

    Parameters

    • source: string

    Returns TokenType | null

visit

  • Apply a visitor to a CST document or item.

    Walks through the tree (depth-first) starting from the root, calling a visitor function with two arguments when entering each item:

    • item: The current item, which included the following members:
      • start: SourceToken[] – Source tokens before the key or value, possibly including its anchor or tag.
      • key?: Token | null – Set for pair values. May then be null, if the key before the : separator is empty.
      • sep?: SourceToken[] – Source tokens between the key and the value, which should include the : map value indicator if value is set.
      • value?: Token – The value of a sequence item, or of a map pair.
    • path: The steps from the root to the current node, as an array of ['key' | 'value', number] tuples.

    The return value of the visitor may be used to control the traversal:

    • undefined (default): Do nothing and continue
    • visit.SKIP: Do not visit the children of this token, continue with next sibling
    • visit.BREAK: Terminate traversal completely
    • visit.REMOVE: Remove the current item, then continue with the next one
    • number: Set the index of the next step. This is useful especially if the index of the current token has changed.
    • function: Define the next visitor for this item. After the original visitor is called on item entry, next visitors are called after handling a non-empty key and when exiting the item.

    Parameters

    Returns void

Generated using TypeDoc