yaml 1.8.3 → 1.10.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 (163) hide show
  1. package/README.md +4 -4
  2. package/browser/dist/PlainValue-ff5147c6.js +1277 -0
  3. package/browser/dist/Schema-2bf2c74e.js +679 -0
  4. package/browser/dist/index.js +923 -38
  5. package/browser/dist/legacy-exports.js +3 -0
  6. package/browser/dist/parse-cst.js +1904 -0
  7. package/browser/dist/resolveSeq-04825f30.js +2373 -0
  8. package/browser/dist/types.js +4 -0
  9. package/browser/dist/util.js +2 -0
  10. package/browser/dist/warnings-0e4b70d3.js +499 -0
  11. package/browser/index.js +1 -1
  12. package/browser/map.js +2 -2
  13. package/browser/pair.js +2 -2
  14. package/browser/parse-cst.js +1 -1
  15. package/browser/scalar.js +2 -2
  16. package/browser/schema.js +8 -6
  17. package/browser/seq.js +2 -2
  18. package/browser/types/binary.js +3 -2
  19. package/browser/types/omap.js +3 -2
  20. package/browser/types/pairs.js +3 -2
  21. package/browser/types/set.js +3 -2
  22. package/browser/types/timestamp.js +6 -6
  23. package/browser/types.js +1 -11
  24. package/browser/util.js +1 -15
  25. package/dist/Document-2cf6b08c.js +757 -0
  26. package/dist/PlainValue-ec8e588e.js +876 -0
  27. package/dist/Schema-42e9705c.js +522 -0
  28. package/dist/index.js +21 -43
  29. package/dist/legacy-exports.js +16 -0
  30. package/dist/parse-cst.js +1747 -0
  31. package/dist/resolveSeq-4a68b39b.js +2115 -0
  32. package/dist/test-events.js +11 -14
  33. package/dist/types.js +23 -0
  34. package/dist/util.js +19 -0
  35. package/dist/warnings-39684f17.js +416 -0
  36. package/index.d.ts +372 -0
  37. package/index.js +1 -1
  38. package/map.js +2 -2
  39. package/package.json +32 -45
  40. package/pair.js +2 -2
  41. package/parse-cst.d.ts +187 -0
  42. package/parse-cst.js +1 -1
  43. package/scalar.js +2 -2
  44. package/schema.js +8 -6
  45. package/seq.js +2 -2
  46. package/types/binary.js +3 -2
  47. package/types/omap.js +3 -2
  48. package/types/pairs.js +3 -2
  49. package/types/set.js +3 -2
  50. package/types/timestamp.js +6 -6
  51. package/types.d.ts +407 -0
  52. package/types.js +16 -10
  53. package/types.mjs +15 -18
  54. package/util.d.ts +86 -0
  55. package/util.js +14 -13
  56. package/util.mjs +13 -19
  57. package/browser/dist/Anchors.js +0 -133
  58. package/browser/dist/Document.js +0 -819
  59. package/browser/dist/addComment.js +0 -8
  60. package/browser/dist/constants.js +0 -26
  61. package/browser/dist/cst/Alias.js +0 -42
  62. package/browser/dist/cst/BlankLine.js +0 -56
  63. package/browser/dist/cst/BlockValue.js +0 -247
  64. package/browser/dist/cst/Collection.js +0 -274
  65. package/browser/dist/cst/CollectionItem.js +0 -136
  66. package/browser/dist/cst/Comment.js +0 -40
  67. package/browser/dist/cst/Directive.js +0 -72
  68. package/browser/dist/cst/Document.js +0 -282
  69. package/browser/dist/cst/FlowCollection.js +0 -216
  70. package/browser/dist/cst/Node.js +0 -388
  71. package/browser/dist/cst/ParseContext.js +0 -248
  72. package/browser/dist/cst/PlainValue.js +0 -166
  73. package/browser/dist/cst/QuoteDouble.js +0 -241
  74. package/browser/dist/cst/QuoteSingle.js +0 -116
  75. package/browser/dist/cst/Range.js +0 -67
  76. package/browser/dist/cst/parse.js +0 -48
  77. package/browser/dist/cst/source-utils.js +0 -168
  78. package/browser/dist/errors.js +0 -112
  79. package/browser/dist/foldFlowLines.js +0 -138
  80. package/browser/dist/listTagNames.js +0 -28
  81. package/browser/dist/schema/Alias.js +0 -139
  82. package/browser/dist/schema/Collection.js +0 -267
  83. package/browser/dist/schema/Map.js +0 -178
  84. package/browser/dist/schema/Merge.js +0 -127
  85. package/browser/dist/schema/Node.js +0 -7
  86. package/browser/dist/schema/Pair.js +0 -171
  87. package/browser/dist/schema/Scalar.js +0 -38
  88. package/browser/dist/schema/Seq.js +0 -114
  89. package/browser/dist/schema/index.js +0 -382
  90. package/browser/dist/schema/parseMap.js +0 -312
  91. package/browser/dist/schema/parseSeq.js +0 -168
  92. package/browser/dist/schema/parseUtils.js +0 -110
  93. package/browser/dist/stringify.js +0 -331
  94. package/browser/dist/tags/core.js +0 -126
  95. package/browser/dist/tags/failsafe/index.js +0 -4
  96. package/browser/dist/tags/failsafe/map.js +0 -56
  97. package/browser/dist/tags/failsafe/seq.js +0 -43
  98. package/browser/dist/tags/failsafe/string.js +0 -28
  99. package/browser/dist/tags/index.js +0 -36
  100. package/browser/dist/tags/json.js +0 -76
  101. package/browser/dist/tags/options.js +0 -23
  102. package/browser/dist/tags/yaml-1.1/binary.js +0 -87
  103. package/browser/dist/tags/yaml-1.1/index.js +0 -157
  104. package/browser/dist/tags/yaml-1.1/omap.js +0 -142
  105. package/browser/dist/tags/yaml-1.1/pairs.js +0 -81
  106. package/browser/dist/tags/yaml-1.1/set.js +0 -114
  107. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -97
  108. package/browser/dist/test-events.js +0 -163
  109. package/browser/dist/toJSON.js +0 -20
  110. package/browser/dist/warnings.js +0 -28
  111. package/dist/Anchors.js +0 -125
  112. package/dist/Document.js +0 -710
  113. package/dist/addComment.js +0 -17
  114. package/dist/constants.js +0 -34
  115. package/dist/cst/Alias.js +0 -38
  116. package/dist/cst/BlankLine.js +0 -56
  117. package/dist/cst/BlockValue.js +0 -248
  118. package/dist/cst/Collection.js +0 -271
  119. package/dist/cst/CollectionItem.js +0 -140
  120. package/dist/cst/Comment.js +0 -38
  121. package/dist/cst/Directive.js +0 -64
  122. package/dist/cst/Document.js +0 -281
  123. package/dist/cst/FlowCollection.js +0 -218
  124. package/dist/cst/Node.js +0 -365
  125. package/dist/cst/ParseContext.js +0 -258
  126. package/dist/cst/PlainValue.js +0 -161
  127. package/dist/cst/QuoteDouble.js +0 -237
  128. package/dist/cst/QuoteSingle.js +0 -113
  129. package/dist/cst/Range.js +0 -63
  130. package/dist/cst/parse.js +0 -55
  131. package/dist/cst/source-utils.js +0 -178
  132. package/dist/errors.js +0 -102
  133. package/dist/foldFlowLines.js +0 -146
  134. package/dist/listTagNames.js +0 -38
  135. package/dist/schema/Alias.js +0 -110
  136. package/dist/schema/Collection.js +0 -188
  137. package/dist/schema/Map.js +0 -103
  138. package/dist/schema/Merge.js +0 -80
  139. package/dist/schema/Node.js +0 -10
  140. package/dist/schema/Pair.js +0 -161
  141. package/dist/schema/Scalar.js +0 -31
  142. package/dist/schema/Seq.js +0 -78
  143. package/dist/schema/index.js +0 -315
  144. package/dist/schema/parseMap.js +0 -343
  145. package/dist/schema/parseSeq.js +0 -180
  146. package/dist/schema/parseUtils.js +0 -104
  147. package/dist/stringify.js +0 -358
  148. package/dist/tags/core.js +0 -114
  149. package/dist/tags/failsafe/index.js +0 -17
  150. package/dist/tags/failsafe/map.js +0 -37
  151. package/dist/tags/failsafe/seq.js +0 -34
  152. package/dist/tags/failsafe/string.js +0 -40
  153. package/dist/tags/index.js +0 -62
  154. package/dist/tags/json.js +0 -60
  155. package/dist/tags/options.js +0 -35
  156. package/dist/tags/yaml-1.1/binary.js +0 -97
  157. package/dist/tags/yaml-1.1/index.js +0 -131
  158. package/dist/tags/yaml-1.1/omap.js +0 -105
  159. package/dist/tags/yaml-1.1/pairs.js +0 -80
  160. package/dist/tags/yaml-1.1/set.js +0 -91
  161. package/dist/tags/yaml-1.1/timestamp.js +0 -93
  162. package/dist/toJSON.js +0 -23
  163. package/dist/warnings.js +0 -39
@@ -1,78 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _toJSON = _interopRequireDefault(require("../toJSON"));
9
-
10
- var _Collection = _interopRequireDefault(require("./Collection"));
11
-
12
- var _Scalar = _interopRequireDefault(require("./Scalar"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- // Published as 'yaml/seq'
17
- function asItemIndex(key) {
18
- let idx = key instanceof _Scalar.default ? key.value : key;
19
- if (idx && typeof idx === 'string') idx = Number(idx);
20
- return Number.isInteger(idx) && idx >= 0 ? idx : null;
21
- }
22
-
23
- class YAMLSeq extends _Collection.default {
24
- add(value) {
25
- this.items.push(value);
26
- }
27
-
28
- delete(key) {
29
- const idx = asItemIndex(key);
30
- if (typeof idx !== 'number') return false;
31
- const del = this.items.splice(idx, 1);
32
- return del.length > 0;
33
- }
34
-
35
- get(key, keepScalar) {
36
- const idx = asItemIndex(key);
37
- if (typeof idx !== 'number') return undefined;
38
- const it = this.items[idx];
39
- return !keepScalar && it instanceof _Scalar.default ? it.value : it;
40
- }
41
-
42
- has(key) {
43
- const idx = asItemIndex(key);
44
- return typeof idx === 'number' && idx < this.items.length;
45
- }
46
-
47
- set(key, value) {
48
- const idx = asItemIndex(key);
49
- if (typeof idx !== 'number') throw new Error(`Expected a valid index, not ${key}.`);
50
- this.items[idx] = value;
51
- }
52
-
53
- toJSON(_, ctx) {
54
- const seq = [];
55
- if (ctx && ctx.onCreate) ctx.onCreate(seq);
56
- let i = 0;
57
-
58
- for (const item of this.items) seq.push((0, _toJSON.default)(item, String(i++), ctx));
59
-
60
- return seq;
61
- }
62
-
63
- toString(ctx, onComment, onChompKeep) {
64
- if (!ctx) return JSON.stringify(this);
65
- return super.toString(ctx, {
66
- blockItem: n => n.type === 'comment' ? n.str : `- ${n.str}`,
67
- flowChars: {
68
- start: '[',
69
- end: ']'
70
- },
71
- isMap: false,
72
- itemIndent: (ctx.indent || '') + ' '
73
- }, onComment, onChompKeep);
74
- }
75
-
76
- }
77
-
78
- exports.default = YAMLSeq;
@@ -1,315 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _warnings = require("../warnings");
9
-
10
- var _constants = require("../constants");
11
-
12
- var _errors = require("../errors");
13
-
14
- var _stringify = require("../stringify");
15
-
16
- var _tags = require("../tags");
17
-
18
- var _string = require("../tags/failsafe/string");
19
-
20
- var _Alias = _interopRequireDefault(require("./Alias"));
21
-
22
- var _Collection = _interopRequireDefault(require("./Collection"));
23
-
24
- var _Node = _interopRequireDefault(require("./Node"));
25
-
26
- var _Pair = _interopRequireDefault(require("./Pair"));
27
-
28
- var _Scalar = _interopRequireDefault(require("./Scalar"));
29
-
30
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
-
32
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
33
-
34
- const isMap = ({
35
- type
36
- }) => type === _constants.Type.FLOW_MAP || type === _constants.Type.MAP;
37
-
38
- const isSeq = ({
39
- type
40
- }) => type === _constants.Type.FLOW_SEQ || type === _constants.Type.SEQ;
41
-
42
- class Schema {
43
- constructor({
44
- customTags,
45
- merge,
46
- schema,
47
- sortMapEntries,
48
- tags: deprecatedCustomTags
49
- }) {
50
- this.merge = !!merge;
51
- this.name = schema;
52
- this.sortMapEntries = sortMapEntries === true ? (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0 : sortMapEntries || null;
53
- this.tags = _tags.schemas[schema.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
54
-
55
- if (!this.tags) {
56
- const keys = Object.keys(_tags.schemas).map(key => JSON.stringify(key)).join(', ');
57
- throw new Error(`Unknown schema "${schema}"; use one of ${keys}`);
58
- }
59
-
60
- if (!customTags && deprecatedCustomTags) {
61
- customTags = deprecatedCustomTags;
62
- (0, _warnings.warnOptionDeprecation)('tags', 'customTags');
63
- }
64
-
65
- if (Array.isArray(customTags)) {
66
- for (const tag of customTags) this.tags = this.tags.concat(tag);
67
- } else if (typeof customTags === 'function') {
68
- this.tags = customTags(this.tags.slice());
69
- }
70
-
71
- for (let i = 0; i < this.tags.length; ++i) {
72
- const tag = this.tags[i];
73
-
74
- if (typeof tag === 'string') {
75
- const tagObj = _tags.tags[tag];
76
-
77
- if (!tagObj) {
78
- const keys = Object.keys(_tags.tags).map(key => JSON.stringify(key)).join(', ');
79
- throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
80
- }
81
-
82
- this.tags[i] = tagObj;
83
- }
84
- }
85
- }
86
-
87
- createNode(value, wrapScalars, tag, ctx) {
88
- if (value instanceof _Node.default) return value;
89
- let tagObj;
90
-
91
- if (tag) {
92
- if (tag.startsWith('!!')) tag = Schema.defaultPrefix + tag.slice(2);
93
- const match = this.tags.filter(t => t.tag === tag);
94
- tagObj = match.find(t => !t.format) || match[0];
95
- if (!tagObj) throw new Error(`Tag ${tag} not found`);
96
- } else {
97
- // TODO: deprecate/remove class check
98
- tagObj = this.tags.find(t => (t.identify && t.identify(value) || t.class && value instanceof t.class) && !t.format);
99
-
100
- if (!tagObj) {
101
- if (typeof value.toJSON === 'function') value = value.toJSON();
102
- if (typeof value !== 'object') return wrapScalars ? new _Scalar.default(value) : value;
103
- tagObj = value instanceof Map ? _tags.tags.map : value[Symbol.iterator] ? _tags.tags.seq : _tags.tags.map;
104
- }
105
- }
106
-
107
- if (!ctx) ctx = {
108
- wrapScalars
109
- };else ctx.wrapScalars = wrapScalars;
110
-
111
- if (ctx.onTagObj) {
112
- ctx.onTagObj(tagObj);
113
- delete ctx.onTagObj;
114
- }
115
-
116
- const obj = {};
117
-
118
- if (value && typeof value === 'object' && ctx.prevObjects) {
119
- const prev = ctx.prevObjects.get(value);
120
-
121
- if (prev) {
122
- const alias = new _Alias.default(prev); // leaves source dirty; must be cleaned by caller
123
-
124
- ctx.aliasNodes.push(alias);
125
- return alias;
126
- }
127
-
128
- obj.value = value;
129
- ctx.prevObjects.set(value, obj);
130
- }
131
-
132
- obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new _Scalar.default(value) : value;
133
- if (tag && obj.node instanceof _Node.default) obj.node.tag = tag;
134
- return obj.node;
135
- }
136
-
137
- createPair(key, value, ctx) {
138
- const k = this.createNode(key, ctx.wrapScalars, null, ctx);
139
- const v = this.createNode(value, ctx.wrapScalars, null, ctx);
140
- return new _Pair.default(k, v);
141
- } // falls back to string on no match
142
-
143
-
144
- resolveScalar(str, tags) {
145
- if (!tags) tags = this.tags;
146
-
147
- for (let i = 0; i < tags.length; ++i) {
148
- const {
149
- format,
150
- test,
151
- resolve
152
- } = tags[i];
153
-
154
- if (test) {
155
- const match = str.match(test);
156
-
157
- if (match) {
158
- let res = resolve.apply(null, match);
159
- if (!(res instanceof _Scalar.default)) res = new _Scalar.default(res);
160
- if (format) res.format = format;
161
- return res;
162
- }
163
- }
164
- }
165
-
166
- if (this.tags.scalarFallback) str = this.tags.scalarFallback(str);
167
- return new _Scalar.default(str);
168
- } // sets node.resolved on success
169
-
170
-
171
- resolveNode(doc, node, tagName) {
172
- const tags = this.tags.filter(({
173
- tag
174
- }) => tag === tagName);
175
- const generic = tags.find(({
176
- test
177
- }) => !test);
178
- if (node.error) doc.errors.push(node.error);
179
-
180
- try {
181
- if (generic) {
182
- let res = generic.resolve(doc, node);
183
- if (!(res instanceof _Collection.default)) res = new _Scalar.default(res);
184
- node.resolved = res;
185
- } else {
186
- const str = (0, _string.resolveString)(doc, node);
187
-
188
- if (typeof str === 'string' && tags.length > 0) {
189
- node.resolved = this.resolveScalar(str, tags);
190
- }
191
- }
192
- } catch (error) {
193
- /* istanbul ignore if */
194
- if (!error.source) error.source = node;
195
- doc.errors.push(error);
196
- node.resolved = null;
197
- }
198
-
199
- if (!node.resolved) return null;
200
- if (tagName && node.tag) node.resolved.tag = tagName;
201
- return node.resolved;
202
- }
203
-
204
- resolveNodeWithFallback(doc, node, tagName) {
205
- const res = this.resolveNode(doc, node, tagName);
206
- if (Object.prototype.hasOwnProperty.call(node, 'resolved')) return res;
207
- const fallback = isMap(node) ? Schema.defaultTags.MAP : isSeq(node) ? Schema.defaultTags.SEQ : Schema.defaultTags.STR;
208
- /* istanbul ignore else */
209
-
210
- if (fallback) {
211
- doc.warnings.push(new _errors.YAMLWarning(node, `The tag ${tagName} is unavailable, falling back to ${fallback}`));
212
- const res = this.resolveNode(doc, node, fallback);
213
- res.tag = tagName;
214
- return res;
215
- } else {
216
- doc.errors.push(new _errors.YAMLReferenceError(node, `The tag ${tagName} is unavailable`));
217
- return null;
218
- }
219
- }
220
-
221
- getTagObject(item) {
222
- if (item instanceof _Alias.default) return _Alias.default;
223
-
224
- if (item.tag) {
225
- const match = this.tags.filter(t => t.tag === item.tag);
226
- if (match.length > 0) return match.find(t => t.format === item.format) || match[0];
227
- }
228
-
229
- let tagObj, obj;
230
-
231
- if (item instanceof _Scalar.default) {
232
- obj = item.value; // TODO: deprecate/remove class check
233
-
234
- const match = this.tags.filter(t => t.identify && t.identify(obj) || t.class && obj instanceof t.class);
235
- tagObj = match.find(t => t.format === item.format) || match.find(t => !t.format);
236
- } else {
237
- obj = item;
238
- tagObj = this.tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
239
- }
240
-
241
- if (!tagObj) {
242
- const name = obj && obj.constructor ? obj.constructor.name : typeof obj;
243
- throw new Error(`Tag not resolved for ${name} value`);
244
- }
245
-
246
- return tagObj;
247
- } // needs to be called before stringifier to allow for circular anchor refs
248
-
249
-
250
- stringifyProps(node, tagObj, {
251
- anchors,
252
- doc
253
- }) {
254
- const props = [];
255
- const anchor = doc.anchors.getName(node);
256
-
257
- if (anchor) {
258
- anchors[anchor] = node;
259
- props.push(`&${anchor}`);
260
- }
261
-
262
- if (node.tag) {
263
- props.push(doc.stringifyTag(node.tag));
264
- } else if (!tagObj.default) {
265
- props.push(doc.stringifyTag(tagObj.tag));
266
- }
267
-
268
- return props.join(' ');
269
- }
270
-
271
- stringify(item, ctx, onComment, onChompKeep) {
272
- let tagObj;
273
-
274
- if (!(item instanceof _Node.default)) {
275
- const createCtx = {
276
- aliasNodes: [],
277
- onTagObj: o => tagObj = o,
278
- prevObjects: new Map()
279
- };
280
- item = this.createNode(item, true, null, createCtx);
281
- const {
282
- anchors
283
- } = ctx.doc;
284
-
285
- for (const alias of createCtx.aliasNodes) {
286
- alias.source = alias.source.node;
287
- let name = anchors.getName(alias.source);
288
-
289
- if (!name) {
290
- name = anchors.newName();
291
- anchors.map[name] = alias.source;
292
- }
293
- }
294
- }
295
-
296
- ctx.tags = this;
297
- if (item instanceof _Pair.default) return item.toString(ctx, onComment, onChompKeep);
298
- if (!tagObj) tagObj = this.getTagObject(item);
299
- const props = this.stringifyProps(item, tagObj, ctx);
300
- if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1;
301
- const str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof _Collection.default ? item.toString(ctx, onComment, onChompKeep) : (0, _stringify.stringifyString)(item, ctx, onComment, onChompKeep);
302
- return props ? item instanceof _Collection.default && str[0] !== '{' && str[0] !== '[' ? `${props}\n${ctx.indent}${str}` : `${props} ${str}` : str;
303
- }
304
-
305
- }
306
-
307
- exports.default = Schema;
308
-
309
- _defineProperty(Schema, "defaultPrefix", 'tag:yaml.org,2002:');
310
-
311
- _defineProperty(Schema, "defaultTags", {
312
- MAP: 'tag:yaml.org,2002:map',
313
- SEQ: 'tag:yaml.org,2002:seq',
314
- STR: 'tag:yaml.org,2002:str'
315
- });