yaml 3.0.0-0 → 3.0.0-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1377 @@
1
+ //#region src/parse/line-counter.d.ts
2
+ /**
3
+ * Tracks newlines during parsing in order to provide an efficient API for
4
+ * determining the one-indexed `{ line, col }` position for any offset
5
+ * within the input.
6
+ */
7
+ declare class LineCounter {
8
+ lineStarts: number[];
9
+ /**
10
+ * Should be called in ascending order. Otherwise, call
11
+ * `lineCounter.lineStarts.sort()` before calling `linePos()`.
12
+ */
13
+ addNewLine: (offset: number) => number;
14
+ /**
15
+ * Performs a binary search and returns the 1-indexed { line, col }
16
+ * position of `offset`. If `line === 0`, `addNewLine` has never been
17
+ * called or `offset` is before the first known newline.
18
+ */
19
+ linePos: (offset: number) => {
20
+ line: number;
21
+ col: number;
22
+ };
23
+ }
24
+ //#endregion
25
+ //#region src/errors.d.ts
26
+ type ErrorCode = "ALIAS_PROPS" | "BAD_ALIAS" | "BAD_DIRECTIVE" | "BAD_DQ_ESCAPE" | "BAD_INDENT" | "BAD_PROP_ORDER" | "BAD_SCALAR_START" | "BLOCK_AS_IMPLICIT_KEY" | "BLOCK_IN_FLOW" | "DUPLICATE_KEY" | "IMPOSSIBLE" | "KEY_OVER_1024_CHARS" | "MISSING_CHAR" | "MULTILINE_IMPLICIT_KEY" | "MULTIPLE_ANCHORS" | "MULTIPLE_DOCS" | "MULTIPLE_TAGS" | "NON_STRING_KEY" | "RESOURCE_EXHAUSTION" | "TAB_AS_INDENT" | "TAG_RESOLVE_FAILED" | "UNEXPECTED_TOKEN" | "BAD_COLLECTION_TYPE";
27
+ type LinePos = {
28
+ line: number;
29
+ col: number;
30
+ };
31
+ declare class YAMLError extends Error {
32
+ name: "YAMLParseError" | "YAMLWarning";
33
+ code: ErrorCode;
34
+ message: string;
35
+ pos: [number, number];
36
+ linePos?: [LinePos] | [LinePos, LinePos];
37
+ constructor(name: YAMLError["name"], pos: [number, number], code: ErrorCode, message: string);
38
+ }
39
+ declare class YAMLParseError extends YAMLError {
40
+ constructor(pos: [number, number], code: ErrorCode, message: string);
41
+ }
42
+ declare class YAMLWarning extends YAMLError {
43
+ constructor(pos: [number, number], code: ErrorCode, message: string);
44
+ }
45
+ //#endregion
46
+ //#region src/doc/applyReviver.d.ts
47
+ type Reviver = (key: unknown, value: unknown) => unknown;
48
+ //#endregion
49
+ //#region src/log.d.ts
50
+ type LogLevelId = "silent" | "error" | "warn" | "debug";
51
+ declare function debug(logLevel: LogLevelId, ...messages: any[]): void;
52
+ declare function warn(logLevel: LogLevelId, warning: string | Error): void;
53
+ //#endregion
54
+ //#region src/stringify/stringify.d.ts
55
+ type StringifyContext = {
56
+ actualString?: boolean;
57
+ anchors: Set<string>;
58
+ doc: Document;
59
+ forceBlockIndent?: boolean;
60
+ implicitKey?: boolean;
61
+ indent: string;
62
+ indentStep: string;
63
+ indentAtStart?: number;
64
+ inFlow: boolean | null;
65
+ inStringifyKey?: boolean;
66
+ flowCollectionPadding: string;
67
+ options: Readonly<Required<Omit<ToStringOptions, "collectionStyle" | "indent">>>;
68
+ resolvedAliases?: Set<Alias>;
69
+ sortMapEntries: ((a: Pair, b: Pair) => number) | null;
70
+ };
71
+ //#endregion
72
+ //#region src/nodes/toJS.d.ts
73
+ /** A context used in `node.toJS()` implementations */
74
+ declare class ToJSContext {
75
+ #private;
76
+ anchors: Map<Node, {
77
+ aliasCount: number;
78
+ count: number;
79
+ res: unknown;
80
+ }>;
81
+ /** Cached anchor and alias nodes in the order they occur in the document */
82
+ aliasResolveCache?: Node[];
83
+ mapAsMap: boolean;
84
+ mapKeyWarned: boolean;
85
+ maxAliasCount: number;
86
+ constructor(opt?: ToJSOptions);
87
+ setAnchor(node: Node, res: unknown): void;
88
+ resolveAlias(doc: Document, source: Node): unknown;
89
+ }
90
+ //#endregion
91
+ //#region src/doc/NodeCreator.d.ts
92
+ declare class NodeCreator {
93
+ #private;
94
+ keepUndefined: boolean;
95
+ replacer?: Replacer;
96
+ schema: Schema;
97
+ constructor(doc: Document<DocValue, boolean>, options?: CreateNodeOptions, replacer?: Replacer);
98
+ constructor(schema: Schema, options?: CreateNodeOptions);
99
+ create(value: unknown, tagName?: string): Node;
100
+ createPair(key: unknown, value: unknown): Pair<Node, Node | null>;
101
+ /**
102
+ * With circular references, the source node is only resolved after all
103
+ * of its child nodes are. This is why anchors are set only after all of
104
+ * the nodes have been created.
105
+ */
106
+ setAnchors(): void;
107
+ }
108
+ //#endregion
109
+ //#region src/nodes/Scalar.d.ts
110
+ declare namespace Scalar {
111
+ type BLOCK_FOLDED = "BLOCK_FOLDED";
112
+ type BLOCK_LITERAL = "BLOCK_LITERAL";
113
+ type PLAIN = "PLAIN";
114
+ type QUOTE_DOUBLE = "QUOTE_DOUBLE";
115
+ type QUOTE_SINGLE = "QUOTE_SINGLE";
116
+ type Type = BLOCK_FOLDED | BLOCK_LITERAL | PLAIN | QUOTE_DOUBLE | QUOTE_SINGLE;
117
+ }
118
+ declare class Scalar<T = unknown> implements NodeBase {
119
+ static readonly BLOCK_FOLDED = "BLOCK_FOLDED";
120
+ static readonly BLOCK_LITERAL = "BLOCK_LITERAL";
121
+ static readonly PLAIN = "PLAIN";
122
+ static readonly QUOTE_DOUBLE = "QUOTE_DOUBLE";
123
+ static readonly QUOTE_SINGLE = "QUOTE_SINGLE";
124
+ value: T;
125
+ /** An optional anchor on this node. Used by alias nodes. */
126
+ anchor?: string;
127
+ /** A comment on or immediately after this node. */
128
+ comment?: string | null;
129
+ /** A comment before this node. */
130
+ commentBefore?: string | null;
131
+ /**
132
+ * By default (undefined), numbers use decimal notation.
133
+ * The YAML 1.2 core schema only supports 'HEX' and 'OCT'.
134
+ * The YAML 1.1 schema also supports 'BIN' and 'TIME'
135
+ */
136
+ format?: string;
137
+ /**
138
+ * If `value` is a number that is serialized as a decimal string
139
+ * (i.e. not using exponential notation),
140
+ * use this value when stringifying this node.
141
+ */
142
+ minFractionDigits?: number;
143
+ /**
144
+ * The `[start, value-end, node-end]` character offsets for
145
+ * the part of the source parsed into this node (undefined if not parsed).
146
+ * The `value-end` and `node-end` positions are themselves not included in their respective ranges.
147
+ */
148
+ range?: Range | null;
149
+ /** A blank line before this node and its commentBefore */
150
+ spaceBefore?: boolean;
151
+ /** The CST token that was composed into this node. */
152
+ srcToken?: FlowScalar | BlockScalar;
153
+ /** Set during parsing to the source string value */
154
+ source?: string;
155
+ /** A fully qualified tag, if required */
156
+ tag?: string;
157
+ /** The scalar style used for the node's string representation */
158
+ type?: Scalar.Type;
159
+ /**
160
+ * Customize the way that a key-value pair is resolved.
161
+ * Used for YAML 1.1 !!merge << handling.
162
+ */
163
+ addToJSMap?: (doc: Document<DocValue, boolean>, ctx: ToJSContext | undefined, map: MapLike, value: unknown, isPlainObject: boolean) => void;
164
+ constructor(value: T);
165
+ /** Create a copy of this node. */
166
+ clone(): this;
167
+ /** A plain JavaScript representation of this node. */
168
+ toJS(_doc?: unknown, ctx?: ToJSContext): T;
169
+ toString(): string;
170
+ }
171
+ //#endregion
172
+ //#region src/nodes/YAMLMap.d.ts
173
+ type MapLike = Map<any, any> | Set<any> | Record<string | number | symbol, any>;
174
+ type KeyArg<K extends Primitive | Node, V extends Primitive | Node> = K | NodeOf<K> | (K extends Scalar ? K["value"] : never) | Pair<K, V>;
175
+ declare class YAMLMap<K extends Primitive | Node = Primitive | Node, V extends Primitive | Node = Primitive | Node> implements CollectionBase {
176
+ #private;
177
+ static readonly tagName = "tag:yaml.org,2002:map";
178
+ schema: Schema;
179
+ values: Map<unknown, Pair<K, V>>;
180
+ /** An optional anchor on this map. Used by alias nodes. */
181
+ anchor?: string;
182
+ /** If true, stringify this and all child nodes using flow rather than block styles. */
183
+ flow?: boolean;
184
+ /** A comment on or immediately after this map. */
185
+ comment?: string | null;
186
+ /** A comment before this map. */
187
+ commentBefore?: string | null;
188
+ /**
189
+ * The `[start, value-end, node-end]` character offsets for
190
+ * the part of the source parsed into this map (undefined if not parsed).
191
+ * The `value-end` and `node-end` positions are themselves not included in their respective ranges.
192
+ */
193
+ range?: Range | null;
194
+ /** A blank line before this map and its commentBefore */
195
+ spaceBefore?: boolean;
196
+ /** The CST token that was composed into this map. */
197
+ srcToken?: BlockMap | FlowCollection;
198
+ /** A fully qualified tag, if required */
199
+ tag?: string;
200
+ /**
201
+ * A generic collection factory method that can be used
202
+ * by other node classes that inherit from YAMLMap
203
+ */
204
+ static create(nc: NodeCreator, obj: unknown): YAMLMap<any, any>;
205
+ constructor(schema: Schema, elements?: Array<Pair<K, V>>);
206
+ get size(): number;
207
+ /**
208
+ * Create a copy of this map.
209
+ *
210
+ * @param schema - If defined, overwrites the original's schema
211
+ */
212
+ clone(schema?: Schema): this;
213
+ /**
214
+ * Remove a value from the mapping.
215
+ * @returns `true` if the item was found and removed.
216
+ */
217
+ delete(key: KeyArg<K, V>): boolean;
218
+ /** Return value at `key`, or `undefined` if not found. */
219
+ get(key: KeyArg<K, V>): NodeOf<V> | null | undefined;
220
+ /** Return pair at `key`, or `undefined` if not found. */
221
+ getPair(key: KeyArg<K, V>): Pair<K, V> | undefined;
222
+ /** Check if the mapping includes a value with the key `key`. */
223
+ has(key: KeyArg<K, V>): boolean;
224
+ /**
225
+ * Return the internal Map key matching `key`, or `undefined` if not found.
226
+ *
227
+ * @param allowMissing - If `true`, a key is always returned,
228
+ * even if the key is not in the map.
229
+ */
230
+ keyOf(key: KeyArg<K, V>, allowMissing?: boolean): unknown;
231
+ pairs(): Iterable<Pair<K, V>>;
232
+ set(key: K | NodeOf<K> | (K extends Scalar ? K["value"] : never), value: V | NodeOf<V> | (V extends Scalar ? V["value"] : never) | null, options?: Omit<CreateNodeOptions, "aliasDuplicateObjects">): this;
233
+ set(pair: Pair<K, V>): this;
234
+ /**
235
+ * A plain JavaScript representation of this node.
236
+ *
237
+ * @param Type - If set, forces the returned collection type
238
+ * @returns Instance of Type, Map, or Object
239
+ */
240
+ toJS<T extends MapLike = Map<any, any>>(doc: Document<DocValue, boolean>, ctx: ToJSContext | undefined, Type: {
241
+ new (): T;
242
+ }): T;
243
+ toJS(doc: Document<DocValue, boolean>, ctx?: ToJSContext): any;
244
+ toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
245
+ }
246
+ //#endregion
247
+ //#region src/nodes/addPairToJSMap.d.ts
248
+ declare function addPairToJSMap(doc: Document<DocValue, boolean>, ctx: ToJSContext, map: MapLike, { key, value }: Pair, isPlainObject: boolean): MapLike;
249
+ //#endregion
250
+ //#region src/nodes/Pair.d.ts
251
+ declare class Pair<K extends Primitive | Node = Primitive | Node, V extends Primitive | Node = Primitive | Node> {
252
+ key: NodeOf<K>;
253
+ value: NodeOf<V> | null;
254
+ comment?: never;
255
+ commentBefore?: never;
256
+ spaceBefore?: never;
257
+ /** The CST token that was composed into this pair. */
258
+ srcToken?: CollectionItem;
259
+ constructor(key: NodeOf<K>, value?: NodeOf<V> | null);
260
+ clone(schema?: Schema): Pair<K, V>;
261
+ toJS(doc: Document<DocValue, boolean>, ctx: ToJSContext): ReturnType<typeof addPairToJSMap>;
262
+ toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
263
+ }
264
+ //#endregion
265
+ //#region src/schema/types.d.ts
266
+ interface TagBase {
267
+ /**
268
+ * An optional factory function, used e.g. by collections when wrapping JS objects as AST nodes.
269
+ */
270
+ createNode?: (nc: NodeCreator, value: unknown) => Node;
271
+ /**
272
+ * If `true`, allows for values to be stringified without
273
+ * an explicit tag together with `test`.
274
+ * If `'key'`, this only applies if the value is used as a mapping key.
275
+ * For most cases, it's unlikely that you'll actually want to use this,
276
+ * even if you first think you do.
277
+ */
278
+ default?: boolean | "key";
279
+ /**
280
+ * If a tag has multiple forms that should be parsed and/or stringified
281
+ * differently, use `format` to identify them.
282
+ */
283
+ format?: string;
284
+ /**
285
+ * Used by `YAML.createNode` to detect your data type, e.g. using `typeof` or
286
+ * `instanceof`.
287
+ */
288
+ identify?: (value: unknown) => boolean;
289
+ /**
290
+ * The identifier for your data type, with which its stringified form will be
291
+ * prefixed. Should either be a !-prefixed local `!tag`, or a fully qualified
292
+ * `tag:domain,date:foo`.
293
+ */
294
+ tag: string;
295
+ }
296
+ interface ScalarTag extends TagBase {
297
+ collection?: never;
298
+ nodeClass?: never;
299
+ /**
300
+ * Turns a value into an AST node.
301
+ * If returning a non-`Node` value, the output will be wrapped as a `Scalar`.
302
+ */
303
+ resolve(value: string, onError: (message: string) => void, options: ParseOptions): unknown;
304
+ /**
305
+ * Optional function stringifying a Scalar node. If your data includes a
306
+ * suitable `.toString()` method, you can probably leave this undefined and
307
+ * use the default stringifier.
308
+ *
309
+ * @param item The node being stringified.
310
+ * @param ctx Contains the stringifying context variables.
311
+ * @param onComment Callback to signal that the stringifier includes the
312
+ * item's comment in its output.
313
+ * @param onChompKeep Callback to signal that the output uses a block scalar
314
+ * type with the `+` chomping indicator.
315
+ */
316
+ stringify?: (item: Scalar, ctx: StringifyContext, onComment?: () => void, onChompKeep?: () => void) => string;
317
+ /**
318
+ * Together with `default` allows for values to be stringified without an
319
+ * explicit tag and detected using a regular expression or a test function.
320
+ * For most cases, it's unlikely that you'll actually want to use these,
321
+ * even if you first think you do.
322
+ */
323
+ test?: (value: string) => boolean;
324
+ }
325
+ interface CollectionTag extends TagBase {
326
+ stringify?: never;
327
+ test?: never;
328
+ /** The source collection type supported by this tag. */
329
+ collection: "map" | "seq";
330
+ createNode: (nc: NodeCreator, value: unknown) => Node;
331
+ /**
332
+ * The `Node` child class that implements this tag.
333
+ * If set, used to select this tag when stringifying.
334
+ */
335
+ nodeClass?: {
336
+ new (schema: Schema): Node;
337
+ };
338
+ /**
339
+ * Turns a value into an AST node.
340
+ * If returning a non-`Node` value, the output will be wrapped as a `Scalar`.
341
+ *
342
+ * Note: this is required if nodeClass is not provided.
343
+ */
344
+ resolve?: (value: Collection, onError: (message: string) => void, options: ParseOptions) => unknown;
345
+ }
346
+ //#endregion
347
+ //#region src/schema/tags.d.ts
348
+ type WithScalarTagTest = {
349
+ test: (value: string) => boolean;
350
+ };
351
+ declare const tagsByName: {
352
+ binary: ScalarTag;
353
+ bool: ScalarTag & WithScalarTagTest;
354
+ float: ScalarTag & WithScalarTagTest;
355
+ floatExp: ScalarTag & WithScalarTagTest;
356
+ floatNaN: ScalarTag & WithScalarTagTest;
357
+ floatTime: ScalarTag & WithScalarTagTest;
358
+ int: ScalarTag & WithScalarTagTest;
359
+ intHex: ScalarTag & WithScalarTagTest;
360
+ intOct: ScalarTag & WithScalarTagTest;
361
+ intTime: ScalarTag & WithScalarTagTest;
362
+ map: CollectionTag;
363
+ merge: ScalarTag & {
364
+ identify(value: unknown): boolean;
365
+ } & WithScalarTagTest;
366
+ null: ScalarTag & WithScalarTagTest;
367
+ omap: CollectionTag;
368
+ pairs: CollectionTag;
369
+ seq: CollectionTag;
370
+ set: CollectionTag;
371
+ timestamp: ScalarTag & WithScalarTagTest;
372
+ };
373
+ type TagId = keyof typeof tagsByName;
374
+ type Tags = Array<ScalarTag | CollectionTag | TagId>;
375
+ //#endregion
376
+ //#region src/options.d.ts
377
+ type ParseOptions = {
378
+ /**
379
+ * Whether integers should be parsed into BigInt rather than number values.
380
+ *
381
+ * Default: `false`
382
+ *
383
+ * https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/BigInt
384
+ */
385
+ intAsBigInt?: boolean;
386
+ /**
387
+ * Include a `srcToken` value on each parsed `Node`, containing the CST token
388
+ * that was composed into this node.
389
+ *
390
+ * Default: `false`
391
+ */
392
+ keepSourceTokens?: boolean;
393
+ /**
394
+ * If set, newlines will be tracked, to allow for `lineCounter.linePos(offset)`
395
+ * to provide the `{ line, col }` positions within the input.
396
+ */
397
+ lineCounter?: LineCounter;
398
+ /**
399
+ * Include line/col position & node type directly in parse errors.
400
+ *
401
+ * Default: `true`
402
+ */
403
+ prettyErrors?: boolean;
404
+ /**
405
+ * Detect and report errors that are required by the YAML 1.2 spec,
406
+ * but are caused by unambiguous content.
407
+ *
408
+ * Default: `true`
409
+ */
410
+ strict?: boolean;
411
+ /**
412
+ * Parse all mapping keys as strings. Treat all non-scalar keys as errors.
413
+ *
414
+ * Default: `false`
415
+ */
416
+ stringKeys?: boolean;
417
+ };
418
+ type DocumentOptions = {
419
+ /**
420
+ * Control the logging level during parsing
421
+ *
422
+ * Default: `'warn'`
423
+ */
424
+ logLevel?: LogLevelId;
425
+ /**
426
+ * The YAML version used by documents without a `%YAML` directive.
427
+ *
428
+ * Default: `"1.2"`
429
+ */
430
+ version?: "1.1" | "1.2" | "next";
431
+ };
432
+ type SchemaOptions = {
433
+ /**
434
+ * When parsing, warn about compatibility issues with the given schema.
435
+ * When stringifying, use scalar styles that are parsed correctly
436
+ * by the `compat` schema as well as the actual schema.
437
+ *
438
+ * Default: `null`
439
+ */
440
+ compat?: string | Tags | null;
441
+ /**
442
+ * Array of additional tags to include in the schema, or a function that may
443
+ * modify the schema's base tag array.
444
+ */
445
+ customTags?: Tags | ((tags: Tags) => Tags) | null;
446
+ /**
447
+ * Determine an internal Map key representation for map and set values,
448
+ * which is used for detecting duplicates and to identify values.
449
+ *
450
+ * Key equality is based on the SameValueZero algorithm.
451
+ *
452
+ * If merge keys are enabled by the schema,
453
+ * multiple `<<` keys are each considered unique.
454
+ */
455
+ mapKey?: (value: unknown) => unknown;
456
+ /**
457
+ * Enable support for `<<` merge keys.
458
+ *
459
+ * Default: `false` for YAML 1.2, `true` for earlier versions
460
+ */
461
+ merge?: boolean;
462
+ /**
463
+ * When using the `'core'` schema, support parsing values with these
464
+ * explicit YAML 1.1 tags:
465
+ *
466
+ * `!!binary`, `!!omap`, `!!pairs`, `!!set`, `!!timestamp`.
467
+ *
468
+ * Default `true`
469
+ */
470
+ resolveKnownTags?: boolean;
471
+ /**
472
+ * The base schema to use.
473
+ *
474
+ * The core library has built-in support for the following:
475
+ * - `'failsafe'`: A minimal schema that parses all scalars as strings
476
+ * - `'core'`: The YAML 1.2 core schema
477
+ * - `'json'`: The YAML 1.2 JSON schema, with minimal rules for JSON compatibility
478
+ * - `'yaml-1.1'`: The YAML 1.1 schema
479
+ *
480
+ * If using another (custom) schema, the `customTags` array needs to
481
+ * fully define the schema's tags.
482
+ *
483
+ * Default: `'core'` for YAML 1.2, `'yaml-1.1'` for earlier versions
484
+ */
485
+ schema?: string | Schema;
486
+ /**
487
+ * Override default values for `toString()` options.
488
+ */
489
+ toStringDefaults?: ToStringOptions;
490
+ };
491
+ type CreateNodeOptions = {
492
+ /**
493
+ * During node construction, use anchors and aliases to keep strictly equal
494
+ * non-null objects as equivalent in YAML.
495
+ *
496
+ * Default: `true`
497
+ */
498
+ aliasDuplicateObjects?: boolean;
499
+ /**
500
+ * Default prefix for anchors.
501
+ *
502
+ * Default: `'a'`, resulting in anchors `a1`, `a2`, etc.
503
+ */
504
+ anchorPrefix?: string;
505
+ /** Force the top-level collection node to use flow style. */
506
+ flow?: boolean;
507
+ /**
508
+ * Keep `undefined` object values when creating mappings, rather than
509
+ * discarding them.
510
+ *
511
+ * Default: `false`
512
+ */
513
+ keepUndefined?: boolean | null;
514
+ onTagObj?: (tagObj: ScalarTag | CollectionTag) => void;
515
+ /**
516
+ * Specify the top-level collection type, e.g. `"!!omap"`. Note that this
517
+ * requires the corresponding tag to be available in this document's schema.
518
+ */
519
+ tag?: string;
520
+ };
521
+ type ToJSOptions = {
522
+ /**
523
+ * Use Map rather than Object to represent mappings.
524
+ *
525
+ * Default: `false`
526
+ */
527
+ mapAsMap?: boolean;
528
+ /**
529
+ * Prevent exponential entity expansion attacks by limiting data aliasing count;
530
+ * set to `-1` to disable checks; `0` disallows all alias nodes.
531
+ *
532
+ * Default: `100`
533
+ */
534
+ maxAliasCount?: number;
535
+ /**
536
+ * If defined, called with the resolved `value` and reference `count` for
537
+ * each anchor in the document.
538
+ */
539
+ onAnchor?: (value: unknown, count: number) => void;
540
+ /**
541
+ * Optional function that may filter or modify the output JS value
542
+ *
543
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#using_the_reviver_parameter
544
+ */
545
+ reviver?: Reviver;
546
+ };
547
+ type ToStringOptions = {
548
+ /**
549
+ * Use block quote styles for scalar values where applicable.
550
+ * Set to `false` to disable block quotes completely.
551
+ *
552
+ * Default: `true`
553
+ */
554
+ blockQuote?: boolean | "folded" | "literal";
555
+ /**
556
+ * Enforce `'block'` or `'flow'` style on maps and sequences.
557
+ * Empty collections will always be stringified as `{}` or `[]`.
558
+ *
559
+ * Default: `'any'`, allowing each node to set its style separately
560
+ * with its `flow: boolean` (default `false`) property.
561
+ */
562
+ collectionStyle?: "any" | "block" | "flow";
563
+ /**
564
+ * Comment stringifier.
565
+ * Output should be valid for the current schema.
566
+ *
567
+ * By default, empty comment lines are left empty,
568
+ * lines consisting of a single space are replaced by `#`,
569
+ * and all other lines are prefixed with a `#`.
570
+ */
571
+ commentString?: (comment: string) => string;
572
+ /**
573
+ * The default type of string literal used to stringify implicit key values.
574
+ * Output may use other types if required to fully represent the value.
575
+ *
576
+ * If `null`, the value of `defaultStringType` is used.
577
+ *
578
+ * Default: `null`
579
+ */
580
+ defaultKeyType?: Scalar.Type | null;
581
+ /**
582
+ * The default type of string literal used to stringify values in general.
583
+ * Output may use other types if required to fully represent the value.
584
+ *
585
+ * Default: `'PLAIN'`
586
+ */
587
+ defaultStringType?: Scalar.Type;
588
+ /**
589
+ * Include directives in the output.
590
+ *
591
+ * - If `true`, at least the document-start marker `---` is always included.
592
+ * This does not force the `%YAML` directive to be included. To do that,
593
+ * set `doc.directives.yaml.explicit = true`.
594
+ * - If `false`, no directives or marker is ever included. If using the `%TAG`
595
+ * directive, you are expected to include it manually in the stream before
596
+ * its use.
597
+ * - If `null`, directives and marker may be included if required.
598
+ *
599
+ * Default: `null`
600
+ */
601
+ directives?: boolean | null;
602
+ /**
603
+ * Restrict double-quoted strings to use JSON-compatible syntax.
604
+ *
605
+ * Default: `false`
606
+ */
607
+ doubleQuotedAsJSON?: boolean;
608
+ /**
609
+ * Minimum length for double-quoted strings to use multiple lines to
610
+ * represent the value. Ignored if `doubleQuotedAsJSON` is set.
611
+ *
612
+ * Default: `40`
613
+ */
614
+ doubleQuotedMinMultiLineLength?: number;
615
+ /**
616
+ * String representation for `false`.
617
+ * With the core schema, use `'false'`, `'False'`, or `'FALSE'`.
618
+ *
619
+ * Default: `'false'`
620
+ */
621
+ falseStr?: string;
622
+ /**
623
+ * When true, a single space of padding will be added inside the delimiters
624
+ * of non-empty single-line flow collections.
625
+ *
626
+ * Default: `true`
627
+ */
628
+ flowCollectionPadding?: boolean;
629
+ /**
630
+ * The number of spaces to use when indenting code.
631
+ *
632
+ * Default: `2`
633
+ */
634
+ indent?: number;
635
+ /**
636
+ * Whether block sequences should be indented.
637
+ *
638
+ * Default: `true`
639
+ */
640
+ indentSeq?: boolean;
641
+ /**
642
+ * Maximum line width (set to `0` to disable folding).
643
+ *
644
+ * This is a soft limit, as only double-quoted semantics allow for inserting
645
+ * a line break in the middle of a word, as well as being influenced by the
646
+ * `minContentWidth` option.
647
+ *
648
+ * Default: `80`
649
+ */
650
+ lineWidth?: number;
651
+ /**
652
+ * Minimum line width for highly-indented content (set to `0` to disable).
653
+ *
654
+ * Default: `20`
655
+ */
656
+ minContentWidth?: number;
657
+ /**
658
+ * String representation for `null`.
659
+ * With the core schema, use `'null'`, `'Null'`, `'NULL'`, `'~'`, or an empty
660
+ * string `''`.
661
+ *
662
+ * Default: `'null'`
663
+ */
664
+ nullStr?: string;
665
+ /**
666
+ * Require keys to be scalars and to use implicit rather than explicit notation.
667
+ *
668
+ * Default: `false`
669
+ */
670
+ simpleKeys?: boolean;
671
+ /**
672
+ * Use 'single quote' rather than "double quote" where applicable.
673
+ * Set to `false` to disable single quotes completely.
674
+ *
675
+ * Default: `null`
676
+ */
677
+ singleQuote?: boolean | null;
678
+ /**
679
+ * When stringifying a map or a set, sort the entries.
680
+ * If `true`, sort by comparing key values with `<`.
681
+ *
682
+ * Default: `false`
683
+ */
684
+ sortMapEntries?: boolean | ((a: Pair, b: Pair) => number);
685
+ /**
686
+ * Add a trailing comma after the last entry in a flow map or flow sequence that's split across multiple lines.
687
+ *
688
+ * Default: `'false'`
689
+ */
690
+ trailingComma?: boolean;
691
+ /**
692
+ * String representation for `true`.
693
+ * With the core schema, use `'true'`, `'True'`, or `'TRUE'`.
694
+ *
695
+ * Default: `'true'`
696
+ */
697
+ trueStr?: string;
698
+ /**
699
+ * The anchor used by an alias must be defined before the alias node. As it's
700
+ * possible for the document to be modified manually, the order may be
701
+ * verified during stringification.
702
+ *
703
+ * Default: `'true'`
704
+ */
705
+ verifyAliasOrder?: boolean;
706
+ };
707
+ //#endregion
708
+ //#region src/schema/Schema.d.ts
709
+ declare class Schema {
710
+ compat: Array<CollectionTag | ScalarTag> | null;
711
+ knownTags: Record<string, CollectionTag | ScalarTag>;
712
+ mapKey: (value: unknown) => unknown;
713
+ name: string;
714
+ tags: Array<CollectionTag | ScalarTag>;
715
+ toStringOptions: Readonly<ToStringOptions> | null;
716
+ constructor({ compat, customTags, mapKey, merge, resolveKnownTags, schema, toStringDefaults }: SchemaOptions);
717
+ clone(): Schema;
718
+ }
719
+ //#endregion
720
+ //#region src/schema/common/map.d.ts
721
+ declare const map: {
722
+ collection: "map";
723
+ default: true;
724
+ nodeClass: typeof YAMLMap;
725
+ tag: string;
726
+ createNode(nc: NodeCreator, obj: unknown): YAMLMap<any, any>;
727
+ resolve(map: Collection, onError: (message: string) => void): YAMLMap<any, any>;
728
+ };
729
+ //#endregion
730
+ //#region src/nodes/YAMLSeq.d.ts
731
+ declare class YAMLSeq<T extends Primitive | Node | Pair = Primitive | Node | Pair> extends Array<NodeOf<T>> implements CollectionBase {
732
+ #private;
733
+ static get tagName(): "tag:yaml.org,2002:seq";
734
+ schema: Schema;
735
+ /** An optional anchor on this collection. Used by alias nodes. */
736
+ anchor?: string;
737
+ /**
738
+ * If true, stringify this and all child nodes using flow rather than
739
+ * block styles.
740
+ */
741
+ flow?: boolean;
742
+ /** A comment on or immediately after this collection. */
743
+ comment?: string | null;
744
+ /** A comment before this collection. */
745
+ commentBefore?: string | null;
746
+ /**
747
+ * The `[start, value-end, node-end]` character offsets for
748
+ * the part of the source parsed into this collection (undefined if not parsed).
749
+ * The `value-end` and `node-end` positions are themselves not included in their respective ranges.
750
+ */
751
+ range?: Range | null;
752
+ /** A blank line before this collection and its commentBefore */
753
+ spaceBefore?: boolean;
754
+ /** The CST token that was composed into this collection. */
755
+ srcToken?: BlockSequence | FlowCollection;
756
+ /** A fully qualified tag, if required */
757
+ tag?: string;
758
+ /**
759
+ * A generic collection factory method that can be extended
760
+ * to other node classes that inherit from YAMLSeq
761
+ */
762
+ static create(nc: NodeCreator, obj: unknown): YAMLSeq;
763
+ constructor(schema: Schema, elements?: Array<T | NodeOf<T>>);
764
+ get size(): number;
765
+ /**
766
+ * Create a copy of this collection.
767
+ *
768
+ * @param schema - If defined, overwrites the original's schema
769
+ */
770
+ clone(schema?: Schema): this;
771
+ /**
772
+ * Change all elements within a range of indices in this sequence to a static value.
773
+ *
774
+ * Non-node values are converted to Node values.
775
+ */
776
+ fill(value: T | NodeOf<T>, start?: number, end?: number): this;
777
+ /** @private */
778
+ _push(item: NodeOf<T>): void;
779
+ /**
780
+ * Append new elements to this sequence, and return its new length.
781
+ *
782
+ * Non-node values are converted to Node values.
783
+ */
784
+ push(...values: Array<T | NodeOf<T>>): number;
785
+ /**
786
+ * Set a value in this sequence.
787
+ *
788
+ * Non-node values are converted to Node values.
789
+ */
790
+ set(idx: number, value: T | NodeOf<T>, options?: Omit<CreateNodeOptions, "aliasDuplicateObjects">): void;
791
+ /**
792
+ * Changes the contents of this sequence by removing or replacing existing elements
793
+ * and/or adding new elements in place.
794
+ *
795
+ * Non-node values are converted to Node values.
796
+ */
797
+ splice(start: number, deleteCount?: number, ...values: Array<T | NodeOf<T>>): NodeOf<T>[];
798
+ /**
799
+ * Prepend new elements to this sequence, and return its new length.
800
+ *
801
+ * Non-node values are converted to Node values.
802
+ */
803
+ unshift(...values: Array<T | NodeOf<T>>): number;
804
+ /** A plain JavaScript representation of this node. */
805
+ toJS(doc: Document<DocValue, boolean>, ctx?: ToJSContext): any[];
806
+ toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
807
+ }
808
+ //#endregion
809
+ //#region src/schema/common/seq.d.ts
810
+ declare const seq: {
811
+ collection: "seq";
812
+ default: true;
813
+ nodeClass: typeof YAMLSeq;
814
+ tag: string;
815
+ createNode(nc: NodeCreator, obj: unknown): YAMLSeq;
816
+ resolve(seq: Collection, onError: (message: string) => void): YAMLSeq;
817
+ };
818
+ //#endregion
819
+ //#region src/schema/common/string.d.ts
820
+ declare const string: ScalarTag;
821
+ //#endregion
822
+ //#region src/stringify/foldFlowLines.d.ts
823
+ /**
824
+ * `'block'` prevents more-indented lines from being folded;
825
+ * `'quoted'` allows for `\` escapes, including escaped newlines
826
+ */
827
+ type FoldMode = "flow" | "block" | "quoted";
828
+ interface FoldOptions {
829
+ /**
830
+ * Accounts for leading contents on the first line, defaulting to
831
+ * `indent.length`
832
+ */
833
+ indentAtStart?: number;
834
+ /** Default: `80` */
835
+ lineWidth?: number;
836
+ /**
837
+ * Allow highly indented lines to stretch the line width or indent content
838
+ * from the start.
839
+ *
840
+ * Default: `20`
841
+ */
842
+ minContentWidth?: number;
843
+ /** Called once if the text is folded */
844
+ onFold?: () => void;
845
+ /** Called once if any line of text exceeds lineWidth characters */
846
+ onOverflow?: () => void;
847
+ }
848
+ /**
849
+ * Tries to keep input at up to `lineWidth` characters, splitting only on spaces
850
+ * not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are
851
+ * terminated with `\n` and started with `indent`.
852
+ */
853
+ declare function foldFlowLines(text: string, indent: string, mode?: FoldMode, { indentAtStart, lineWidth, minContentWidth, onFold, onOverflow }?: FoldOptions): string;
854
+ //#endregion
855
+ //#region src/stringify/stringifyNumber.d.ts
856
+ declare function stringifyNumber({ format, minFractionDigits, source, tag, value }: Scalar, version?: "1.1" | "1.2"): string;
857
+ //#endregion
858
+ //#region src/stringify/stringifyString.d.ts
859
+ interface StringifyScalar {
860
+ value: string;
861
+ comment?: string | null;
862
+ type?: string;
863
+ }
864
+ declare function stringifyString(item: Scalar | StringifyScalar, ctx: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
865
+ //#endregion
866
+ //#region src/nodes/YAMLSet.d.ts
867
+ declare class YAMLSet<T extends Primitive | Node = Primitive | Node> implements CollectionBase {
868
+ #private;
869
+ static readonly tagName = "tag:yaml.org,2002:set";
870
+ schema: Schema;
871
+ /** A fully qualified tag */
872
+ tag: string;
873
+ values: Map<unknown, NodeOf<T>>;
874
+ /** An optional anchor on this set. Used by alias nodes. */
875
+ anchor?: string;
876
+ /** If true, stringify this and all child nodes using flow rather than block styles. */
877
+ flow?: boolean;
878
+ /** A comment on or immediately after this set. */
879
+ comment?: string | null;
880
+ /** A comment before this set. */
881
+ commentBefore?: string | null;
882
+ /**
883
+ * The `[start, value-end, node-end]` character offsets for
884
+ * the part of the source parsed into this set (undefined if not parsed).
885
+ * The `value-end` and `node-end` positions are themselves not included in their respective ranges.
886
+ */
887
+ range?: Range | null;
888
+ /** A blank line before this set and its commentBefore */
889
+ spaceBefore?: boolean;
890
+ /** The CST token that was composed into this set. */
891
+ srcToken?: BlockMap | FlowCollection;
892
+ constructor(schema: Schema);
893
+ get size(): number;
894
+ add(value: T | NodeOf<T>, options?: Omit<CreateNodeOptions, "aliasDuplicateObjects">): this;
895
+ /**
896
+ * Create a copy of this set.
897
+ *
898
+ * @param schema - If defined, overwrites the original's schema
899
+ */
900
+ clone(schema?: Schema): this;
901
+ /**
902
+ * Remove `value` from the set.
903
+ * @returns `true` if the item was found and removed.
904
+ */
905
+ delete(value: T | NodeOf<T>): boolean;
906
+ /** Return the node matching `value`, if the set includes it. */
907
+ get(value: T | NodeOf<T>): NodeOf<T> | undefined;
908
+ /** Check if the set includes `value`. */
909
+ has(value: T | NodeOf<T>): boolean;
910
+ /**
911
+ * Return the internal Map key matching `value`, or `undefined` if not found.
912
+ *
913
+ * @param allowMissing - If `true`, a key is always returned,
914
+ * even if the value is not in the set.
915
+ */
916
+ keyOf(value: T | NodeOf<T>, allowMissing?: boolean): unknown;
917
+ /** A plain JavaScript representation of this set. */
918
+ toJS(doc: Document<DocValue, boolean>, ctx?: ToJSContext): Set<any>;
919
+ toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
920
+ }
921
+ //#endregion
922
+ //#region src/nodes/types.d.ts
923
+ type Collection = YAMLMap | YAMLSeq | YAMLSet;
924
+ type Node = Scalar | Collection | Alias;
925
+ type Primitive = boolean | number | bigint | string | null;
926
+ type NodeOf<T> = T extends Primitive ? Scalar<T> : T;
927
+ /** Utility type mapper */
928
+ type NodeType<T> = T extends string | number | bigint | boolean | null | undefined ? Scalar<T> : T extends Date ? Scalar<string | Date> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends Set<any> ? YAMLSet<NodeType<keyof T>> : T extends {
929
+ [key: string | number]: any;
930
+ } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
931
+ type Range = [start: number, valueEnd: number, nodeEnd: number];
932
+ interface NodeBase {
933
+ /** A comment on or immediately after this */
934
+ comment?: string | null;
935
+ /** A comment before this */
936
+ commentBefore?: string | null;
937
+ /**
938
+ * The `[start, value-end, node-end]` character offsets for the part of the
939
+ * source parsed into this node (undefined if not parsed). The `value-end`
940
+ * and `node-end` positions are themselves not included in their respective
941
+ * ranges.
942
+ */
943
+ range?: Range | null;
944
+ /** A blank line before this node and its commentBefore */
945
+ spaceBefore?: boolean;
946
+ /** The CST token that was composed into this node. */
947
+ srcToken?: Token;
948
+ /** A fully qualified tag, if required */
949
+ tag?: string;
950
+ /**
951
+ * Create a copy of this node.
952
+ *
953
+ * @param schema - If defined, overwrites the original's schema for cloned collections.
954
+ */
955
+ clone(schema?: Schema): this;
956
+ /** A plain JavaScript representation of this node. */
957
+ toJS(doc: Document<DocValue, boolean>, opt?: ToJSContext): any;
958
+ toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
959
+ }
960
+ interface CollectionBase extends NodeBase {
961
+ schema: Schema;
962
+ /** An optional anchor on this collection. Used by alias nodes. */
963
+ anchor?: string;
964
+ /** If true, stringify this and all child nodes using flow styles. */
965
+ flow?: boolean;
966
+ /** The number of items in this collection. */
967
+ readonly size: number;
968
+ /** Create a deep copy of this collection */
969
+ clone(schema?: Schema): this;
970
+ }
971
+ //#endregion
972
+ //#region src/parse/cst-scalar.d.ts
973
+ /**
974
+ * If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
975
+ * Otherwise, return `null`.
976
+ */
977
+ declare function resolveAsScalar(token: FlowScalar | BlockScalar, strict?: boolean, onError?: (offset: number, code: ErrorCode, message: string) => void): {
978
+ value: string;
979
+ type: Scalar.Type | null;
980
+ comment: string;
981
+ range: Range;
982
+ };
983
+ declare function resolveAsScalar(token: Token | null | undefined, strict?: boolean, onError?: (offset: number, code: ErrorCode, message: string) => void): {
984
+ value: string;
985
+ type: Scalar.Type | null;
986
+ comment: string;
987
+ range: Range;
988
+ } | null;
989
+ /**
990
+ * Create a new scalar token with `value`
991
+ *
992
+ * Values that represent an actual string but may be parsed as a different type should use a `type` other than `'PLAIN'`,
993
+ * as this function does not support any schema operations and won't check for such conflicts.
994
+ *
995
+ * @param value The string representation of the value, which will have its content properly indented.
996
+ * @param context.end Comments and whitespace after the end of the value, or after the block scalar header. If undefined, a newline will be added.
997
+ * @param context.implicitKey Being within an implicit key may affect the resolved type of the token's value.
998
+ * @param context.indent The indent level of the token.
999
+ * @param context.inFlow Is this scalar within a flow collection? This may affect the resolved type of the token's value.
1000
+ * @param context.offset The offset position of the token.
1001
+ * @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
1002
+ */
1003
+ declare function createScalarToken(value: string, context: {
1004
+ end?: SourceToken[];
1005
+ implicitKey?: boolean;
1006
+ indent: number;
1007
+ inFlow?: boolean;
1008
+ offset?: number;
1009
+ type?: Scalar.Type;
1010
+ }): BlockScalar | FlowScalar;
1011
+ /**
1012
+ * Set the value of `token` to the given string `value`, overwriting any previous contents and type that it may have.
1013
+ *
1014
+ * Best efforts are made to retain any comments previously associated with the `token`,
1015
+ * though all contents within a collection's `items` will be overwritten.
1016
+ *
1017
+ * Values that represent an actual string but may be parsed as a different type should use a `type` other than `'PLAIN'`,
1018
+ * as this function does not support any schema operations and won't check for such conflicts.
1019
+ *
1020
+ * @param token Any token. If it does not include an `indent` value, the value will be stringified as if it were an implicit key.
1021
+ * @param value The string representation of the value, which will have its content properly indented.
1022
+ * @param context.afterKey In most cases, values after a key should have an additional level of indentation.
1023
+ * @param context.implicitKey Being within an implicit key may affect the resolved type of the token's value.
1024
+ * @param context.inFlow Being within a flow collection may affect the resolved type of the token's value.
1025
+ * @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
1026
+ */
1027
+ declare function setScalarValue(token: Token, value: string, context?: {
1028
+ afterKey?: boolean;
1029
+ implicitKey?: boolean;
1030
+ inFlow?: boolean;
1031
+ type?: Scalar.Type;
1032
+ }): void;
1033
+ //#endregion
1034
+ //#region src/parse/cst-stringify.d.ts
1035
+ /**
1036
+ * Stringify a CST document, token, or collection item
1037
+ *
1038
+ * Fair warning: This applies no validation whatsoever, and
1039
+ * simply concatenates the sources in their logical order.
1040
+ */
1041
+ declare const stringify: (cst: Token | CollectionItem) => string;
1042
+ //#endregion
1043
+ //#region src/parse/cst-visit.d.ts
1044
+ type VisitPath = readonly ["key" | "value", number][];
1045
+ type Visitor = (item: CollectionItem, path: VisitPath) => number | symbol | Visitor | void;
1046
+ /**
1047
+ * Apply a visitor to a CST document or item.
1048
+ *
1049
+ * Walks through the tree (depth-first) starting from the root, calling a
1050
+ * `visitor` function with two arguments when entering each item:
1051
+ * - `item`: The current item, which included the following members:
1052
+ * - `start: SourceToken[]` – Source tokens before the key or value,
1053
+ * possibly including its anchor or tag.
1054
+ * - `key?: Token | null` – Set for pair values. May then be `null`, if
1055
+ * the key before the `:` separator is empty.
1056
+ * - `sep?: SourceToken[]` – Source tokens between the key and the value,
1057
+ * which should include the `:` map value indicator if `value` is set.
1058
+ * - `value?: Token` – The value of a sequence item, or of a map pair.
1059
+ * - `path`: The steps from the root to the current node, as an array of
1060
+ * `['key' | 'value', number]` tuples.
1061
+ *
1062
+ * The return value of the visitor may be used to control the traversal:
1063
+ * - `undefined` (default): Do nothing and continue
1064
+ * - `visit.SKIP`: Do not visit the children of this token, continue with
1065
+ * next sibling
1066
+ * - `visit.BREAK`: Terminate traversal completely
1067
+ * - `visit.REMOVE`: Remove the current item, then continue with the next one
1068
+ * - `number`: Set the index of the next step. This is useful especially if
1069
+ * the index of the current token has changed.
1070
+ * - `function`: Define the next visitor for this item. After the original
1071
+ * visitor is called on item entry, next visitors are called after handling
1072
+ * a non-empty `key` and when exiting the item.
1073
+ */
1074
+ declare const visit: {
1075
+ (cst: Document$1 | CollectionItem, visitor: Visitor): void;
1076
+ /** Terminate visit traversal completely */
1077
+ BREAK: symbol;
1078
+ /** Do not visit the children of the current item */
1079
+ SKIP: symbol;
1080
+ /** Remove the current item */
1081
+ REMOVE: symbol;
1082
+ /** Find the item at `path` from `cst` as the root */
1083
+ itemAtPath(cst: Document$1 | CollectionItem, path: VisitPath): CollectionItem | undefined;
1084
+ /**
1085
+ * Get the immediate parent collection of the item at `path` from `cst` as the root.
1086
+ *
1087
+ * Throws an error if the collection is not found, which should never happen if the item itself exists.
1088
+ */
1089
+ parentCollection(cst: Document$1 | CollectionItem, path: VisitPath): BlockMap | BlockSequence | FlowCollection;
1090
+ };
1091
+ declare namespace cst_d_exports {
1092
+ export { BOM, BlockMap, BlockScalar, BlockSequence, CollectionItem, DOCUMENT, Directive, Document$1 as Document, DocumentEnd, ErrorToken, FLOW_END, FlowCollection, FlowScalar, SCALAR, SourceToken, Token, TokenType, VisitPath, Visitor, createScalarToken, isCollection, isScalar, prettyToken, resolveAsScalar, setScalarValue, stringify, tokenType, visit };
1093
+ }
1094
+ interface SourceToken {
1095
+ type: "byte-order-mark" | "doc-mode" | "doc-start" | "space" | "comment" | "newline" | "directive-line" | "anchor" | "tag" | "seq-item-ind" | "explicit-key-ind" | "map-value-ind" | "flow-map-start" | "flow-map-end" | "flow-seq-start" | "flow-seq-end" | "flow-error-end" | "comma" | "block-scalar-header";
1096
+ offset: number;
1097
+ indent: number;
1098
+ source: string;
1099
+ }
1100
+ interface ErrorToken {
1101
+ type: "error";
1102
+ offset: number;
1103
+ source: string;
1104
+ message: string;
1105
+ }
1106
+ interface Directive {
1107
+ type: "directive";
1108
+ offset: number;
1109
+ source: string;
1110
+ }
1111
+ interface Document$1 {
1112
+ type: "document";
1113
+ offset: number;
1114
+ start: SourceToken[];
1115
+ value?: Token;
1116
+ end?: SourceToken[];
1117
+ }
1118
+ interface DocumentEnd {
1119
+ type: "doc-end";
1120
+ offset: number;
1121
+ source: string;
1122
+ end?: SourceToken[];
1123
+ }
1124
+ interface FlowScalar {
1125
+ type: "alias" | "scalar" | "single-quoted-scalar" | "double-quoted-scalar";
1126
+ offset: number;
1127
+ indent: number;
1128
+ source: string;
1129
+ end?: SourceToken[];
1130
+ }
1131
+ interface BlockScalar {
1132
+ type: "block-scalar";
1133
+ offset: number;
1134
+ indent: number;
1135
+ props: Token[];
1136
+ source: string;
1137
+ }
1138
+ interface BlockMap {
1139
+ type: "block-map";
1140
+ offset: number;
1141
+ indent: number;
1142
+ items: Array<{
1143
+ start: SourceToken[];
1144
+ explicitKey?: true;
1145
+ key?: never;
1146
+ sep?: never;
1147
+ value?: never;
1148
+ } | {
1149
+ start: SourceToken[];
1150
+ explicitKey?: true;
1151
+ key: Token | null;
1152
+ sep: SourceToken[];
1153
+ value?: Token;
1154
+ }>;
1155
+ }
1156
+ interface BlockSequence {
1157
+ type: "block-seq";
1158
+ offset: number;
1159
+ indent: number;
1160
+ items: Array<{
1161
+ start: SourceToken[];
1162
+ key?: never;
1163
+ sep?: never;
1164
+ value?: Token;
1165
+ }>;
1166
+ }
1167
+ type CollectionItem = {
1168
+ start: SourceToken[];
1169
+ key?: Token | null;
1170
+ sep?: SourceToken[];
1171
+ value?: Token;
1172
+ };
1173
+ interface FlowCollection {
1174
+ type: "flow-collection";
1175
+ offset: number;
1176
+ indent: number;
1177
+ start: SourceToken;
1178
+ items: CollectionItem[];
1179
+ end: SourceToken[];
1180
+ }
1181
+ type Token = SourceToken | ErrorToken | Directive | Document$1 | DocumentEnd | FlowScalar | BlockScalar | BlockMap | BlockSequence | FlowCollection;
1182
+ type TokenType = SourceToken["type"] | DocumentEnd["type"] | FlowScalar["type"];
1183
+ /** The byte order mark */
1184
+ declare const BOM = "";
1185
+ /** Start of doc-mode */
1186
+ declare const DOCUMENT = "";
1187
+ /** Unexpected end of flow-mode */
1188
+ declare const FLOW_END = "";
1189
+ /** Next token is a scalar value */
1190
+ declare const SCALAR = "";
1191
+ /** @returns `true` if `token` is a flow or block collection */
1192
+ declare const isCollection: (token: Token | null | undefined) => token is BlockMap | BlockSequence | FlowCollection;
1193
+ /** @returns `true` if `token` is a flow or block scalar; not an alias */
1194
+ declare const isScalar: (token: Token | null | undefined) => token is FlowScalar | BlockScalar;
1195
+ /** Get a printable representation of a lexer token */
1196
+ declare function prettyToken(token: string): string;
1197
+ /** Identify the type of a lexer token. May return `null` for unknown tokens. */
1198
+ declare function tokenType(source: string): TokenType | null;
1199
+ //#endregion
1200
+ //#region src/nodes/Alias.d.ts
1201
+ declare class Alias implements NodeBase {
1202
+ source: string;
1203
+ anchor?: never;
1204
+ /** A comment on or immediately after this node. */
1205
+ comment?: string | null;
1206
+ /** A comment before this node. */
1207
+ commentBefore?: string | null;
1208
+ /**
1209
+ * The `[start, value-end, node-end]` character offsets for
1210
+ * the part of the source parsed into this node (undefined if not parsed).
1211
+ * The `value-end` and `node-end` positions are themselves not included in their respective ranges.
1212
+ */
1213
+ range?: Range | null;
1214
+ /** A blank line before this node and its commentBefore */
1215
+ spaceBefore?: boolean;
1216
+ /** The CST token that was composed into this node. */
1217
+ srcToken?: FlowScalar & {
1218
+ type: "alias";
1219
+ };
1220
+ tag?: never;
1221
+ constructor(source: string);
1222
+ /** Create a copy of this node. */
1223
+ clone(): this;
1224
+ /**
1225
+ * Resolve the value of this alias within `doc`, finding the last
1226
+ * instance of the `source` anchor before this node.
1227
+ */
1228
+ resolve(doc: Document, ctx?: ToJSContext): Scalar | YAMLMap | YAMLSeq | YAMLSet | undefined;
1229
+ /** A plain JavaScript representation of the resolved value of this alias. */
1230
+ toJS(doc: Document<DocValue, boolean>, ctx?: ToJSContext): any;
1231
+ toString(ctx?: StringifyContext, _onComment?: () => void, _onChompKeep?: () => void): string;
1232
+ }
1233
+ //#endregion
1234
+ //#region src/doc/Document.d.ts
1235
+ type DocValue = Scalar | YAMLSeq | YAMLMap | YAMLSet;
1236
+ type Replacer = any[] | ((key: any, value: any) => unknown);
1237
+ declare namespace Document {
1238
+ /** @ts-ignore The typing of directives fails in TS <= 4.2 */
1239
+ interface Parsed<Value extends DocValue = DocValue, Strict extends boolean = true> extends Document<Value, Strict> {
1240
+ directives: Directives;
1241
+ range: Range;
1242
+ }
1243
+ }
1244
+ declare class Document<Value extends DocValue = DocValue, Strict extends boolean = true> {
1245
+ /** A comment before this Document */
1246
+ commentBefore: string | null;
1247
+ /** A comment immediately after this Document */
1248
+ comment: string | null;
1249
+ /** The document value. */
1250
+ value: Value;
1251
+ directives: Strict extends true ? Directives | undefined : Directives;
1252
+ /** Errors encountered during parsing. */
1253
+ errors: YAMLError[];
1254
+ options: Required<Omit<ParseOptions & DocumentOptions, "_directives" | "lineCounter" | "version">>;
1255
+ /**
1256
+ * The `[start, value-end, node-end]` character offsets for the part of the
1257
+ * source parsed into this document (undefined if not parsed). The `value-end`
1258
+ * and `node-end` positions are themselves not included in their respective
1259
+ * ranges.
1260
+ */
1261
+ range?: Range;
1262
+ /** The schema used with the document. Use `setSchema()` to change. */
1263
+ schema: Schema;
1264
+ /** Warnings encountered during parsing. */
1265
+ warnings: YAMLWarning[];
1266
+ /**
1267
+ * @param value - The initial value for the document, which will be wrapped
1268
+ * in a Node container.
1269
+ */
1270
+ constructor(value?: any, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions);
1271
+ constructor(value: any, replacer: null | Replacer, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions);
1272
+ /**
1273
+ * Create a deep copy of this Document and its value.
1274
+ *
1275
+ * Custom Node values that inherit from `Object` still refer to their original instances.
1276
+ */
1277
+ clone(): Document<Value, Strict>;
1278
+ /**
1279
+ * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
1280
+ *
1281
+ * If `node` already has an anchor, `name` is ignored.
1282
+ * Otherwise, the `node.anchor` value will be set to `name`,
1283
+ * or if an anchor with that name is already present in the document,
1284
+ * `name` will be used as a prefix for a new unique anchor.
1285
+ * If `name` is undefined, the generated anchor will use 'a' as a prefix.
1286
+ */
1287
+ createAlias(node: Strict extends true ? DocValue : Node, name?: string): Alias;
1288
+ /**
1289
+ * Convert any value into a `Node` using the current schema, recursively
1290
+ * turning objects into collections.
1291
+ */
1292
+ createNode<T = unknown>(value: T, options?: CreateNodeOptions): NodeType<T>;
1293
+ createNode<T = unknown>(value: T, replacer: Replacer | CreateNodeOptions | null, options?: CreateNodeOptions): NodeType<T>;
1294
+ /**
1295
+ * Convert a key and a value into a `Pair` using the current schema,
1296
+ * recursively wrapping all values as `Scalar` or `Collection` nodes.
1297
+ */
1298
+ createPair<K = unknown, V = unknown>(key: K, value: V, options?: CreateNodeOptions): Pair<K extends Primitive | Node ? K : Node, V extends Primitive | Node ? V : Node>;
1299
+ /**
1300
+ * Returns item at `key`, or `undefined` if not found.
1301
+ */
1302
+ get(key: any): Strict extends true ? Node | Pair | null | undefined : any;
1303
+ /**
1304
+ * Returns pair at `key`, or `undefined` if not found.
1305
+ */
1306
+ getPair(key: any): Strict extends true ? Pair | undefined : any;
1307
+ /**
1308
+ * Sets a value in this document's top-level collection. For `!!set`, `value` is ignored.
1309
+ */
1310
+ set(key: any, value: any): void;
1311
+ /**
1312
+ * Change the YAML version and schema used by the document.
1313
+ * A `null` version disables support for directives, explicit tags, anchors, and aliases.
1314
+ * It also requires the `schema` option to be given as a `Schema` instance value.
1315
+ *
1316
+ * Overrides all previously set schema options.
1317
+ */
1318
+ setSchema(version: "1.1" | "1.2" | "next" | null, options?: SchemaOptions): void;
1319
+ /** A plain JavaScript representation of the document `value`. */
1320
+ toJS(opt?: ToJSOptions): any;
1321
+ /** A JSON representation of the document `value`. */
1322
+ toJSON(): any;
1323
+ /** A YAML representation of the document. */
1324
+ toString(options?: ToStringOptions): string;
1325
+ }
1326
+ //#endregion
1327
+ //#region src/doc/directives.d.ts
1328
+ declare class Directives {
1329
+ static defaultYaml: Directives["yaml"];
1330
+ static defaultTags: Directives["tags"];
1331
+ yaml: {
1332
+ version: "1.1" | "1.2" | "next";
1333
+ explicit?: boolean;
1334
+ };
1335
+ tags: Record<string, string>;
1336
+ /**
1337
+ * The directives-end/doc-start marker `---`. If `null`, a marker may still be
1338
+ * included in the document's stringified representation.
1339
+ */
1340
+ docStart: true | null;
1341
+ /** The doc-end marker `...`. */
1342
+ docEnd: boolean;
1343
+ /**
1344
+ * Used when parsing YAML 1.1, where:
1345
+ * > If the document specifies no directives, it is parsed using the same
1346
+ * > settings as the previous document. If the document does specify any
1347
+ * > directives, all directives of previous documents, if any, are ignored.
1348
+ */
1349
+ private atNextDocument?;
1350
+ constructor(yaml?: Directives["yaml"], tags?: Directives["tags"]);
1351
+ clone(): Directives;
1352
+ /**
1353
+ * During parsing, get a Directives instance for the current document and
1354
+ * update the stream state according to the current version's spec.
1355
+ */
1356
+ atDocument(): Directives;
1357
+ /**
1358
+ * @param onError - May be called even if the action was successful
1359
+ * @returns `true` on success
1360
+ */
1361
+ add(line: string, onError: (offset: number, message: string, warning?: boolean) => void): boolean;
1362
+ /**
1363
+ * Resolves a tag, matching handles to those defined in %TAG directives.
1364
+ *
1365
+ * @returns Resolved tag, which may also be the non-specific tag `'!'` or a
1366
+ * `'!local'` tag, or `null` if unresolvable.
1367
+ */
1368
+ tagName(source: string, onError: (message: string) => void): string | null;
1369
+ /**
1370
+ * Given a fully resolved tag, returns its printable string form,
1371
+ * taking into account current tag prefixes and defaults.
1372
+ */
1373
+ tagString(tag: string): string;
1374
+ toString(doc?: Document): string;
1375
+ }
1376
+ //#endregion
1377
+ export { CollectionTag as A, debug as B, DocumentOptions as C, ToStringOptions as D, ToJSOptions as E, Scalar as F, YAMLParseError as G, Reviver as H, NodeCreator as I, YAMLWarning as K, ToJSContext as L, Pair as M, KeyArg as N, TagId as O, YAMLMap as P, StringifyContext as R, CreateNodeOptions as S, SchemaOptions as T, ErrorCode as U, warn as V, YAMLError as W, string as _, Alias as a, map as b, Node as c, Range as d, YAMLSet as f, foldFlowLines as g, FoldOptions as h, Replacer as i, ScalarTag as j, Tags as k, NodeBase as l, stringifyNumber as m, DocValue as n, Token as o, stringifyString as p, LineCounter as q, Document as r, cst_d_exports as s, Directives as t, Primitive as u, seq as v, ParseOptions as w, Schema as x, YAMLSeq as y, LogLevelId as z };