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
@@ -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,108 @@
1
- 'use strict';
2
-
3
- var identity = require('./nodes/identity.js');
4
- var publicApi = require('./public-api.js');
5
- var visit = require('./visit.js');
1
+ import { _ as Collection, b as Scalar, f as Alias, g as YAMLSeq, n as visit, p as Pair, u as YAMLMap, x as NodeBase } from "./directives-CG6n4xSM.js";
2
+ import "./line-counter-TFl552k_.js";
3
+ import { n as parseAllDocuments } from "./public-api-BE74JyVm.js";
6
4
 
5
+ //#region src/test-events.ts
7
6
  const scalarChar = {
8
- BLOCK_FOLDED: '>',
9
- BLOCK_LITERAL: '|',
10
- PLAIN: ':',
11
- QUOTE_DOUBLE: '"',
12
- QUOTE_SINGLE: "'"
7
+ BLOCK_FOLDED: ">",
8
+ BLOCK_LITERAL: "|",
9
+ PLAIN: ":",
10
+ QUOTE_DOUBLE: "\"",
11
+ QUOTE_SINGLE: "'"
13
12
  };
14
13
  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;
14
+ let found = false;
15
+ visit(doc, { Value(_key, node) {
16
+ if (node.anchor === anchor) {
17
+ found = true;
18
+ return visit.BREAK;
19
+ }
20
+ } });
21
+ return found;
25
22
  }
26
- // test harness for yaml-test-suite event tests
27
23
  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 };
24
+ const docs = parseAllDocuments(src);
25
+ const errDoc = docs.find((doc) => doc.errors.length > 0);
26
+ const error = errDoc ? errDoc.errors[0].message : null;
27
+ const events = ["+STR"];
28
+ try {
29
+ for (let i = 0; i < docs.length; ++i) {
30
+ const doc = docs[i];
31
+ const root = doc.value;
32
+ const [rootStart] = doc.range || [0];
33
+ const error = doc.errors[0];
34
+ if (error && (!error.pos || error.pos[0] < rootStart)) throw new Error();
35
+ let docStart = "+DOC";
36
+ if (doc.directives.docStart) docStart += " ---";
37
+ else if (root.range[2] === root.range[0] && !root.anchor && !root.tag) continue;
38
+ events.push(docStart);
39
+ addEvents(events, doc, error?.pos[0] ?? -1, root);
40
+ let docEnd = "-DOC";
41
+ if (doc.directives.docEnd) docEnd += " ...";
42
+ events.push(docEnd);
43
+ }
44
+ } catch (e) {
45
+ return {
46
+ events,
47
+ error: error ?? e
48
+ };
49
+ }
50
+ events.push("-STR");
51
+ return {
52
+ events,
53
+ error
54
+ };
63
55
  }
64
56
  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
- }
57
+ if (!node) {
58
+ events.push("=VAL :");
59
+ return;
60
+ }
61
+ if (errPos !== -1 && node instanceof NodeBase && node.range[0] >= errPos) throw new Error();
62
+ let props = "";
63
+ let anchor = node instanceof Scalar || node instanceof Collection ? node.anchor : void 0;
64
+ if (anchor) {
65
+ if (/\d$/.test(anchor)) {
66
+ const alt = anchor.replace(/\d$/, "");
67
+ if (anchorExists(doc, alt)) anchor = alt;
68
+ }
69
+ props = ` &${anchor}`;
70
+ }
71
+ if (node instanceof NodeBase && node.tag) props += ` <${node.tag}>`;
72
+ if (node instanceof YAMLMap) {
73
+ const ev = node.flow ? "+MAP {}" : "+MAP";
74
+ events.push(`${ev}${props}`);
75
+ node.items.forEach(({ key, value }) => {
76
+ addEvents(events, doc, errPos, key);
77
+ addEvents(events, doc, errPos, value);
78
+ });
79
+ events.push("-MAP");
80
+ } else if (node instanceof YAMLSeq) {
81
+ const ev = node.flow ? "+SEQ []" : "+SEQ";
82
+ events.push(`${ev}${props}`);
83
+ node.items.forEach((item) => {
84
+ addEvents(events, doc, errPos, item);
85
+ });
86
+ events.push("-SEQ");
87
+ } else if (node instanceof Pair) {
88
+ events.push(`+MAP${props}`);
89
+ addEvents(events, doc, errPos, node.key);
90
+ addEvents(events, doc, errPos, node.value);
91
+ events.push("-MAP");
92
+ } else if (node instanceof Alias) {
93
+ let alias = node.source;
94
+ if (alias && /\d$/.test(alias)) {
95
+ const alt = alias.replace(/\d$/, "");
96
+ if (anchorExists(doc, alt)) alias = alt;
97
+ }
98
+ events.push(`=ALI${props} *${alias}`);
99
+ } else if (node instanceof Scalar) {
100
+ const scalar = scalarChar[String(node.type)];
101
+ if (!scalar) throw new Error(`Unexpected node type ${node.type}`);
102
+ 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");
103
+ events.push(`=VAL${props} ${scalar}${value}`);
104
+ } else throw new Error(`Unexpected node ${node}`);
132
105
  }
133
106
 
134
- exports.testEvents = testEvents;
107
+ //#endregion
108
+ 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 LogLevelId, F as StringifyContext, H as warn, L as ToJSContext, M as findPair, R as toJS, V as debug, a as string, i as foldFlowLines, n as stringifyNumber, o as seq, r as FoldOptions, s as map, t as stringifyString, z as NodeCreator } from "./stringifyString-S_ITVLTO.js";
2
+ export { type FoldOptions, type LogLevelId, type NodeCreator, type StringifyContext, type ToJSContext, debug, findPair, foldFlowLines, map as mapTag, seq as seqTag, string as stringTag, stringifyNumber, stringifyString, toJS, warn };
package/dist/util.js CHANGED
@@ -1,28 +1,3 @@
1
- 'use strict';
1
+ import { S as toJS, c as seq, d as findPair, h as warn, l as map, m as debug, o as stringifyNumber, s as string, v as stringifyString, y as foldFlowLines } from "./directives-CG6n4xSM.js";
2
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;
3
+ export { debug, findPair, foldFlowLines, map as mapTag, seq as seqTag, string as stringTag, stringifyNumber, stringifyString, toJS, warn };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml",
3
- "version": "2.8.2",
3
+ "version": "3.0.0-0",
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 };
@@ -1,102 +0,0 @@
1
- import { Alias } from '../nodes/Alias.js';
2
- import { isScalar } from '../nodes/identity.js';
3
- import { composeCollection } from './compose-collection.js';
4
- import { composeScalar } from './compose-scalar.js';
5
- import { resolveEnd } from './resolve-end.js';
6
- import { emptyScalarPosition } from './util-empty-scalar-position.js';
7
-
8
- const CN = { composeNode, composeEmptyNode };
9
- function composeNode(ctx, token, props, onError) {
10
- const atKey = ctx.atKey;
11
- const { spaceBefore, comment, anchor, tag } = props;
12
- let node;
13
- let isSrcToken = true;
14
- switch (token.type) {
15
- case 'alias':
16
- node = composeAlias(ctx, token, onError);
17
- if (anchor || tag)
18
- onError(token, 'ALIAS_PROPS', 'An alias node must not specify any properties');
19
- break;
20
- case 'scalar':
21
- case 'single-quoted-scalar':
22
- case 'double-quoted-scalar':
23
- case 'block-scalar':
24
- node = composeScalar(ctx, token, tag, onError);
25
- if (anchor)
26
- node.anchor = anchor.source.substring(1);
27
- break;
28
- case 'block-map':
29
- case 'block-seq':
30
- case 'flow-collection':
31
- node = composeCollection(CN, ctx, token, props, onError);
32
- if (anchor)
33
- node.anchor = anchor.source.substring(1);
34
- break;
35
- default: {
36
- const message = token.type === 'error'
37
- ? token.message
38
- : `Unsupported token (type: ${token.type})`;
39
- onError(token, 'UNEXPECTED_TOKEN', message);
40
- node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError);
41
- isSrcToken = false;
42
- }
43
- }
44
- if (anchor && node.anchor === '')
45
- onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
46
- if (atKey &&
47
- ctx.options.stringKeys &&
48
- (!isScalar(node) ||
49
- typeof node.value !== 'string' ||
50
- (node.tag && node.tag !== 'tag:yaml.org,2002:str'))) {
51
- const msg = 'With stringKeys, all keys must be strings';
52
- onError(tag ?? token, 'NON_STRING_KEY', msg);
53
- }
54
- if (spaceBefore)
55
- node.spaceBefore = true;
56
- if (comment) {
57
- if (token.type === 'scalar' && token.source === '')
58
- node.comment = comment;
59
- else
60
- node.commentBefore = comment;
61
- }
62
- // @ts-expect-error Type checking misses meaning of isSrcToken
63
- if (ctx.options.keepSourceTokens && isSrcToken)
64
- node.srcToken = token;
65
- return node;
66
- }
67
- function composeEmptyNode(ctx, offset, before, pos, { spaceBefore, comment, anchor, tag, end }, onError) {
68
- const token = {
69
- type: 'scalar',
70
- offset: emptyScalarPosition(offset, before, pos),
71
- indent: -1,
72
- source: ''
73
- };
74
- const node = composeScalar(ctx, token, tag, onError);
75
- if (anchor) {
76
- node.anchor = anchor.source.substring(1);
77
- if (node.anchor === '')
78
- onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
79
- }
80
- if (spaceBefore)
81
- node.spaceBefore = true;
82
- if (comment) {
83
- node.comment = comment;
84
- node.range[2] = end;
85
- }
86
- return node;
87
- }
88
- function composeAlias({ options }, { offset, source, end }, onError) {
89
- const alias = new Alias(source.substring(1));
90
- if (alias.source === '')
91
- onError(offset, 'BAD_ALIAS', 'Alias cannot be an empty string');
92
- if (alias.source.endsWith(':'))
93
- onError(offset + source.length - 1, 'BAD_ALIAS', 'Alias ending in : is ambiguous', true);
94
- const valueEnd = offset + source.length;
95
- const re = resolveEnd(end, valueEnd, options.strict, onError);
96
- alias.range = [offset, valueEnd, re.offset];
97
- if (re.comment)
98
- alias.comment = re.comment;
99
- return alias;
100
- }
101
-
102
- export { composeEmptyNode, composeNode };