yaml 2.8.2 → 3.0.0-0

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