[d24f17c] | 1 | import type { Reviver } from './doc/applyReviver.js';
|
---|
| 2 | import type { Directives } from './doc/directives.js';
|
---|
| 3 | import type { LogLevelId } from './log.js';
|
---|
| 4 | import type { ParsedNode } from './nodes/Node.js';
|
---|
| 5 | import type { Pair } from './nodes/Pair.js';
|
---|
| 6 | import type { Scalar } from './nodes/Scalar.js';
|
---|
| 7 | import type { LineCounter } from './parse/line-counter.js';
|
---|
| 8 | import type { Schema } from './schema/Schema.js';
|
---|
| 9 | import type { Tags } from './schema/tags.js';
|
---|
| 10 | import type { CollectionTag, ScalarTag } from './schema/types.js';
|
---|
| 11 | export type ParseOptions = {
|
---|
| 12 | /**
|
---|
| 13 | * Whether integers should be parsed into BigInt rather than number values.
|
---|
| 14 | *
|
---|
| 15 | * Default: `false`
|
---|
| 16 | *
|
---|
| 17 | * https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/BigInt
|
---|
| 18 | */
|
---|
| 19 | intAsBigInt?: boolean;
|
---|
| 20 | /**
|
---|
| 21 | * Include a `srcToken` value on each parsed `Node`, containing the CST token
|
---|
| 22 | * that was composed into this node.
|
---|
| 23 | *
|
---|
| 24 | * Default: `false`
|
---|
| 25 | */
|
---|
| 26 | keepSourceTokens?: boolean;
|
---|
| 27 | /**
|
---|
| 28 | * If set, newlines will be tracked, to allow for `lineCounter.linePos(offset)`
|
---|
| 29 | * to provide the `{ line, col }` positions within the input.
|
---|
| 30 | */
|
---|
| 31 | lineCounter?: LineCounter;
|
---|
| 32 | /**
|
---|
| 33 | * Include line/col position & node type directly in parse errors.
|
---|
| 34 | *
|
---|
| 35 | * Default: `true`
|
---|
| 36 | */
|
---|
| 37 | prettyErrors?: boolean;
|
---|
| 38 | /**
|
---|
| 39 | * Detect and report errors that are required by the YAML 1.2 spec,
|
---|
| 40 | * but are caused by unambiguous content.
|
---|
| 41 | *
|
---|
| 42 | * Default: `true`
|
---|
| 43 | */
|
---|
| 44 | strict?: boolean;
|
---|
| 45 | /**
|
---|
| 46 | * YAML requires map keys to be unique. By default, this is checked by
|
---|
| 47 | * comparing scalar values with `===`; deep equality is not checked for
|
---|
| 48 | * aliases or collections. If merge keys are enabled by the schema,
|
---|
| 49 | * multiple `<<` keys are allowed.
|
---|
| 50 | *
|
---|
| 51 | * Set `false` to disable, or provide your own comparator function to
|
---|
| 52 | * customise. The comparator will be passed two `ParsedNode` values, and
|
---|
| 53 | * is expected to return a `boolean` indicating their equality.
|
---|
| 54 | *
|
---|
| 55 | * Default: `true`
|
---|
| 56 | */
|
---|
| 57 | uniqueKeys?: boolean | ((a: ParsedNode, b: ParsedNode) => boolean);
|
---|
| 58 | };
|
---|
| 59 | export type DocumentOptions = {
|
---|
| 60 | /**
|
---|
| 61 | * @internal
|
---|
| 62 | * Used internally by Composer. If set and includes an explicit version,
|
---|
| 63 | * that overrides the `version` option.
|
---|
| 64 | */
|
---|
| 65 | _directives?: Directives;
|
---|
| 66 | /**
|
---|
| 67 | * Control the logging level during parsing
|
---|
| 68 | *
|
---|
| 69 | * Default: `'warn'`
|
---|
| 70 | */
|
---|
| 71 | logLevel?: LogLevelId;
|
---|
| 72 | /**
|
---|
| 73 | * The YAML version used by documents without a `%YAML` directive.
|
---|
| 74 | *
|
---|
| 75 | * Default: `"1.2"`
|
---|
| 76 | */
|
---|
| 77 | version?: '1.1' | '1.2' | 'next';
|
---|
| 78 | };
|
---|
| 79 | export type SchemaOptions = {
|
---|
| 80 | /**
|
---|
| 81 | * When parsing, warn about compatibility issues with the given schema.
|
---|
| 82 | * When stringifying, use scalar styles that are parsed correctly
|
---|
| 83 | * by the `compat` schema as well as the actual schema.
|
---|
| 84 | *
|
---|
| 85 | * Default: `null`
|
---|
| 86 | */
|
---|
| 87 | compat?: string | Tags | null;
|
---|
| 88 | /**
|
---|
| 89 | * Array of additional tags to include in the schema, or a function that may
|
---|
| 90 | * modify the schema's base tag array.
|
---|
| 91 | */
|
---|
| 92 | customTags?: Tags | ((tags: Tags) => Tags) | null;
|
---|
| 93 | /**
|
---|
| 94 | * Enable support for `<<` merge keys.
|
---|
| 95 | *
|
---|
| 96 | * Default: `false` for YAML 1.2, `true` for earlier versions
|
---|
| 97 | */
|
---|
| 98 | merge?: boolean;
|
---|
| 99 | /**
|
---|
| 100 | * When using the `'core'` schema, support parsing values with these
|
---|
| 101 | * explicit YAML 1.1 tags:
|
---|
| 102 | *
|
---|
| 103 | * `!!binary`, `!!omap`, `!!pairs`, `!!set`, `!!timestamp`.
|
---|
| 104 | *
|
---|
| 105 | * Default `true`
|
---|
| 106 | */
|
---|
| 107 | resolveKnownTags?: boolean;
|
---|
| 108 | /**
|
---|
| 109 | * The base schema to use.
|
---|
| 110 | *
|
---|
| 111 | * The core library has built-in support for the following:
|
---|
| 112 | * - `'failsafe'`: A minimal schema that parses all scalars as strings
|
---|
| 113 | * - `'core'`: The YAML 1.2 core schema
|
---|
| 114 | * - `'json'`: The YAML 1.2 JSON schema, with minimal rules for JSON compatibility
|
---|
| 115 | * - `'yaml-1.1'`: The YAML 1.1 schema
|
---|
| 116 | *
|
---|
| 117 | * If using another (custom) schema, the `customTags` array needs to
|
---|
| 118 | * fully define the schema's tags.
|
---|
| 119 | *
|
---|
| 120 | * Default: `'core'` for YAML 1.2, `'yaml-1.1'` for earlier versions
|
---|
| 121 | */
|
---|
| 122 | schema?: string | Schema;
|
---|
| 123 | /**
|
---|
| 124 | * When adding to or stringifying a map, sort the entries.
|
---|
| 125 | * If `true`, sort by comparing key values with `<`.
|
---|
| 126 | * Does not affect item order when parsing.
|
---|
| 127 | *
|
---|
| 128 | * Default: `false`
|
---|
| 129 | */
|
---|
| 130 | sortMapEntries?: boolean | ((a: Pair, b: Pair) => number);
|
---|
| 131 | /**
|
---|
| 132 | * Override default values for `toString()` options.
|
---|
| 133 | */
|
---|
| 134 | toStringDefaults?: ToStringOptions;
|
---|
| 135 | };
|
---|
| 136 | export type CreateNodeOptions = {
|
---|
| 137 | /**
|
---|
| 138 | * During node construction, use anchors and aliases to keep strictly equal
|
---|
| 139 | * non-null objects as equivalent in YAML.
|
---|
| 140 | *
|
---|
| 141 | * Default: `true`
|
---|
| 142 | */
|
---|
| 143 | aliasDuplicateObjects?: boolean;
|
---|
| 144 | /**
|
---|
| 145 | * Default prefix for anchors.
|
---|
| 146 | *
|
---|
| 147 | * Default: `'a'`, resulting in anchors `a1`, `a2`, etc.
|
---|
| 148 | */
|
---|
| 149 | anchorPrefix?: string;
|
---|
| 150 | /** Force the top-level collection node to use flow style. */
|
---|
| 151 | flow?: boolean;
|
---|
| 152 | /**
|
---|
| 153 | * Keep `undefined` object values when creating mappings, rather than
|
---|
| 154 | * discarding them.
|
---|
| 155 | *
|
---|
| 156 | * Default: `false`
|
---|
| 157 | */
|
---|
| 158 | keepUndefined?: boolean | null;
|
---|
| 159 | onTagObj?: (tagObj: ScalarTag | CollectionTag) => void;
|
---|
| 160 | /**
|
---|
| 161 | * Specify the top-level collection type, e.g. `"!!omap"`. Note that this
|
---|
| 162 | * requires the corresponding tag to be available in this document's schema.
|
---|
| 163 | */
|
---|
| 164 | tag?: string;
|
---|
| 165 | };
|
---|
| 166 | export type ToJSOptions = {
|
---|
| 167 | /**
|
---|
| 168 | * Use Map rather than Object to represent mappings.
|
---|
| 169 | *
|
---|
| 170 | * Default: `false`
|
---|
| 171 | */
|
---|
| 172 | mapAsMap?: boolean;
|
---|
| 173 | /**
|
---|
| 174 | * Prevent exponential entity expansion attacks by limiting data aliasing count;
|
---|
| 175 | * set to `-1` to disable checks; `0` disallows all alias nodes.
|
---|
| 176 | *
|
---|
| 177 | * Default: `100`
|
---|
| 178 | */
|
---|
| 179 | maxAliasCount?: number;
|
---|
| 180 | /**
|
---|
| 181 | * If defined, called with the resolved `value` and reference `count` for
|
---|
| 182 | * each anchor in the document.
|
---|
| 183 | */
|
---|
| 184 | onAnchor?: (value: unknown, count: number) => void;
|
---|
| 185 | /**
|
---|
| 186 | * Optional function that may filter or modify the output JS value
|
---|
| 187 | *
|
---|
| 188 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#using_the_reviver_parameter
|
---|
| 189 | */
|
---|
| 190 | reviver?: Reviver;
|
---|
| 191 | };
|
---|
| 192 | export type ToStringOptions = {
|
---|
| 193 | /**
|
---|
| 194 | * Use block quote styles for scalar values where applicable.
|
---|
| 195 | * Set to `false` to disable block quotes completely.
|
---|
| 196 | *
|
---|
| 197 | * Default: `true`
|
---|
| 198 | */
|
---|
| 199 | blockQuote?: boolean | 'folded' | 'literal';
|
---|
| 200 | /**
|
---|
| 201 | * Enforce `'block'` or `'flow'` style on maps and sequences.
|
---|
| 202 | * Empty collections will always be stringified as `{}` or `[]`.
|
---|
| 203 | *
|
---|
| 204 | * Default: `'any'`, allowing each node to set its style separately
|
---|
| 205 | * with its `flow: boolean` (default `false`) property.
|
---|
| 206 | */
|
---|
| 207 | collectionStyle?: 'any' | 'block' | 'flow';
|
---|
| 208 | /**
|
---|
| 209 | * Comment stringifier.
|
---|
| 210 | * Output should be valid for the current schema.
|
---|
| 211 | *
|
---|
| 212 | * By default, empty comment lines are left empty,
|
---|
| 213 | * lines consisting of a single space are replaced by `#`,
|
---|
| 214 | * and all other lines are prefixed with a `#`.
|
---|
| 215 | */
|
---|
| 216 | commentString?: (comment: string) => string;
|
---|
| 217 | /**
|
---|
| 218 | * The default type of string literal used to stringify implicit key values.
|
---|
| 219 | * Output may use other types if required to fully represent the value.
|
---|
| 220 | *
|
---|
| 221 | * If `null`, the value of `defaultStringType` is used.
|
---|
| 222 | *
|
---|
| 223 | * Default: `null`
|
---|
| 224 | */
|
---|
| 225 | defaultKeyType?: Scalar.Type | null;
|
---|
| 226 | /**
|
---|
| 227 | * The default type of string literal used to stringify values in general.
|
---|
| 228 | * Output may use other types if required to fully represent the value.
|
---|
| 229 | *
|
---|
| 230 | * Default: `'PLAIN'`
|
---|
| 231 | */
|
---|
| 232 | defaultStringType?: Scalar.Type;
|
---|
| 233 | /**
|
---|
| 234 | * Include directives in the output.
|
---|
| 235 | *
|
---|
| 236 | * - If `true`, at least the document-start marker `---` is always included.
|
---|
| 237 | * This does not force the `%YAML` directive to be included. To do that,
|
---|
| 238 | * set `doc.directives.yaml.explicit = true`.
|
---|
| 239 | * - If `false`, no directives or marker is ever included. If using the `%TAG`
|
---|
| 240 | * directive, you are expected to include it manually in the stream before
|
---|
| 241 | * its use.
|
---|
| 242 | * - If `null`, directives and marker may be included if required.
|
---|
| 243 | *
|
---|
| 244 | * Default: `null`
|
---|
| 245 | */
|
---|
| 246 | directives?: boolean | null;
|
---|
| 247 | /**
|
---|
| 248 | * Restrict double-quoted strings to use JSON-compatible syntax.
|
---|
| 249 | *
|
---|
| 250 | * Default: `false`
|
---|
| 251 | */
|
---|
| 252 | doubleQuotedAsJSON?: boolean;
|
---|
| 253 | /**
|
---|
| 254 | * Minimum length for double-quoted strings to use multiple lines to
|
---|
| 255 | * represent the value. Ignored if `doubleQuotedAsJSON` is set.
|
---|
| 256 | *
|
---|
| 257 | * Default: `40`
|
---|
| 258 | */
|
---|
| 259 | doubleQuotedMinMultiLineLength?: number;
|
---|
| 260 | /**
|
---|
| 261 | * String representation for `false`.
|
---|
| 262 | * With the core schema, use `'false'`, `'False'`, or `'FALSE'`.
|
---|
| 263 | *
|
---|
| 264 | * Default: `'false'`
|
---|
| 265 | */
|
---|
| 266 | falseStr?: string;
|
---|
| 267 | /**
|
---|
| 268 | * When true, a single space of padding will be added inside the delimiters
|
---|
| 269 | * of non-empty single-line flow collections.
|
---|
| 270 | *
|
---|
| 271 | * Default: `true`
|
---|
| 272 | */
|
---|
| 273 | flowCollectionPadding?: boolean;
|
---|
| 274 | /**
|
---|
| 275 | * The number of spaces to use when indenting code.
|
---|
| 276 | *
|
---|
| 277 | * Default: `2`
|
---|
| 278 | */
|
---|
| 279 | indent?: number;
|
---|
| 280 | /**
|
---|
| 281 | * Whether block sequences should be indented.
|
---|
| 282 | *
|
---|
| 283 | * Default: `true`
|
---|
| 284 | */
|
---|
| 285 | indentSeq?: boolean;
|
---|
| 286 | /**
|
---|
| 287 | * Maximum line width (set to `0` to disable folding).
|
---|
| 288 | *
|
---|
| 289 | * This is a soft limit, as only double-quoted semantics allow for inserting
|
---|
| 290 | * a line break in the middle of a word, as well as being influenced by the
|
---|
| 291 | * `minContentWidth` option.
|
---|
| 292 | *
|
---|
| 293 | * Default: `80`
|
---|
| 294 | */
|
---|
| 295 | lineWidth?: number;
|
---|
| 296 | /**
|
---|
| 297 | * Minimum line width for highly-indented content (set to `0` to disable).
|
---|
| 298 | *
|
---|
| 299 | * Default: `20`
|
---|
| 300 | */
|
---|
| 301 | minContentWidth?: number;
|
---|
| 302 | /**
|
---|
| 303 | * String representation for `null`.
|
---|
| 304 | * With the core schema, use `'null'`, `'Null'`, `'NULL'`, `'~'`, or an empty
|
---|
| 305 | * string `''`.
|
---|
| 306 | *
|
---|
| 307 | * Default: `'null'`
|
---|
| 308 | */
|
---|
| 309 | nullStr?: string;
|
---|
| 310 | /**
|
---|
| 311 | * Require keys to be scalars and to use implicit rather than explicit notation.
|
---|
| 312 | *
|
---|
| 313 | * Default: `false`
|
---|
| 314 | */
|
---|
| 315 | simpleKeys?: boolean;
|
---|
| 316 | /**
|
---|
| 317 | * Use 'single quote' rather than "double quote" where applicable.
|
---|
| 318 | * Set to `false` to disable single quotes completely.
|
---|
| 319 | *
|
---|
| 320 | * Default: `null`
|
---|
| 321 | */
|
---|
| 322 | singleQuote?: boolean | null;
|
---|
| 323 | /**
|
---|
| 324 | * String representation for `true`.
|
---|
| 325 | * With the core schema, use `'true'`, `'True'`, or `'TRUE'`.
|
---|
| 326 | *
|
---|
| 327 | * Default: `'true'`
|
---|
| 328 | */
|
---|
| 329 | trueStr?: string;
|
---|
| 330 | /**
|
---|
| 331 | * The anchor used by an alias must be defined before the alias node. As it's
|
---|
| 332 | * possible for the document to be modified manually, the order may be
|
---|
| 333 | * verified during stringification.
|
---|
| 334 | *
|
---|
| 335 | * Default: `'true'`
|
---|
| 336 | */
|
---|
| 337 | verifyAliasOrder?: boolean;
|
---|
| 338 | };
|
---|