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.
Files changed (238) hide show
  1. package/README.md +65 -85
  2. package/{bin.mjs → bin.js} +1 -1
  3. package/dist/chunk-pbuEa-1d.js +13 -0
  4. package/dist/cli.d.ts +10 -7
  5. package/dist/cli.js +180 -0
  6. package/dist/directives-CiM56lHW.js +2963 -0
  7. package/dist/directives-DlYEVlkC.d.ts +1396 -0
  8. package/dist/index.d.ts +320 -25
  9. package/dist/index.js +4 -50
  10. package/dist/line-counter-bmCJ4fGy.js +3086 -0
  11. package/dist/public-api-BTMehGT6.js +77 -0
  12. package/dist/test-events.d.ts +6 -3
  13. package/dist/test-events.js +105 -126
  14. package/dist/util.d.ts +2 -16
  15. package/dist/util.js +2 -28
  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 -109
  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 -225
  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 -116
  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 -67
  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 -129
  82. package/browser/dist/stringify/stringifyCollection.js +0 -153
  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 -25
  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 -112
  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 -227
  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 -118
  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 -47
  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 -350
  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 -71
  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 -132
  224. package/dist/stringify/stringifyCollection.d.ts +0 -17
  225. package/dist/stringify/stringifyCollection.js +0 -155
  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 -27
  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
package/dist/index.d.ts CHANGED
@@ -1,25 +1,320 @@
1
- export { Composer } from './compose/composer';
2
- export { Document } from './doc/Document';
3
- export { Schema } from './schema/Schema';
4
- export type { ErrorCode } from './errors';
5
- export { YAMLError, YAMLParseError, YAMLWarning } from './errors';
6
- export { Alias } from './nodes/Alias';
7
- export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/identity';
8
- export type { Node, ParsedNode, Range } from './nodes/Node';
9
- export { Pair } from './nodes/Pair';
10
- export { Scalar } from './nodes/Scalar';
11
- export { YAMLMap } from './nodes/YAMLMap';
12
- export { YAMLSeq } from './nodes/YAMLSeq';
13
- export type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options';
14
- export * as CST from './parse/cst';
15
- export { Lexer } from './parse/lexer';
16
- export { LineCounter } from './parse/line-counter';
17
- export { Parser } from './parse/parser';
18
- export type { EmptyStream } from './public-api';
19
- export { parse, parseAllDocuments, parseDocument, stringify } from './public-api';
20
- export type { TagId, Tags } from './schema/tags';
21
- export type { CollectionTag, ScalarTag } from './schema/types';
22
- export type { YAMLOMap } from './schema/yaml-1.1/omap';
23
- export type { YAMLSet } from './schema/yaml-1.1/set';
24
- export type { asyncVisitor, asyncVisitorFn, visitor, visitorFn } from './visit';
25
- export { visit, visitAsync } from './visit';
1
+ import { A as CollectionTag, C as DocumentOptions, D as ToStringOptions, E as ToJSOptions, F as Scalar, G as YAMLParseError, H as Reviver, K as YAMLWarning, L as ToJSContext, M as Pair, N as KeyArg, O as TagId, P as YAMLMap, R as StringifyContext, S as CreateNodeOptions, T as SchemaOptions, U as ErrorCode, W as YAMLError, a as Alias, c as Node, d as Range, f as YAMLSet, i as Replacer, j as ScalarTag, k as Tags, l as NodeBase, n as DocValue, o as Token, q as LineCounter, r as Document, s as cst_d_exports, t as Directives, u as Primitive, w as ParseOptions, x as Schema, y as YAMLSeq } from "./directives-DlYEVlkC.js";
2
+
3
+ //#region src/compose/composer.d.ts
4
+ /**
5
+ * Compose a stream of CST nodes into a stream of YAML Documents.
6
+ *
7
+ * ```ts
8
+ * import { Composer, Parser } from 'yaml'
9
+ *
10
+ * const src: string = ...
11
+ * const tokens = new Parser().parse(src)
12
+ * const docs = new Composer().compose(tokens)
13
+ * ```
14
+ */
15
+ declare class Composer<Value extends DocValue = DocValue, Strict extends boolean = true> {
16
+ private directives;
17
+ private doc;
18
+ private docs;
19
+ private options;
20
+ private atDirectives;
21
+ private prelude;
22
+ private errors;
23
+ private warnings;
24
+ constructor(options?: ParseOptions & DocumentOptions & SchemaOptions);
25
+ private onError;
26
+ private decorate;
27
+ /**
28
+ * Current stream status information.
29
+ *
30
+ * Mostly useful at the end of input for an empty stream.
31
+ */
32
+ streamInfo(): {
33
+ comment: string;
34
+ directives: Directives;
35
+ errors: YAMLParseError[];
36
+ warnings: YAMLWarning[];
37
+ };
38
+ /**
39
+ * Compose tokens into documents.
40
+ *
41
+ * @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
42
+ * @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
43
+ */
44
+ compose(tokens: Iterable<Token>, forceDoc?: boolean, endOffset?: number): Document.Parsed<Value, Strict>[];
45
+ /** Advance the composer by one CST token. */
46
+ next(token: Token): void;
47
+ /**
48
+ * Call at end of input to handle any remaining document.
49
+ *
50
+ * @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
51
+ * @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
52
+ */
53
+ end(forceDoc?: boolean, endOffset?: number): Document.Parsed<Value, Strict>[];
54
+ }
55
+ //#endregion
56
+ //#region src/nodes/identity.d.ts
57
+ /** Type predicate for collections */
58
+ declare const isCollection: (node: unknown) => node is YAMLMap | YAMLSeq | YAMLSet;
59
+ /** Type predicate for `Node` values */
60
+ declare const isNode: (node: unknown) => node is Node;
61
+ //#endregion
62
+ //#region src/parse/lexer.d.ts
63
+ /**
64
+ * Splits an input `source` string into lexical YAML tokens,
65
+ * i.e. smaller strings that are easily identifiable by `tokens.tokenType()`.
66
+ *
67
+ * Lexing starts always in a "stream" context.
68
+ *
69
+ * In addition to slices of the original input, the following control characters
70
+ * may also be emitted:
71
+ *
72
+ * - `\x02` (Start of Text): A document starts with the next token
73
+ * - `\x18` (Cancel): Unexpected end of flow-mode (indicates an error)
74
+ * - `\x1f` (Unit Separator): Next token is a scalar value
75
+ * - `\u{FEFF}` (Byte order mark): Emitted separately outside documents
76
+ */
77
+ declare function lex(source: string): string[];
78
+ //#endregion
79
+ //#region src/parse/parser.d.ts
80
+ /**
81
+ * A YAML concrete syntax tree (CST) parser
82
+ *
83
+ * ```ts
84
+ * const src: string = ...
85
+ * for (const token of new Parser().parse(src)) {
86
+ * // token: Token
87
+ * }
88
+ * ```
89
+ *
90
+ * To use the parser with a user-provided lexer:
91
+ *
92
+ * ```ts
93
+ * function parse(source: string, lexTokens: string[]) {
94
+ * const parser = new Parser()
95
+ * for (const lexeme of lexTokens) parser.next(lexeme)
96
+ * return parser.end()
97
+ * }
98
+ *
99
+ * const src: string = ...
100
+ * for (const token of parse(src, lex(src))) {
101
+ * // token: Token
102
+ * }
103
+ * ```
104
+ */
105
+ declare class Parser {
106
+ private onNewLine?;
107
+ /** If true, space and sequence indicators count as indentation */
108
+ private atNewLine;
109
+ /** If true, next token is a scalar value */
110
+ private atScalar;
111
+ /** Current indentation level */
112
+ private indent;
113
+ /** Current offset since the start of parsing */
114
+ offset: number;
115
+ /** On the same line with a block map key */
116
+ private onKeyLine;
117
+ /** Top indicates the node that's currently being built */
118
+ stack: Token[];
119
+ /** The source of the current token, set in parse() */
120
+ private source;
121
+ /** The type of the current token, set in parse() */
122
+ private type;
123
+ tokens: Token[];
124
+ /**
125
+ * @param onNewLine - If defined, called separately with the start position of
126
+ * each new line (in `parse()`, including the start of input).
127
+ */
128
+ constructor(onNewLine?: (offset: number) => void);
129
+ /**
130
+ * Parse `source` as a YAML stream.
131
+ *
132
+ * Errors are not thrown, but included in the result as `{ type: 'error', message }` tokens.
133
+ *
134
+ * @returns Tokens representing each directive, document, and other structure.
135
+ */
136
+ parse(source: string): Token[];
137
+ /**
138
+ * Advance the parser by the `source` of one lexical token.
139
+ */
140
+ next(source: string): void;
141
+ /** Call at end of input to account for any remaining constructions */
142
+ end(): Token[];
143
+ private get sourceToken();
144
+ private step;
145
+ private peek;
146
+ private pop;
147
+ private stream;
148
+ private document;
149
+ private scalar;
150
+ private blockScalar;
151
+ private blockMap;
152
+ private blockSequence;
153
+ private flowCollection;
154
+ private flowScalar;
155
+ private startBlockValue;
156
+ private atIndentedComment;
157
+ private documentEnd;
158
+ private lineEnd;
159
+ }
160
+ //#endregion
161
+ //#region src/public-api.d.ts
162
+ interface EmptyStream extends Array<Document.Parsed>, ReturnType<Composer["streamInfo"]> {
163
+ empty: true;
164
+ }
165
+ /**
166
+ * Parse the input as a stream of YAML documents.
167
+ *
168
+ * Documents should be separated from each other by `...` or `---` marker lines.
169
+ *
170
+ * @returns If an empty `docs` array is returned, it will be of type
171
+ * EmptyStream and contain additional stream information. In
172
+ * TypeScript, you should use `'empty' in docs` as a type guard for it.
173
+ */
174
+ declare function parseAllDocuments<Value extends DocValue = DocValue, Strict extends boolean = true>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<Value, Strict>[] | EmptyStream;
175
+ /** Parse an input string into a single YAML.Document */
176
+ declare function parseDocument<Value extends DocValue = DocValue, Strict extends boolean = true>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<Value, Strict>;
177
+ /**
178
+ * Parse an input string into JavaScript.
179
+ *
180
+ * Only supports input consisting of a single YAML document; for multi-document
181
+ * support you should use `YAML.parseAllDocuments`. May throw on error, and may
182
+ * log warnings using `console.warn`.
183
+ *
184
+ * @param str - A string with YAML formatting.
185
+ * @param reviver - A reviver function, as in `JSON.parse()`
186
+ * @returns The value will match the type of the root value of the parsed YAML
187
+ * document, so Maps become objects, Sequences arrays, and scalars result in
188
+ * nulls, booleans, numbers and strings.
189
+ */
190
+ declare function parse(src: string, options?: ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions): any;
191
+ declare function parse(src: string, reviver: Reviver, options?: ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions): any;
192
+ /**
193
+ * Stringify a value as a YAML document.
194
+ *
195
+ * @param replacer - A replacer array or function, as in `JSON.stringify()`
196
+ * @returns Will always include `\n` as the last character, as is expected of YAML documents.
197
+ */
198
+ declare function stringify(value: any, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions): string;
199
+ declare function stringify(value: any, replacer?: Replacer | null, options?: string | number | (DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions)): string;
200
+ //#endregion
201
+ //#region src/schema/yaml-1.1/omap.d.ts
202
+ declare class YAMLOMap<K extends Primitive | Node = Primitive | Node, V extends Primitive | Node = Primitive | Node> extends YAMLSeq<Pair<K, V>> {
203
+ constructor(schema: Schema, elements?: Array<Pair<K, V>>);
204
+ /**
205
+ * Append new pairs to the omap, and return its new length.
206
+ */
207
+ push(...pairs: Pair<K, V>[]): number;
208
+ /**
209
+ * Set a pair in this omap.
210
+ *
211
+ * Throws if `idx` is not an integer.
212
+ */
213
+ set(idx: number, pair: Pair<K, V>): void;
214
+ /**
215
+ * The returned value actually has type `Map<unknown, unknown>`,
216
+ * but TypeScript won't allow widening the signature of a child method.
217
+ */
218
+ toJS(doc: Document<DocValue, boolean>, ctx?: ToJSContext): never[];
219
+ toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
220
+ }
221
+ //#endregion
222
+ //#region src/visit.d.ts
223
+ type visitorFn<T> = (key: number | "key" | "value" | null, node: T, path: readonly (Document | Node | Pair)[]) => void | symbol | number | Node | Pair;
224
+ type visitor = visitorFn<Node | Pair | null> | {
225
+ Alias?: visitorFn<Alias>;
226
+ Collection?: visitorFn<YAMLMap | YAMLSeq | YAMLSet>;
227
+ Map?: visitorFn<YAMLMap | YAMLSet>;
228
+ Node?: visitorFn<Alias | Scalar | YAMLMap | YAMLSeq | YAMLSet>;
229
+ Pair?: visitorFn<Pair>;
230
+ Scalar?: visitorFn<Scalar>;
231
+ Seq?: visitorFn<YAMLSeq>;
232
+ Value?: visitorFn<Scalar | YAMLMap | YAMLSeq | YAMLSet>;
233
+ };
234
+ type asyncVisitorFn<T> = (key: number | "key" | "value" | null, node: T, path: readonly (Document | Node | Pair)[]) => void | symbol | number | Node | Pair | Promise<void | symbol | number | Node | Pair>;
235
+ type asyncVisitor = asyncVisitorFn<Node | Pair | null> | {
236
+ Alias?: asyncVisitorFn<Alias>;
237
+ Collection?: asyncVisitorFn<YAMLMap | YAMLSeq | YAMLSet>;
238
+ Map?: asyncVisitorFn<YAMLMap | YAMLSet>;
239
+ Node?: asyncVisitorFn<Alias | Scalar | YAMLMap | YAMLSeq | YAMLSet>;
240
+ Pair?: asyncVisitorFn<Pair>;
241
+ Scalar?: asyncVisitorFn<Scalar>;
242
+ Seq?: asyncVisitorFn<YAMLSeq>;
243
+ Value?: asyncVisitorFn<Scalar | YAMLMap | YAMLSeq | YAMLSet>;
244
+ };
245
+ /**
246
+ * Apply a visitor to an AST node or document.
247
+ *
248
+ * Walks through the tree (depth-first) starting from `node`, calling a
249
+ * `visitor` function with three arguments:
250
+ * - `key`: For sequence values and map `Pair`, the node's index in the
251
+ * collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.
252
+ * `null` for the root node.
253
+ * - `node`: The current node.
254
+ * - `path`: The ancestry of the current node.
255
+ *
256
+ * The return value of the visitor may be used to control the traversal:
257
+ * - `undefined` (default): Do nothing and continue
258
+ * - `visit.SKIP`: Do not visit the children of this node, continue with next
259
+ * sibling
260
+ * - `visit.BREAK`: Terminate traversal completely
261
+ * - `visit.REMOVE`: Remove the current node, then continue with the next one
262
+ * - `Node`: Replace the current node, then continue by visiting it
263
+ * - `number`: While iterating the items of a sequence or map, set the index
264
+ * of the next step. This is useful especially if the index of the current
265
+ * node has changed.
266
+ *
267
+ * If `visitor` is a single function, it will be called with all values
268
+ * encountered in the tree, including e.g. `null` values. Alternatively,
269
+ * separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,
270
+ * `Alias` and `Scalar` node. To define the same visitor function for more than
271
+ * one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)
272
+ * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
273
+ * specific defined one will be used for each node.
274
+ */
275
+ declare const visit: {
276
+ (node: Node | Document | null, visitor: visitor): void; /** Terminate visit traversal completely */
277
+ BREAK: symbol; /** Do not visit the children of the current node */
278
+ SKIP: symbol; /** Remove the current node */
279
+ REMOVE: symbol;
280
+ };
281
+ /**
282
+ * Apply an async visitor to an AST node or document.
283
+ *
284
+ * Walks through the tree (depth-first) starting from `node`, calling a
285
+ * `visitor` function with three arguments:
286
+ * - `key`: For sequence values and map `Pair`, the node's index in the
287
+ * collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.
288
+ * `null` for the root node.
289
+ * - `node`: The current node.
290
+ * - `path`: The ancestry of the current node.
291
+ *
292
+ * The return value of the visitor may be used to control the traversal:
293
+ * - `Promise`: Must resolve to one of the following values
294
+ * - `undefined` (default): Do nothing and continue
295
+ * - `visitAsync.SKIP`: Do not visit the children of this node,
296
+ * continue with next sibling
297
+ * - `visitAsync.BREAK`: Terminate traversal completely
298
+ * - `visitAsync.REMOVE`: Remove the current node,
299
+ * then continue with the next one
300
+ * - `Node`: Replace the current node, then continue by visiting it
301
+ * - `number`: While iterating the items of a sequence or map, set the index
302
+ * of the next step. This is useful especially if the index of the current
303
+ * node has changed.
304
+ *
305
+ * If `visitor` is a single function, it will be called with all values
306
+ * encountered in the tree, including e.g. `null` values. Alternatively,
307
+ * separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,
308
+ * `Alias` and `Scalar` node. To define the same visitor function for more than
309
+ * one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)
310
+ * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
311
+ * specific defined one will be used for each node.
312
+ */
313
+ declare const visitAsync: {
314
+ (node: Node | Document | null, visitor: asyncVisitor): Promise<void>; /** Terminate visit traversal completely */
315
+ BREAK: symbol; /** Do not visit the children of the current node */
316
+ SKIP: symbol; /** Remove the current node */
317
+ REMOVE: symbol;
318
+ };
319
+ //#endregion
320
+ export { Alias, cst_d_exports as CST, type CollectionTag, Composer, type CreateNodeOptions, type DocValue, Document, type DocumentOptions, type EmptyStream, type ErrorCode, type KeyArg, LineCounter, type Node, type NodeBase, Pair, type ParseOptions, Parser, type Range, Scalar, type ScalarTag, Schema, type SchemaOptions, type TagId, type Tags, type ToJSOptions, type ToStringOptions, YAMLError, YAMLMap, type YAMLOMap, YAMLParseError, YAMLSeq, YAMLSet, YAMLWarning, type asyncVisitor, type asyncVisitorFn, isCollection, isNode, lex, parse, parseAllDocuments, parseDocument, stringify, visit, visitAsync, type visitor, type visitorFn };
package/dist/index.js CHANGED
@@ -1,50 +1,4 @@
1
- 'use strict';
2
-
3
- var composer = require('./compose/composer.js');
4
- var Document = require('./doc/Document.js');
5
- var Schema = require('./schema/Schema.js');
6
- var errors = require('./errors.js');
7
- var Alias = require('./nodes/Alias.js');
8
- var identity = require('./nodes/identity.js');
9
- var Pair = require('./nodes/Pair.js');
10
- var Scalar = require('./nodes/Scalar.js');
11
- var YAMLMap = require('./nodes/YAMLMap.js');
12
- var YAMLSeq = require('./nodes/YAMLSeq.js');
13
- var cst = require('./parse/cst.js');
14
- var lexer = require('./parse/lexer.js');
15
- var lineCounter = require('./parse/line-counter.js');
16
- var parser = require('./parse/parser.js');
17
- var publicApi = require('./public-api.js');
18
- var visit = require('./visit.js');
19
-
20
-
21
-
22
- exports.Composer = composer.Composer;
23
- exports.Document = Document.Document;
24
- exports.Schema = Schema.Schema;
25
- exports.YAMLError = errors.YAMLError;
26
- exports.YAMLParseError = errors.YAMLParseError;
27
- exports.YAMLWarning = errors.YAMLWarning;
28
- exports.Alias = Alias.Alias;
29
- exports.isAlias = identity.isAlias;
30
- exports.isCollection = identity.isCollection;
31
- exports.isDocument = identity.isDocument;
32
- exports.isMap = identity.isMap;
33
- exports.isNode = identity.isNode;
34
- exports.isPair = identity.isPair;
35
- exports.isScalar = identity.isScalar;
36
- exports.isSeq = identity.isSeq;
37
- exports.Pair = Pair.Pair;
38
- exports.Scalar = Scalar.Scalar;
39
- exports.YAMLMap = YAMLMap.YAMLMap;
40
- exports.YAMLSeq = YAMLSeq.YAMLSeq;
41
- exports.CST = cst;
42
- exports.Lexer = lexer.Lexer;
43
- exports.LineCounter = lineCounter.LineCounter;
44
- exports.Parser = parser.Parser;
45
- exports.parse = publicApi.parse;
46
- exports.parseAllDocuments = publicApi.parseAllDocuments;
47
- exports.parseDocument = publicApi.parseDocument;
48
- exports.stringify = publicApi.stringify;
49
- exports.visit = visit.visit;
50
- exports.visitAsync = visit.visitAsync;
1
+ import { S as Scalar, a as Schema, d as Pair, f as isCollection, g as YAMLMap, h as YAMLSeq, i as Document, m as YAMLSet, n as visit, p as isNode, r as visitAsync, u as Alias } from "./directives-CiM56lHW.js";
2
+ import { a as cst_exports, c as YAMLParseError, i as lex, l as YAMLWarning, n as Composer, r as Parser, s as YAMLError, t as LineCounter } from "./line-counter-bmCJ4fGy.js";
3
+ import { i as stringify, n as parseAllDocuments, r as parseDocument, t as parse } from "./public-api-BTMehGT6.js";
4
+ export { Alias, cst_exports as CST, Composer, Document, LineCounter, Pair, Parser, Scalar, Schema, YAMLError, YAMLMap, YAMLParseError, YAMLSeq, YAMLSet, YAMLWarning, isCollection, isNode, lex, parse, parseAllDocuments, parseDocument, stringify, visit, visitAsync };