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
@@ -0,0 +1,77 @@
1
+ import { i as Document, y as warn } from "./directives-CiM56lHW.js";
2
+ import { c as YAMLParseError, n as Composer, r as Parser, t as LineCounter, u as prettifyError } from "./line-counter-bmCJ4fGy.js";
3
+ //#region src/public-api.ts
4
+ function parseOptions(options) {
5
+ const prettyErrors = options.prettyErrors !== false;
6
+ return {
7
+ lineCounter: options.lineCounter || prettyErrors && new LineCounter() || null,
8
+ prettyErrors
9
+ };
10
+ }
11
+ /**
12
+ * Parse the input as a stream of YAML documents.
13
+ *
14
+ * Documents should be separated from each other by `...` or `---` marker lines.
15
+ *
16
+ * @returns If an empty `docs` array is returned, it will be of type
17
+ * EmptyStream and contain additional stream information. In
18
+ * TypeScript, you should use `'empty' in docs` as a type guard for it.
19
+ */
20
+ function parseAllDocuments(source, options = {}) {
21
+ const { lineCounter, prettyErrors } = parseOptions(options);
22
+ const parser = new Parser(lineCounter?.addNewLine);
23
+ const composer = new Composer(options);
24
+ const docs = Array.from(composer.compose(parser.parse(source)));
25
+ if (prettyErrors && lineCounter) for (const doc of docs) {
26
+ doc.errors.forEach(prettifyError(source, lineCounter));
27
+ doc.warnings.forEach(prettifyError(source, lineCounter));
28
+ }
29
+ if (docs.length > 0) return docs;
30
+ return Object.assign([], { empty: true }, composer.streamInfo());
31
+ }
32
+ /** Parse an input string into a single YAML.Document */
33
+ function parseDocument(source, options = {}) {
34
+ const { lineCounter, prettyErrors } = parseOptions(options);
35
+ const parser = new Parser(lineCounter?.addNewLine);
36
+ const composer = new Composer(options);
37
+ let doc = null;
38
+ for (const _doc of composer.compose(parser.parse(source), true, source.length)) if (!doc) doc = _doc;
39
+ else if (doc.options.logLevel !== "silent") {
40
+ doc.errors.push(new YAMLParseError(_doc.range.slice(0, 2), "MULTIPLE_DOCS", "Source contains multiple documents; please use YAML.parseAllDocuments()"));
41
+ break;
42
+ }
43
+ if (prettyErrors && lineCounter) {
44
+ doc.errors.forEach(prettifyError(source, lineCounter));
45
+ doc.warnings.forEach(prettifyError(source, lineCounter));
46
+ }
47
+ return doc;
48
+ }
49
+ function parse(src, reviver, options) {
50
+ let _reviver = void 0;
51
+ if (typeof reviver === "function") _reviver = reviver;
52
+ else if (options === void 0 && reviver && typeof reviver === "object") options = reviver;
53
+ const doc = parseDocument(src, options);
54
+ if (!doc) return null;
55
+ doc.warnings.forEach((warning) => warn(doc.options.logLevel, warning));
56
+ if (doc.errors.length > 0) if (doc.options.logLevel !== "silent") throw doc.errors[0];
57
+ else doc.errors = [];
58
+ return doc.toJS(Object.assign({ reviver: _reviver }, options));
59
+ }
60
+ function stringify(value, replacer, options) {
61
+ let _replacer = null;
62
+ if (typeof replacer === "function" || Array.isArray(replacer)) _replacer = replacer;
63
+ else if (options === void 0 && replacer) options = replacer;
64
+ if (typeof options === "string") options = options.length;
65
+ if (typeof options === "number") {
66
+ const indent = Math.round(options);
67
+ options = indent < 1 ? void 0 : indent > 8 ? { indent: 8 } : { indent };
68
+ }
69
+ if (value === void 0) {
70
+ const { keepUndefined } = options ?? replacer ?? {};
71
+ if (!keepUndefined) return void 0;
72
+ }
73
+ if (value instanceof Document && !_replacer) return value.toString(options);
74
+ return new Document(value, _replacer, options).toString(options);
75
+ }
76
+ //#endregion
77
+ export { stringify as i, parseAllDocuments as n, parseDocument as r, parse as t };
@@ -1,4 +1,7 @@
1
- export declare function testEvents(src: string): {
2
- events: string[];
3
- error: unknown;
1
+ //#region src/test-events.d.ts
2
+ declare function testEvents(src: string): {
3
+ events: string[];
4
+ error: unknown;
4
5
  };
6
+ //#endregion
7
+ export { testEvents };
@@ -1,134 +1,113 @@
1
- 'use strict';
2
-
3
- var identity = require('./nodes/identity.js');
4
- var publicApi = require('./public-api.js');
5
- var visit = require('./visit.js');
6
-
1
+ import { S as Scalar, d as Pair, g as YAMLMap, h as YAMLSeq, m as YAMLSet, n as visit, p as isNode, u as Alias } from "./directives-CiM56lHW.js";
2
+ import { n as parseAllDocuments } from "./public-api-BTMehGT6.js";
3
+ //#region src/test-events.ts
7
4
  const scalarChar = {
8
- BLOCK_FOLDED: '>',
9
- BLOCK_LITERAL: '|',
10
- PLAIN: ':',
11
- QUOTE_DOUBLE: '"',
12
- QUOTE_SINGLE: "'"
5
+ BLOCK_FOLDED: ">",
6
+ BLOCK_LITERAL: "|",
7
+ PLAIN: ":",
8
+ QUOTE_DOUBLE: "\"",
9
+ QUOTE_SINGLE: "'"
13
10
  };
14
11
  function anchorExists(doc, anchor) {
15
- let found = false;
16
- visit.visit(doc, {
17
- Value(_key, node) {
18
- if (node.anchor === anchor) {
19
- found = true;
20
- return visit.visit.BREAK;
21
- }
22
- }
23
- });
24
- return found;
12
+ let found = false;
13
+ visit(doc, { Value(_key, node) {
14
+ if (node.anchor === anchor) {
15
+ found = true;
16
+ return visit.BREAK;
17
+ }
18
+ } });
19
+ return found;
25
20
  }
26
- // test harness for yaml-test-suite event tests
27
21
  function testEvents(src) {
28
- const docs = publicApi.parseAllDocuments(src);
29
- const errDoc = docs.find(doc => doc.errors.length > 0);
30
- const error = errDoc ? errDoc.errors[0].message : null;
31
- const events = ['+STR'];
32
- try {
33
- for (let i = 0; i < docs.length; ++i) {
34
- const doc = docs[i];
35
- let root = doc.contents;
36
- if (Array.isArray(root))
37
- root = root[0];
38
- const [rootStart] = doc.range || [0];
39
- const error = doc.errors[0];
40
- if (error && (!error.pos || error.pos[0] < rootStart))
41
- throw new Error();
42
- let docStart = '+DOC';
43
- if (doc.directives.docStart)
44
- docStart += ' ---';
45
- else if (doc.contents &&
46
- doc.contents.range[2] === doc.contents.range[0] &&
47
- !doc.contents.anchor &&
48
- !doc.contents.tag)
49
- continue;
50
- events.push(docStart);
51
- addEvents(events, doc, error?.pos[0] ?? -1, root);
52
- let docEnd = '-DOC';
53
- if (doc.directives.docEnd)
54
- docEnd += ' ...';
55
- events.push(docEnd);
56
- }
57
- }
58
- catch (e) {
59
- return { events, error: error ?? e };
60
- }
61
- events.push('-STR');
62
- return { events, error };
22
+ const docs = parseAllDocuments(src);
23
+ const errDoc = docs.find((doc) => doc.errors.length > 0);
24
+ const error = errDoc ? errDoc.errors[0].message : null;
25
+ const events = ["+STR"];
26
+ try {
27
+ for (let i = 0; i < docs.length; ++i) {
28
+ const doc = docs[i];
29
+ const root = doc.value;
30
+ const [rootStart] = doc.range || [0];
31
+ const error = doc.errors[0];
32
+ if (error && (!error.pos || error.pos[0] < rootStart)) throw new Error();
33
+ let docStart = "+DOC";
34
+ if (doc.directives.docStart) docStart += " ---";
35
+ else if (root.range[2] === root.range[0] && !root.anchor && !root.tag) continue;
36
+ events.push(docStart);
37
+ addEvents(events, doc, error?.pos[0] ?? -1, root);
38
+ let docEnd = "-DOC";
39
+ if (doc.directives.docEnd) docEnd += " ...";
40
+ events.push(docEnd);
41
+ }
42
+ } catch (e) {
43
+ return {
44
+ events,
45
+ error: error ?? e
46
+ };
47
+ }
48
+ events.push("-STR");
49
+ return {
50
+ events,
51
+ error
52
+ };
63
53
  }
64
54
  function addEvents(events, doc, errPos, node) {
65
- if (!node) {
66
- events.push('=VAL :');
67
- return;
68
- }
69
- if (errPos !== -1 && identity.isNode(node) && node.range[0] >= errPos)
70
- throw new Error();
71
- let props = '';
72
- let anchor = identity.isScalar(node) || identity.isCollection(node) ? node.anchor : undefined;
73
- if (anchor) {
74
- if (/\d$/.test(anchor)) {
75
- const alt = anchor.replace(/\d$/, '');
76
- if (anchorExists(doc, alt))
77
- anchor = alt;
78
- }
79
- props = ` &${anchor}`;
80
- }
81
- if (identity.isNode(node) && node.tag)
82
- props += ` <${node.tag}>`;
83
- if (identity.isMap(node)) {
84
- const ev = node.flow ? '+MAP {}' : '+MAP';
85
- events.push(`${ev}${props}`);
86
- node.items.forEach(({ key, value }) => {
87
- addEvents(events, doc, errPos, key);
88
- addEvents(events, doc, errPos, value);
89
- });
90
- events.push('-MAP');
91
- }
92
- else if (identity.isSeq(node)) {
93
- const ev = node.flow ? '+SEQ []' : '+SEQ';
94
- events.push(`${ev}${props}`);
95
- node.items.forEach(item => {
96
- addEvents(events, doc, errPos, item);
97
- });
98
- events.push('-SEQ');
99
- }
100
- else if (identity.isPair(node)) {
101
- events.push(`+MAP${props}`);
102
- addEvents(events, doc, errPos, node.key);
103
- addEvents(events, doc, errPos, node.value);
104
- events.push('-MAP');
105
- }
106
- else if (identity.isAlias(node)) {
107
- let alias = node.source;
108
- if (alias && /\d$/.test(alias)) {
109
- const alt = alias.replace(/\d$/, '');
110
- if (anchorExists(doc, alt))
111
- alias = alt;
112
- }
113
- events.push(`=ALI${props} *${alias}`);
114
- }
115
- else {
116
- const scalar = scalarChar[String(node.type)];
117
- if (!scalar)
118
- throw new Error(`Unexpected node type ${node.type}`);
119
- const value = node.source
120
- .replace(/\\/g, '\\\\')
121
- .replace(/\0/g, '\\0')
122
- .replace(/\x07/g, '\\a')
123
- .replace(/\x08/g, '\\b')
124
- .replace(/\t/g, '\\t')
125
- .replace(/\n/g, '\\n')
126
- .replace(/\v/g, '\\v')
127
- .replace(/\f/g, '\\f')
128
- .replace(/\r/g, '\\r')
129
- .replace(/\x1b/g, '\\e');
130
- events.push(`=VAL${props} ${scalar}${value}`);
131
- }
55
+ if (!node) {
56
+ events.push("=VAL :");
57
+ return;
58
+ }
59
+ if (errPos !== -1 && isNode(node) && node.range[0] >= errPos) throw new Error();
60
+ let props = "";
61
+ let anchor = isNode(node) ? node.anchor : void 0;
62
+ if (anchor) {
63
+ if (/\d$/.test(anchor)) {
64
+ const alt = anchor.replace(/\d$/, "");
65
+ if (anchorExists(doc, alt)) anchor = alt;
66
+ }
67
+ props = ` &${anchor}`;
68
+ }
69
+ if (isNode(node) && node.tag) props += ` <${node.tag}>`;
70
+ if (node instanceof YAMLMap) {
71
+ const ev = node.flow ? "+MAP {}" : "+MAP";
72
+ events.push(`${ev}${props}`);
73
+ for (const { key, value } of node.values.values()) {
74
+ addEvents(events, doc, errPos, key);
75
+ addEvents(events, doc, errPos, value);
76
+ }
77
+ events.push("-MAP");
78
+ } else if (node instanceof YAMLSeq) {
79
+ const ev = node.flow ? "+SEQ []" : "+SEQ";
80
+ events.push(`${ev}${props}`);
81
+ node.forEach((item) => {
82
+ addEvents(events, doc, errPos, item);
83
+ });
84
+ events.push("-SEQ");
85
+ } else if (node instanceof YAMLSet) {
86
+ const ev = node.flow ? "+MAP {}" : "+MAP";
87
+ events.push(`${ev}${props}`);
88
+ for (const value of node.values.values()) {
89
+ addEvents(events, doc, errPos, value);
90
+ events.push("=VAL :");
91
+ }
92
+ events.push("-MAP");
93
+ } else if (node instanceof Pair) {
94
+ events.push(`+MAP${props}`);
95
+ addEvents(events, doc, errPos, node.key);
96
+ addEvents(events, doc, errPos, node.value);
97
+ events.push("-MAP");
98
+ } else if (node instanceof Alias) {
99
+ let alias = node.source;
100
+ if (alias && /\d$/.test(alias)) {
101
+ const alt = alias.replace(/\d$/, "");
102
+ if (anchorExists(doc, alt)) alias = alt;
103
+ }
104
+ events.push(`=ALI${props} *${alias}`);
105
+ } else if (node instanceof Scalar) {
106
+ const scalar = scalarChar[String(node.type)];
107
+ if (!scalar) throw new Error(`Unexpected node type ${node.type}`);
108
+ const value = node.source.replace(/\\/g, "\\\\").replace(/\0/g, "\\0").replace(/\x07/g, "\\a").replace(/\x08/g, "\\b").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\v/g, "\\v").replace(/\f/g, "\\f").replace(/\r/g, "\\r").replace(/\x1b/g, "\\e");
109
+ events.push(`=VAL${props} ${scalar}${value}`);
110
+ } else throw new Error(`Unexpected node ${node}`);
132
111
  }
133
-
134
- exports.testEvents = testEvents;
112
+ //#endregion
113
+ export { testEvents };
package/dist/util.d.ts CHANGED
@@ -1,16 +1,2 @@
1
- export { createNode } from './doc/createNode';
2
- export type { CreateNodeContext } from './doc/createNode';
3
- export { debug, warn } from './log';
4
- export type { LogLevelId } from './log';
5
- export { createPair } from './nodes/Pair';
6
- export { toJS } from './nodes/toJS';
7
- export type { ToJSContext } from './nodes/toJS';
8
- export { findPair } from './nodes/YAMLMap';
9
- export { map as mapTag } from './schema/common/map';
10
- export { seq as seqTag } from './schema/common/seq';
11
- export { string as stringTag } from './schema/common/string';
12
- export { foldFlowLines } from './stringify/foldFlowLines';
13
- export type { FoldOptions } from './stringify/foldFlowLines';
14
- export type { StringifyContext } from './stringify/stringify';
15
- export { stringifyNumber } from './stringify/stringifyNumber';
16
- export { stringifyString } from './stringify/stringifyString';
1
+ import { B as debug, I as NodeCreator, L as ToJSContext, R as StringifyContext, V as warn, _ as string, b as map, g as foldFlowLines, h as FoldOptions, m as stringifyNumber, p as stringifyString, v as seq, z as LogLevelId } from "./directives-DlYEVlkC.js";
2
+ export { FoldOptions, LogLevelId, NodeCreator, StringifyContext, ToJSContext, debug, foldFlowLines, map as mapTag, seq as seqTag, string as stringTag, stringifyNumber, stringifyString, warn };
package/dist/util.js CHANGED
@@ -1,28 +1,2 @@
1
- 'use strict';
2
-
3
- var createNode = require('./doc/createNode.js');
4
- var log = require('./log.js');
5
- var Pair = require('./nodes/Pair.js');
6
- var toJS = require('./nodes/toJS.js');
7
- var YAMLMap = require('./nodes/YAMLMap.js');
8
- var map = require('./schema/common/map.js');
9
- var seq = require('./schema/common/seq.js');
10
- var string = require('./schema/common/string.js');
11
- var foldFlowLines = require('./stringify/foldFlowLines.js');
12
- var stringifyNumber = require('./stringify/stringifyNumber.js');
13
- var stringifyString = require('./stringify/stringifyString.js');
14
-
15
-
16
-
17
- exports.createNode = createNode.createNode;
18
- exports.debug = log.debug;
19
- exports.warn = log.warn;
20
- exports.createPair = Pair.createPair;
21
- exports.toJS = toJS.toJS;
22
- exports.findPair = YAMLMap.findPair;
23
- exports.mapTag = map.map;
24
- exports.seqTag = seq.seq;
25
- exports.stringTag = string.string;
26
- exports.foldFlowLines = foldFlowLines.foldFlowLines;
27
- exports.stringifyNumber = stringifyNumber.stringifyNumber;
28
- exports.stringifyString = stringifyString.stringifyString;
1
+ import { _ as ToJSContext, b as stringifyString, c as seq, l as map, o as stringifyNumber, s as string, v as debug, x as foldFlowLines, y as warn } from "./directives-CiM56lHW.js";
2
+ export { ToJSContext, debug, foldFlowLines, map as mapTag, seq as seqTag, string as stringTag, stringifyNumber, stringifyString, warn };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml",
3
- "version": "2.8.4",
3
+ "version": "3.0.0-1",
4
4
  "license": "ISC",
5
5
  "author": "Eemeli Aro <eemeli@gmail.com>",
6
6
  "funding": "https://github.com/sponsors/eemeli",
@@ -13,55 +13,41 @@
13
13
  ],
14
14
  "homepage": "https://eemeli.org/yaml/",
15
15
  "files": [
16
- "browser/",
17
- "dist/",
18
- "util.js"
16
+ "dist/"
19
17
  ],
20
- "type": "commonjs",
18
+ "type": "module",
21
19
  "main": "./dist/index.js",
22
- "bin": "./bin.mjs",
23
- "browser": {
24
- "./dist/index.js": "./browser/index.js",
25
- "./dist/util.js": "./browser/dist/util.js",
26
- "./util.js": "./browser/dist/util.js"
27
- },
20
+ "bin": "./bin.js",
28
21
  "exports": {
29
22
  ".": {
30
23
  "types": "./dist/index.d.ts",
31
- "node": "./dist/index.js",
32
- "default": "./browser/index.js"
24
+ "default": "./dist/index.js"
33
25
  },
34
26
  "./package.json": "./package.json",
35
27
  "./util": {
36
28
  "types": "./dist/util.d.ts",
37
- "node": "./dist/util.js",
38
- "default": "./browser/dist/util.js"
29
+ "default": "./dist/util.js"
39
30
  }
40
31
  },
41
32
  "scripts": {
42
- "build": "npm run build:node && npm run build:browser",
43
- "build:browser": "rollup -c config/rollup.browser-config.mjs",
44
- "build:node": "rollup -c config/rollup.node-config.mjs",
33
+ "build": "rolldown -c",
45
34
  "clean": "git clean -fdxe node_modules",
46
- "lint": "eslint config/ src/",
35
+ "lint": "eslint src/",
47
36
  "prettier": "prettier --write .",
48
- "prestart": "rollup --sourcemap -c config/rollup.node-config.mjs",
49
- "start": "node --enable-source-maps -i -e 'YAML=require(\"./dist/index.js\");const{parse,parseDocument,parseAllDocuments}=YAML'",
50
- "test": "jest --config config/jest.config.js",
37
+ "start": "node -i -e 'YAML=require(\"./src/index.ts\");const{parse,parseDocument,parseAllDocuments,stringify}=YAML'",
38
+ "test": "vitest run",
51
39
  "test:all": "npm test && npm run test:types && npm run test:dist && npm run test:dist:types",
52
- "test:browsers": "cd playground && npm test",
53
- "test:dist": "npm run build:node && jest --config config/jest.config.js",
54
- "test:dist:types": "tsc --allowJs --moduleResolution node --noEmit --target es5 dist/index.js",
40
+ "test:dist": "npm run build && vitest run",
41
+ "test:dist:types": "tsc --allowJs --moduleResolution node --noEmit --target es5 dist/cli.js dist/index.js dist/test-events.js dist/util.js",
55
42
  "test:types": "tsc --noEmit && tsc --noEmit -p tests/tsconfig.json",
56
43
  "docs:install": "cd docs-slate && bundle install",
57
- "predocs:deploy": "node docs/prepare-docs.mjs",
44
+ "predocs:deploy": "node docs/prepare-docs.js",
58
45
  "docs:deploy": "cd docs-slate && ./deploy.sh",
59
- "predocs": "node docs/prepare-docs.mjs",
46
+ "predocs": "node docs/prepare-docs.js",
60
47
  "docs": "cd docs-slate && bundle exec middleman server",
61
48
  "preversion": "npm test && npm run build",
62
49
  "prepublishOnly": "npm run clean && npm test && npm run build"
63
50
  },
64
- "browserslist": "defaults, not ie 11",
65
51
  "prettier": {
66
52
  "arrowParens": "avoid",
67
53
  "semi": false,
@@ -69,29 +55,19 @@
69
55
  "trailingComma": "none"
70
56
  },
71
57
  "devDependencies": {
72
- "@babel/core": "^7.12.10",
73
- "@babel/plugin-transform-typescript": "^7.12.17",
74
- "@babel/preset-env": "^7.12.11",
75
58
  "@eslint/js": "^9.9.1",
76
- "@rollup/plugin-babel": "^6.0.3",
77
- "@rollup/plugin-replace": "^6.0.3",
78
- "@rollup/plugin-typescript": "^12.1.1",
79
- "@types/jest": "^29.2.4",
80
59
  "@types/node": "^20.11.20",
81
- "babel-jest": "^29.0.1",
82
60
  "eslint": "^9.9.1",
83
61
  "eslint-config-prettier": "^10.1.8",
84
62
  "fast-check": "^2.12.0",
85
- "jest": "^29.0.1",
86
- "jest-resolve": "^29.7.0",
87
- "jest-ts-webcompat-resolver": "^1.0.0",
88
63
  "prettier": "^3.0.2",
89
- "rollup": "^4.12.0",
90
- "tslib": "^2.8.1",
91
- "typescript": "^5.7.2",
92
- "typescript-eslint": "^8.4.0"
64
+ "rolldown": "^1.0.0-beta.54",
65
+ "rolldown-plugin-dts": "^0.22.1",
66
+ "typescript": "^5.9.3",
67
+ "typescript-eslint": "^8.4.0",
68
+ "vitest": "^4.0.15"
93
69
  },
94
70
  "engines": {
95
- "node": ">= 14.6"
71
+ "node": "^20.19 || ^22.12 || >=24"
96
72
  }
97
73
  }
@@ -1,88 +0,0 @@
1
- import { isNode } from '../nodes/identity.js';
2
- import { Scalar } from '../nodes/Scalar.js';
3
- import { YAMLMap } from '../nodes/YAMLMap.js';
4
- import { YAMLSeq } from '../nodes/YAMLSeq.js';
5
- import { resolveBlockMap } from './resolve-block-map.js';
6
- import { resolveBlockSeq } from './resolve-block-seq.js';
7
- import { resolveFlowCollection } from './resolve-flow-collection.js';
8
-
9
- function resolveCollection(CN, ctx, token, onError, tagName, tag) {
10
- const coll = token.type === 'block-map'
11
- ? resolveBlockMap(CN, ctx, token, onError, tag)
12
- : token.type === 'block-seq'
13
- ? resolveBlockSeq(CN, ctx, token, onError, tag)
14
- : resolveFlowCollection(CN, ctx, token, onError, tag);
15
- const Coll = coll.constructor;
16
- // If we got a tagName matching the class, or the tag name is '!',
17
- // then use the tagName from the node class used to create it.
18
- if (tagName === '!' || tagName === Coll.tagName) {
19
- coll.tag = Coll.tagName;
20
- return coll;
21
- }
22
- if (tagName)
23
- coll.tag = tagName;
24
- return coll;
25
- }
26
- function composeCollection(CN, ctx, token, props, onError) {
27
- const tagToken = props.tag;
28
- const tagName = !tagToken
29
- ? null
30
- : ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg));
31
- if (token.type === 'block-seq') {
32
- const { anchor, newlineAfterProp: nl } = props;
33
- const lastProp = anchor && tagToken
34
- ? anchor.offset > tagToken.offset
35
- ? anchor
36
- : tagToken
37
- : (anchor ?? tagToken);
38
- if (lastProp && (!nl || nl.offset < lastProp.offset)) {
39
- const message = 'Missing newline after block sequence props';
40
- onError(lastProp, 'MISSING_CHAR', message);
41
- }
42
- }
43
- const expType = token.type === 'block-map'
44
- ? 'map'
45
- : token.type === 'block-seq'
46
- ? 'seq'
47
- : token.start.source === '{'
48
- ? 'map'
49
- : 'seq';
50
- // shortcut: check if it's a generic YAMLMap or YAMLSeq
51
- // before jumping into the custom tag logic.
52
- if (!tagToken ||
53
- !tagName ||
54
- tagName === '!' ||
55
- (tagName === YAMLMap.tagName && expType === 'map') ||
56
- (tagName === YAMLSeq.tagName && expType === 'seq')) {
57
- return resolveCollection(CN, ctx, token, onError, tagName);
58
- }
59
- let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType);
60
- if (!tag) {
61
- const kt = ctx.schema.knownTags[tagName];
62
- if (kt?.collection === expType) {
63
- ctx.schema.tags.push(Object.assign({}, kt, { default: false }));
64
- tag = kt;
65
- }
66
- else {
67
- if (kt) {
68
- onError(tagToken, 'BAD_COLLECTION_TYPE', `${kt.tag} used for ${expType} collection, but expects ${kt.collection ?? 'scalar'}`, true);
69
- }
70
- else {
71
- onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, true);
72
- }
73
- return resolveCollection(CN, ctx, token, onError, tagName);
74
- }
75
- }
76
- const coll = resolveCollection(CN, ctx, token, onError, tagName, tag);
77
- const res = tag.resolve?.(coll, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg), ctx.options) ?? coll;
78
- const node = isNode(res)
79
- ? res
80
- : new Scalar(res);
81
- node.range = coll.range;
82
- node.tag = tagName;
83
- if (tag?.format)
84
- node.format = tag.format;
85
- return node;
86
- }
87
-
88
- export { composeCollection };
@@ -1,43 +0,0 @@
1
- import { Document } from '../doc/Document.js';
2
- import { composeNode, composeEmptyNode } from './compose-node.js';
3
- import { resolveEnd } from './resolve-end.js';
4
- import { resolveProps } from './resolve-props.js';
5
-
6
- function composeDoc(options, directives, { offset, start, value, end }, onError) {
7
- const opts = Object.assign({ _directives: directives }, options);
8
- const doc = new Document(undefined, opts);
9
- const ctx = {
10
- atKey: false,
11
- atRoot: true,
12
- directives: doc.directives,
13
- options: doc.options,
14
- schema: doc.schema
15
- };
16
- const props = resolveProps(start, {
17
- indicator: 'doc-start',
18
- next: value ?? end?.[0],
19
- offset,
20
- onError,
21
- parentIndent: 0,
22
- startOnNewline: true
23
- });
24
- if (props.found) {
25
- doc.directives.docStart = true;
26
- if (value &&
27
- (value.type === 'block-map' || value.type === 'block-seq') &&
28
- !props.hasNewline)
29
- onError(props.end, 'MISSING_CHAR', 'Block collection cannot start on same line with directives-end marker');
30
- }
31
- // @ts-expect-error If Contents is set, let's trust the user
32
- doc.contents = value
33
- ? composeNode(ctx, value, props, onError)
34
- : composeEmptyNode(ctx, props.end, start, null, props, onError);
35
- const contentEnd = doc.contents.range[2];
36
- const re = resolveEnd(end, contentEnd, false, onError);
37
- if (re.comment)
38
- doc.comment = re.comment;
39
- doc.range = [offset, contentEnd, re.offset];
40
- return doc;
41
- }
42
-
43
- export { composeDoc };