Options
All
  • Public
  • Public/Protected
  • All
Menu

enhanced-yaml - v0.1.0

Index

Type aliases

DumpOptions

DumpOptions: Partial<RequiredDumpOptions>

LoadOptions

LoadOptions: Partial<RequiredLoadOptions>

SafeDumpOptions

SafeDumpOptions: Omit<DumpOptions, "schema">

SafeLoadOptions

SafeLoadOptions: Omit<LoadOptions, "schema">

Schema

Schema: "failsafe" | "json" | "core"

SimilarityScore

SimilarityScore: number

A number between 0 and 1.

Used to pick the most similar value in a list to a given value.

SupportedNode

SupportedNode: Alias | Scalar | Pair | YAMLMap | YAMLSeq

The nodes supported by the serializer. Using an unsupported node will cause the serializer to throw.

Functions

arePairsEqual

  • arePairsEqual(a: Pair, b: Pair): boolean
  • Parameters

    • a: Pair
    • b: Pair

    Returns boolean

areScalarsEqual

  • areScalarsEqual(a: Scalar, b: Scalar): boolean
  • Parameters

    • a: Scalar
    • b: Scalar

    Returns boolean

areValuesEqual

  • areValuesEqual(a: unknown, b: unknown): boolean
  • Parameters

    • a: unknown
    • b: unknown

    Returns boolean

assertNode

  • assertNode(value: unknown): assertsvalue is Node
  • Parameters

    • value: unknown

    Returns assertsvalue is Node

computeArraySimilarityScore

  • Computes the similarity score between 2 Arrays, based on their contents.

    Parameters

    • a: unknown[]
    • b: unknown[]

    Returns SimilarityScore

computeCollectionSimilarityScore

  • computeCollectionSimilarityScore(a: Collection, b: Collection): SimilarityScore
  • Computes the similarity score between 2 Collections (e.g. YAMLMap, YAMLSeq), based on their items.

    Parameters

    • a: Collection
    • b: Collection

    Returns SimilarityScore

computePairSimilarityScore

  • Computes the similarity score between 2 Pairs, based on their keys and values. If the keys aren't equal, we don't consider the Pairs as being similar.

    Parameters

    • a: Pair
    • b: Pair

    Returns SimilarityScore

computeScalarSimilarityScore

  • Computes the similarity score between 2 Scalars, based on their values.

    Parameters

    • a: Scalar
    • b: Scalar

    Returns SimilarityScore

computeSimilarityScore

  • Computes the similarity score between 2 values.

    Parameters

    • a: unknown
    • b: unknown

    Returns SimilarityScore

dump

  • dump(value: unknown, options?: DumpOptions, original?: undefined | string): string
  • Stringifies a JavaScript value into the corresponding YAML string.

    Uses the core schema by default.

    Parameters

    • value: unknown

      The JavaScript value to dump.

    • Default value options: DumpOptions = {}

      The DumpOptions that affect how the value is serialized.

    • Optional original: undefined | string

      The original YAML string. If set, this function will preserve all comments and styling from the original source.

    Returns string

load

  • Parses a YAML string into the corresponding JavaScript value.

    Uses the core schema by default.

    Parameters

    • source: string

      The YAML source to load.

    • Default value options: LoadOptions = {}

      The LoadOptions that affect how the value is deserialized.

    Returns unknown

makeUpdater

  • makeUpdater<T>(structure: T, original: unknown): Updater<T>
  • Creates an updater given a data structure and the original node.

    Type parameters

    • T: {}

    Parameters

    • structure: T
    • original: unknown

    Returns Updater<T>

pairItems

  • pairItems<UpdatedItem, OriginalItem>(__namedParameters: { original: OriginalItem[]; updated: UpdatedItem[] }): Array<{ originalItem: OriginalItem | null; updatedItem: UpdatedItem }>
  • Pairs all updated items with an original item or null, based on a similarity score system.

    Type parameters

    • UpdatedItem

    • OriginalItem

    Parameters

    • __namedParameters: { original: OriginalItem[]; updated: UpdatedItem[] }
      • original: OriginalItem[]
      • updated: UpdatedItem[]

    Returns Array<{ originalItem: OriginalItem | null; updatedItem: UpdatedItem }>

preserveOriginalCollectionOrdering

  • preserveOriginalCollectionOrdering<T>(updater: Updater<T>, updatedCollection: InstanceType<T>): void
  • Preserves the ordering of the original collection node.

    If an item from the updated node is missing in the original node, it will be moved to the end of the resulting node.

    Type parameters

    • T: typeof Collection

    Parameters

    • updater: Updater<T>
    • updatedCollection: InstanceType<T>

    Returns void

safeDump

  • safeDump(value: unknown, options?: SafeDumpOptions, original?: undefined | string): string
  • Serializes (stringifies) a JavaScript value into the corresponding YAML string.

    Uses the failsafe schema.

    Parameters

    • value: unknown

      The JavaScript value to dump.

    • Default value options: SafeDumpOptions = {}

      The DumpOptions that affect how the value is serialized.

    • Optional original: undefined | string

      The original YAML string. If set, this function will preserve all comments and styling from the original source.

    Returns string

safeLoad

  • Parses a YAML string into the corresponding JavaScript value.

    Uses the failsafe schema.

    Parameters

    • source: string

      The YAML source to load.

    • Default value options: SafeLoadOptions = {}

      The LoadOptions that affect how the value is deserialized.

    Returns unknown

updateMap

  • updateMap(original: unknown, updated: YAMLMap, options: UpdaterOptions): YAMLMap
  • Updates a Map's items and sorts them:

    • it preserves the original ordering if the preserveOriginalOrdering option is set
    • it sorts them based on the sortMapEntries option if set

    Parameters

    Returns YAMLMap

updatePair

  • updatePair(original: unknown, updated: Pair, options: UpdaterOptions): Pair
  • Updates a Pair's key and value.

    Parameters

    Returns Pair

updateScalar

  • updateScalar(original: unknown, updated: Scalar): Scalar
  • Updates a Scalar's value.

    Parameters

    • original: unknown
    • updated: Scalar

    Returns Scalar

updateSequence

  • updateSequence(original: unknown, updated: YAMLSeq, options: UpdaterOptions): YAMLSeq
  • Updates a sequence's items by pairing each updated item with a corresponding original item based on a computed similarity score.

    It also preserves the original ordering if the preserveOriginalOrdering option is set.

    Parameters

    Returns YAMLSeq

updateValue

  • Updates a supported value.

    Parameters

    Returns SupportedNode

Object literals

Const defaultDumpOptions

defaultDumpOptions: object

indent

indent: number = 2

indentBlockSequences

indentBlockSequences: true = true

preserveOriginalOrdering

preserveOriginalOrdering: false = false

prettyErrors

prettyErrors: true = true

schema

schema: "core" = "core"

sortMapEntries

sortMapEntries: false = false

Const defaultLoadOptions

defaultLoadOptions: object

prettyErrors

prettyErrors: true = true

schema

schema: "core" = "core"

Generated using TypeDoc