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