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,15 +1,14 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
3
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
- import parseCST from './cst/parse';
6
- import YAMLDocument from './Document';
7
- import { YAMLSemanticError } from './errors';
8
- import Schema from './schema';
9
- import { warn } from './warnings';
1
+ import { d as defaultTagPrefix, _ as _createForOfIteratorHelper, a as _typeof, b as _createClass, c as _classCallCheck, e as _defineProperty, Y as YAMLSyntaxError, T as Type, f as YAMLWarning, g as YAMLSemanticError, h as _slicedToArray, i as YAMLError, j as _inherits, k as _createSuper } from './PlainValue-ff5147c6.js';
2
+ import { parse as parse$1 } from './parse-cst.js';
3
+ import { b as binaryOptions, a as boolOptions, i as intOptions, n as nullOptions, s as strOptions, N as Node, P as Pair, S as Scalar, c as stringifyString, A as Alias, Y as YAMLSeq, d as YAMLMap, M as Merge, C as Collection, r as resolveNode, e as isEmptyPath, t as toJSON, f as addComment } from './resolveSeq-04825f30.js';
4
+ import { S as Schema } from './Schema-2bf2c74e.js';
5
+ import { w as warn } from './warnings-0e4b70d3.js';
6
+
10
7
  var defaultOptions = {
11
8
  anchorPrefix: 'a',
12
9
  customTags: null,
10
+ indent: 2,
11
+ indentSeq: true,
13
12
  keepCstNodes: false,
14
13
  keepNodeTypes: true,
15
14
  keepBlobsInJSON: true,
@@ -20,6 +19,896 @@ var defaultOptions = {
20
19
  simpleKeys: false,
21
20
  version: '1.2'
22
21
  };
22
+ var scalarOptions = {
23
+ get binary() {
24
+ return binaryOptions;
25
+ },
26
+
27
+ set binary(opt) {
28
+ Object.assign(binaryOptions, opt);
29
+ },
30
+
31
+ get bool() {
32
+ return boolOptions;
33
+ },
34
+
35
+ set bool(opt) {
36
+ Object.assign(boolOptions, opt);
37
+ },
38
+
39
+ get int() {
40
+ return intOptions;
41
+ },
42
+
43
+ set int(opt) {
44
+ Object.assign(intOptions, opt);
45
+ },
46
+
47
+ get null() {
48
+ return nullOptions;
49
+ },
50
+
51
+ set null(opt) {
52
+ Object.assign(nullOptions, opt);
53
+ },
54
+
55
+ get str() {
56
+ return strOptions;
57
+ },
58
+
59
+ set str(opt) {
60
+ Object.assign(strOptions, opt);
61
+ }
62
+
63
+ };
64
+ var documentOptions = {
65
+ '1.0': {
66
+ schema: 'yaml-1.1',
67
+ merge: true,
68
+ tagPrefixes: [{
69
+ handle: '!',
70
+ prefix: defaultTagPrefix
71
+ }, {
72
+ handle: '!!',
73
+ prefix: 'tag:private.yaml.org,2002:'
74
+ }]
75
+ },
76
+ '1.1': {
77
+ schema: 'yaml-1.1',
78
+ merge: true,
79
+ tagPrefixes: [{
80
+ handle: '!',
81
+ prefix: '!'
82
+ }, {
83
+ handle: '!!',
84
+ prefix: defaultTagPrefix
85
+ }]
86
+ },
87
+ '1.2': {
88
+ schema: 'core',
89
+ merge: false,
90
+ tagPrefixes: [{
91
+ handle: '!',
92
+ prefix: '!'
93
+ }, {
94
+ handle: '!!',
95
+ prefix: defaultTagPrefix
96
+ }]
97
+ }
98
+ };
99
+
100
+ function stringifyTag(doc, tag) {
101
+ if ((doc.version || doc.options.version) === '1.0') {
102
+ var priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/);
103
+ if (priv) return '!' + priv[1];
104
+ var vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/);
105
+ return vocab ? "!".concat(vocab[1], "/").concat(vocab[2]) : "!".concat(tag.replace(/^tag:/, ''));
106
+ }
107
+
108
+ var p = doc.tagPrefixes.find(function (p) {
109
+ return tag.indexOf(p.prefix) === 0;
110
+ });
111
+
112
+ if (!p) {
113
+ var dtp = doc.getDefaults().tagPrefixes;
114
+ p = dtp && dtp.find(function (p) {
115
+ return tag.indexOf(p.prefix) === 0;
116
+ });
117
+ }
118
+
119
+ if (!p) return tag[0] === '!' ? tag : "!<".concat(tag, ">");
120
+ var suffix = tag.substr(p.prefix.length).replace(/[!,[\]{}]/g, function (ch) {
121
+ return {
122
+ '!': '%21',
123
+ ',': '%2C',
124
+ '[': '%5B',
125
+ ']': '%5D',
126
+ '{': '%7B',
127
+ '}': '%7D'
128
+ }[ch];
129
+ });
130
+ return p.handle + suffix;
131
+ }
132
+
133
+ function getTagObject(tags, item) {
134
+ if (item instanceof Alias) return Alias;
135
+
136
+ if (item.tag) {
137
+ var match = tags.filter(function (t) {
138
+ return t.tag === item.tag;
139
+ });
140
+ if (match.length > 0) return match.find(function (t) {
141
+ return t.format === item.format;
142
+ }) || match[0];
143
+ }
144
+
145
+ var tagObj, obj;
146
+
147
+ if (item instanceof Scalar) {
148
+ obj = item.value; // TODO: deprecate/remove class check
149
+
150
+ var _match = tags.filter(function (t) {
151
+ return t.identify && t.identify(obj) || t.class && obj instanceof t.class;
152
+ });
153
+
154
+ tagObj = _match.find(function (t) {
155
+ return t.format === item.format;
156
+ }) || _match.find(function (t) {
157
+ return !t.format;
158
+ });
159
+ } else {
160
+ obj = item;
161
+ tagObj = tags.find(function (t) {
162
+ return t.nodeClass && obj instanceof t.nodeClass;
163
+ });
164
+ }
165
+
166
+ if (!tagObj) {
167
+ var name = obj && obj.constructor ? obj.constructor.name : _typeof(obj);
168
+ throw new Error("Tag not resolved for ".concat(name, " value"));
169
+ }
170
+
171
+ return tagObj;
172
+ } // needs to be called before value stringifier to allow for circular anchor refs
173
+
174
+
175
+ function stringifyProps(node, tagObj, _ref) {
176
+ var anchors = _ref.anchors,
177
+ doc = _ref.doc;
178
+ var props = [];
179
+ var anchor = doc.anchors.getName(node);
180
+
181
+ if (anchor) {
182
+ anchors[anchor] = node;
183
+ props.push("&".concat(anchor));
184
+ }
185
+
186
+ if (node.tag) {
187
+ props.push(stringifyTag(doc, node.tag));
188
+ } else if (!tagObj.default) {
189
+ props.push(stringifyTag(doc, tagObj.tag));
190
+ }
191
+
192
+ return props.join(' ');
193
+ }
194
+
195
+ function stringify(item, ctx, onComment, onChompKeep) {
196
+ var _ctx$doc = ctx.doc,
197
+ anchors = _ctx$doc.anchors,
198
+ schema = _ctx$doc.schema;
199
+ var tagObj;
200
+
201
+ if (!(item instanceof Node)) {
202
+ var createCtx = {
203
+ aliasNodes: [],
204
+ onTagObj: function onTagObj(o) {
205
+ return tagObj = o;
206
+ },
207
+ prevObjects: new Map()
208
+ };
209
+ item = schema.createNode(item, true, null, createCtx);
210
+
211
+ var _iterator = _createForOfIteratorHelper(createCtx.aliasNodes),
212
+ _step;
213
+
214
+ try {
215
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
216
+ var alias = _step.value;
217
+ alias.source = alias.source.node;
218
+ var name = anchors.getName(alias.source);
219
+
220
+ if (!name) {
221
+ name = anchors.newName();
222
+ anchors.map[name] = alias.source;
223
+ }
224
+ }
225
+ } catch (err) {
226
+ _iterator.e(err);
227
+ } finally {
228
+ _iterator.f();
229
+ }
230
+ }
231
+
232
+ if (item instanceof Pair) return item.toString(ctx, onComment, onChompKeep);
233
+ if (!tagObj) tagObj = getTagObject(schema.tags, item);
234
+ var props = stringifyProps(item, tagObj, ctx);
235
+ if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1;
236
+ var str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof Scalar ? stringifyString(item, ctx, onComment, onChompKeep) : item.toString(ctx, onComment, onChompKeep);
237
+ if (!props) return str;
238
+ return item instanceof Scalar || str[0] === '{' || str[0] === '[' ? "".concat(props, " ").concat(str) : "".concat(props, "\n").concat(ctx.indent).concat(str);
239
+ }
240
+
241
+ var Anchors = /*#__PURE__*/function () {
242
+ _createClass(Anchors, null, [{
243
+ key: "validAnchorNode",
244
+ value: function validAnchorNode(node) {
245
+ return node instanceof Scalar || node instanceof YAMLSeq || node instanceof YAMLMap;
246
+ }
247
+ }]);
248
+
249
+ function Anchors(prefix) {
250
+ _classCallCheck(this, Anchors);
251
+
252
+ _defineProperty(this, "map", {});
253
+
254
+ this.prefix = prefix;
255
+ }
256
+
257
+ _createClass(Anchors, [{
258
+ key: "createAlias",
259
+ value: function createAlias(node, name) {
260
+ this.setAnchor(node, name);
261
+ return new Alias(node);
262
+ }
263
+ }, {
264
+ key: "createMergePair",
265
+ value: function createMergePair() {
266
+ var _this = this;
267
+
268
+ var merge = new Merge();
269
+
270
+ for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) {
271
+ sources[_key] = arguments[_key];
272
+ }
273
+
274
+ merge.value.items = sources.map(function (s) {
275
+ if (s instanceof Alias) {
276
+ if (s.source instanceof YAMLMap) return s;
277
+ } else if (s instanceof YAMLMap) {
278
+ return _this.createAlias(s);
279
+ }
280
+
281
+ throw new Error('Merge sources must be Map nodes or their Aliases');
282
+ });
283
+ return merge;
284
+ }
285
+ }, {
286
+ key: "getName",
287
+ value: function getName(node) {
288
+ var map = this.map;
289
+ return Object.keys(map).find(function (a) {
290
+ return map[a] === node;
291
+ });
292
+ }
293
+ }, {
294
+ key: "getNames",
295
+ value: function getNames() {
296
+ return Object.keys(this.map);
297
+ }
298
+ }, {
299
+ key: "getNode",
300
+ value: function getNode(name) {
301
+ return this.map[name];
302
+ }
303
+ }, {
304
+ key: "newName",
305
+ value: function newName(prefix) {
306
+ if (!prefix) prefix = this.prefix;
307
+ var names = Object.keys(this.map);
308
+
309
+ for (var i = 1; true; ++i) {
310
+ var name = "".concat(prefix).concat(i);
311
+ if (!names.includes(name)) return name;
312
+ }
313
+ } // During parsing, map & aliases contain CST nodes
314
+
315
+ }, {
316
+ key: "resolveNodes",
317
+ value: function resolveNodes() {
318
+ var map = this.map,
319
+ _cstAliases = this._cstAliases;
320
+ Object.keys(map).forEach(function (a) {
321
+ map[a] = map[a].resolved;
322
+ });
323
+
324
+ _cstAliases.forEach(function (a) {
325
+ a.source = a.source.resolved;
326
+ });
327
+
328
+ delete this._cstAliases;
329
+ }
330
+ }, {
331
+ key: "setAnchor",
332
+ value: function setAnchor(node, name) {
333
+ if (node != null && !Anchors.validAnchorNode(node)) {
334
+ throw new Error('Anchors may only be set for Scalar, Seq and Map nodes');
335
+ }
336
+
337
+ if (name && /[\x00-\x19\s,[\]{}]/.test(name)) {
338
+ throw new Error('Anchor names must not contain whitespace or control characters');
339
+ }
340
+
341
+ var map = this.map;
342
+ var prev = node && Object.keys(map).find(function (a) {
343
+ return map[a] === node;
344
+ });
345
+
346
+ if (prev) {
347
+ if (!name) {
348
+ return prev;
349
+ } else if (prev !== name) {
350
+ delete map[prev];
351
+ map[name] = node;
352
+ }
353
+ } else {
354
+ if (!name) {
355
+ if (!node) return null;
356
+ name = this.newName();
357
+ }
358
+
359
+ map[name] = node;
360
+ }
361
+
362
+ return name;
363
+ }
364
+ }]);
365
+
366
+ return Anchors;
367
+ }();
368
+
369
+ var visit = function visit(node, tags) {
370
+ if (node && _typeof(node) === 'object') {
371
+ var tag = node.tag;
372
+
373
+ if (node instanceof Collection) {
374
+ if (tag) tags[tag] = true;
375
+ node.items.forEach(function (n) {
376
+ return visit(n, tags);
377
+ });
378
+ } else if (node instanceof Pair) {
379
+ visit(node.key, tags);
380
+ visit(node.value, tags);
381
+ } else if (node instanceof Scalar) {
382
+ if (tag) tags[tag] = true;
383
+ }
384
+ }
385
+
386
+ return tags;
387
+ };
388
+
389
+ var listTagNames = function listTagNames(node) {
390
+ return Object.keys(visit(node, {}));
391
+ };
392
+
393
+ function parseContents(doc, contents) {
394
+ var comments = {
395
+ before: [],
396
+ after: []
397
+ };
398
+ var body = undefined;
399
+ var spaceBefore = false;
400
+
401
+ var _iterator = _createForOfIteratorHelper(contents),
402
+ _step;
403
+
404
+ try {
405
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
406
+ var node = _step.value;
407
+
408
+ if (node.valueRange) {
409
+ if (body !== undefined) {
410
+ var msg = 'Document contains trailing content not separated by a ... or --- line';
411
+ doc.errors.push(new YAMLSyntaxError(node, msg));
412
+ break;
413
+ }
414
+
415
+ var res = resolveNode(doc, node);
416
+
417
+ if (spaceBefore) {
418
+ res.spaceBefore = true;
419
+ spaceBefore = false;
420
+ }
421
+
422
+ body = res;
423
+ } else if (node.comment !== null) {
424
+ var cc = body === undefined ? comments.before : comments.after;
425
+ cc.push(node.comment);
426
+ } else if (node.type === Type.BLANK_LINE) {
427
+ spaceBefore = true;
428
+
429
+ if (body === undefined && comments.before.length > 0 && !doc.commentBefore) {
430
+ // space-separated comments at start are parsed as document comments
431
+ doc.commentBefore = comments.before.join('\n');
432
+ comments.before = [];
433
+ }
434
+ }
435
+ }
436
+ } catch (err) {
437
+ _iterator.e(err);
438
+ } finally {
439
+ _iterator.f();
440
+ }
441
+
442
+ doc.contents = body || null;
443
+
444
+ if (!body) {
445
+ doc.comment = comments.before.concat(comments.after).join('\n') || null;
446
+ } else {
447
+ var cb = comments.before.join('\n');
448
+
449
+ if (cb) {
450
+ var cbNode = body instanceof Collection && body.items[0] ? body.items[0] : body;
451
+ cbNode.commentBefore = cbNode.commentBefore ? "".concat(cb, "\n").concat(cbNode.commentBefore) : cb;
452
+ }
453
+
454
+ doc.comment = comments.after.join('\n') || null;
455
+ }
456
+ }
457
+
458
+ function resolveTagDirective(_ref, directive) {
459
+ var tagPrefixes = _ref.tagPrefixes;
460
+
461
+ var _directive$parameters = _slicedToArray(directive.parameters, 2),
462
+ handle = _directive$parameters[0],
463
+ prefix = _directive$parameters[1];
464
+
465
+ if (!handle || !prefix) {
466
+ var msg = 'Insufficient parameters given for %TAG directive';
467
+ throw new YAMLSemanticError(directive, msg);
468
+ }
469
+
470
+ if (tagPrefixes.some(function (p) {
471
+ return p.handle === handle;
472
+ })) {
473
+ var _msg = 'The %TAG directive must only be given at most once per handle in the same document.';
474
+ throw new YAMLSemanticError(directive, _msg);
475
+ }
476
+
477
+ return {
478
+ handle: handle,
479
+ prefix: prefix
480
+ };
481
+ }
482
+
483
+ function resolveYamlDirective(doc, directive) {
484
+ var _directive$parameters2 = _slicedToArray(directive.parameters, 1),
485
+ version = _directive$parameters2[0];
486
+
487
+ if (directive.name === 'YAML:1.0') version = '1.0';
488
+
489
+ if (!version) {
490
+ var msg = 'Insufficient parameters given for %YAML directive';
491
+ throw new YAMLSemanticError(directive, msg);
492
+ }
493
+
494
+ if (!documentOptions[version]) {
495
+ var v0 = doc.version || doc.options.version;
496
+
497
+ var _msg2 = "Document will be parsed as YAML ".concat(v0, " rather than YAML ").concat(version);
498
+
499
+ doc.warnings.push(new YAMLWarning(directive, _msg2));
500
+ }
501
+
502
+ return version;
503
+ }
504
+
505
+ function parseDirectives(doc, directives, prevDoc) {
506
+ var directiveComments = [];
507
+ var hasDirectives = false;
508
+
509
+ var _iterator = _createForOfIteratorHelper(directives),
510
+ _step;
511
+
512
+ try {
513
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
514
+ var directive = _step.value;
515
+ var comment = directive.comment,
516
+ name = directive.name;
517
+
518
+ switch (name) {
519
+ case 'TAG':
520
+ try {
521
+ doc.tagPrefixes.push(resolveTagDirective(doc, directive));
522
+ } catch (error) {
523
+ doc.errors.push(error);
524
+ }
525
+
526
+ hasDirectives = true;
527
+ break;
528
+
529
+ case 'YAML':
530
+ case 'YAML:1.0':
531
+ if (doc.version) {
532
+ var msg = 'The %YAML directive must only be given at most once per document.';
533
+ doc.errors.push(new YAMLSemanticError(directive, msg));
534
+ }
535
+
536
+ try {
537
+ doc.version = resolveYamlDirective(doc, directive);
538
+ } catch (error) {
539
+ doc.errors.push(error);
540
+ }
541
+
542
+ hasDirectives = true;
543
+ break;
544
+
545
+ default:
546
+ if (name) {
547
+ var _msg3 = "YAML only supports %TAG and %YAML directives, and not %".concat(name);
548
+
549
+ doc.warnings.push(new YAMLWarning(directive, _msg3));
550
+ }
551
+
552
+ }
553
+
554
+ if (comment) directiveComments.push(comment);
555
+ }
556
+ } catch (err) {
557
+ _iterator.e(err);
558
+ } finally {
559
+ _iterator.f();
560
+ }
561
+
562
+ if (prevDoc && !hasDirectives && '1.1' === (doc.version || prevDoc.version || doc.options.version)) {
563
+ var copyTagPrefix = function copyTagPrefix(_ref2) {
564
+ var handle = _ref2.handle,
565
+ prefix = _ref2.prefix;
566
+ return {
567
+ handle: handle,
568
+ prefix: prefix
569
+ };
570
+ };
571
+
572
+ doc.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
573
+ doc.version = prevDoc.version;
574
+ }
575
+
576
+ doc.commentBefore = directiveComments.join('\n') || null;
577
+ }
578
+
579
+ function assertCollection(contents) {
580
+ if (contents instanceof Collection) return true;
581
+ throw new Error('Expected a YAML collection as document contents');
582
+ }
583
+
584
+ var Document = /*#__PURE__*/function () {
585
+ function Document(options) {
586
+ _classCallCheck(this, Document);
587
+
588
+ this.anchors = new Anchors(options.anchorPrefix);
589
+ this.commentBefore = null;
590
+ this.comment = null;
591
+ this.contents = null;
592
+ this.directivesEndMarker = null;
593
+ this.errors = [];
594
+ this.options = options;
595
+ this.schema = null;
596
+ this.tagPrefixes = [];
597
+ this.version = null;
598
+ this.warnings = [];
599
+ }
600
+
601
+ _createClass(Document, [{
602
+ key: "add",
603
+ value: function add(value) {
604
+ assertCollection(this.contents);
605
+ return this.contents.add(value);
606
+ }
607
+ }, {
608
+ key: "addIn",
609
+ value: function addIn(path, value) {
610
+ assertCollection(this.contents);
611
+ this.contents.addIn(path, value);
612
+ }
613
+ }, {
614
+ key: "delete",
615
+ value: function _delete(key) {
616
+ assertCollection(this.contents);
617
+ return this.contents.delete(key);
618
+ }
619
+ }, {
620
+ key: "deleteIn",
621
+ value: function deleteIn(path) {
622
+ if (isEmptyPath(path)) {
623
+ if (this.contents == null) return false;
624
+ this.contents = null;
625
+ return true;
626
+ }
627
+
628
+ assertCollection(this.contents);
629
+ return this.contents.deleteIn(path);
630
+ }
631
+ }, {
632
+ key: "getDefaults",
633
+ value: function getDefaults() {
634
+ return Document.defaults[this.version] || Document.defaults[this.options.version] || {};
635
+ }
636
+ }, {
637
+ key: "get",
638
+ value: function get(key, keepScalar) {
639
+ return this.contents instanceof Collection ? this.contents.get(key, keepScalar) : undefined;
640
+ }
641
+ }, {
642
+ key: "getIn",
643
+ value: function getIn(path, keepScalar) {
644
+ if (isEmptyPath(path)) return !keepScalar && this.contents instanceof Scalar ? this.contents.value : this.contents;
645
+ return this.contents instanceof Collection ? this.contents.getIn(path, keepScalar) : undefined;
646
+ }
647
+ }, {
648
+ key: "has",
649
+ value: function has(key) {
650
+ return this.contents instanceof Collection ? this.contents.has(key) : false;
651
+ }
652
+ }, {
653
+ key: "hasIn",
654
+ value: function hasIn(path) {
655
+ if (isEmptyPath(path)) return this.contents !== undefined;
656
+ return this.contents instanceof Collection ? this.contents.hasIn(path) : false;
657
+ }
658
+ }, {
659
+ key: "set",
660
+ value: function set(key, value) {
661
+ assertCollection(this.contents);
662
+ this.contents.set(key, value);
663
+ }
664
+ }, {
665
+ key: "setIn",
666
+ value: function setIn(path, value) {
667
+ if (isEmptyPath(path)) this.contents = value;else {
668
+ assertCollection(this.contents);
669
+ this.contents.setIn(path, value);
670
+ }
671
+ }
672
+ }, {
673
+ key: "setSchema",
674
+ value: function setSchema(id, customTags) {
675
+ if (!id && !customTags && this.schema) return;
676
+ if (typeof id === 'number') id = id.toFixed(1);
677
+
678
+ if (id === '1.0' || id === '1.1' || id === '1.2') {
679
+ if (this.version) this.version = id;else this.options.version = id;
680
+ delete this.options.schema;
681
+ } else if (id && typeof id === 'string') {
682
+ this.options.schema = id;
683
+ }
684
+
685
+ if (Array.isArray(customTags)) this.options.customTags = customTags;
686
+ var opt = Object.assign({}, this.getDefaults(), this.options);
687
+ this.schema = new Schema(opt);
688
+ }
689
+ }, {
690
+ key: "parse",
691
+ value: function parse(node, prevDoc) {
692
+ if (this.options.keepCstNodes) this.cstNode = node;
693
+ if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
694
+ var _node$directives = node.directives,
695
+ directives = _node$directives === void 0 ? [] : _node$directives,
696
+ _node$contents = node.contents,
697
+ contents = _node$contents === void 0 ? [] : _node$contents,
698
+ directivesEndMarker = node.directivesEndMarker,
699
+ error = node.error,
700
+ valueRange = node.valueRange;
701
+
702
+ if (error) {
703
+ if (!error.source) error.source = this;
704
+ this.errors.push(error);
705
+ }
706
+
707
+ parseDirectives(this, directives, prevDoc);
708
+ if (directivesEndMarker) this.directivesEndMarker = true;
709
+ this.range = valueRange ? [valueRange.start, valueRange.end] : null;
710
+ this.setSchema();
711
+ this.anchors._cstAliases = [];
712
+ parseContents(this, contents);
713
+ this.anchors.resolveNodes();
714
+
715
+ if (this.options.prettyErrors) {
716
+ var _iterator = _createForOfIteratorHelper(this.errors),
717
+ _step;
718
+
719
+ try {
720
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
721
+ var _error = _step.value;
722
+ if (_error instanceof YAMLError) _error.makePretty();
723
+ }
724
+ } catch (err) {
725
+ _iterator.e(err);
726
+ } finally {
727
+ _iterator.f();
728
+ }
729
+
730
+ var _iterator2 = _createForOfIteratorHelper(this.warnings),
731
+ _step2;
732
+
733
+ try {
734
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
735
+ var warn = _step2.value;
736
+ if (warn instanceof YAMLError) warn.makePretty();
737
+ }
738
+ } catch (err) {
739
+ _iterator2.e(err);
740
+ } finally {
741
+ _iterator2.f();
742
+ }
743
+ }
744
+
745
+ return this;
746
+ }
747
+ }, {
748
+ key: "listNonDefaultTags",
749
+ value: function listNonDefaultTags() {
750
+ return listTagNames(this.contents).filter(function (t) {
751
+ return t.indexOf(Schema.defaultPrefix) !== 0;
752
+ });
753
+ }
754
+ }, {
755
+ key: "setTagPrefix",
756
+ value: function setTagPrefix(handle, prefix) {
757
+ if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !');
758
+
759
+ if (prefix) {
760
+ var prev = this.tagPrefixes.find(function (p) {
761
+ return p.handle === handle;
762
+ });
763
+ if (prev) prev.prefix = prefix;else this.tagPrefixes.push({
764
+ handle: handle,
765
+ prefix: prefix
766
+ });
767
+ } else {
768
+ this.tagPrefixes = this.tagPrefixes.filter(function (p) {
769
+ return p.handle !== handle;
770
+ });
771
+ }
772
+ }
773
+ }, {
774
+ key: "toJSON",
775
+ value: function toJSON$1(arg, onAnchor) {
776
+ var _this = this;
777
+
778
+ var _this$options = this.options,
779
+ keepBlobsInJSON = _this$options.keepBlobsInJSON,
780
+ mapAsMap = _this$options.mapAsMap,
781
+ maxAliasCount = _this$options.maxAliasCount;
782
+ var keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof Scalar));
783
+ var ctx = {
784
+ doc: this,
785
+ indentStep: ' ',
786
+ keep: keep,
787
+ mapAsMap: keep && !!mapAsMap,
788
+ maxAliasCount: maxAliasCount,
789
+ stringify: stringify // Requiring directly in Pair would create circular dependencies
790
+
791
+ };
792
+ var anchorNames = Object.keys(this.anchors.map);
793
+ if (anchorNames.length > 0) ctx.anchors = new Map(anchorNames.map(function (name) {
794
+ return [_this.anchors.map[name], {
795
+ alias: [],
796
+ aliasCount: 0,
797
+ count: 1
798
+ }];
799
+ }));
800
+
801
+ var res = toJSON(this.contents, arg, ctx);
802
+
803
+ if (typeof onAnchor === 'function' && ctx.anchors) {
804
+ var _iterator3 = _createForOfIteratorHelper(ctx.anchors.values()),
805
+ _step3;
806
+
807
+ try {
808
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
809
+ var _step3$value = _step3.value,
810
+ count = _step3$value.count,
811
+ _res = _step3$value.res;
812
+ onAnchor(_res, count);
813
+ }
814
+ } catch (err) {
815
+ _iterator3.e(err);
816
+ } finally {
817
+ _iterator3.f();
818
+ }
819
+ }
820
+
821
+ return res;
822
+ }
823
+ }, {
824
+ key: "toString",
825
+ value: function toString() {
826
+ if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified');
827
+ var indentSize = this.options.indent;
828
+
829
+ if (!Number.isInteger(indentSize) || indentSize <= 0) {
830
+ var s = JSON.stringify(indentSize);
831
+ throw new Error("\"indent\" option must be a positive integer, not ".concat(s));
832
+ }
833
+
834
+ this.setSchema();
835
+ var lines = [];
836
+ var hasDirectives = false;
837
+
838
+ if (this.version) {
839
+ var vd = '%YAML 1.2';
840
+
841
+ if (this.schema.name === 'yaml-1.1') {
842
+ if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1';
843
+ }
844
+
845
+ lines.push(vd);
846
+ hasDirectives = true;
847
+ }
848
+
849
+ var tagNames = this.listNonDefaultTags();
850
+ this.tagPrefixes.forEach(function (_ref) {
851
+ var handle = _ref.handle,
852
+ prefix = _ref.prefix;
853
+
854
+ if (tagNames.some(function (t) {
855
+ return t.indexOf(prefix) === 0;
856
+ })) {
857
+ lines.push("%TAG ".concat(handle, " ").concat(prefix));
858
+ hasDirectives = true;
859
+ }
860
+ });
861
+ if (hasDirectives || this.directivesEndMarker) lines.push('---');
862
+
863
+ if (this.commentBefore) {
864
+ if (hasDirectives || !this.directivesEndMarker) lines.unshift('');
865
+ lines.unshift(this.commentBefore.replace(/^/gm, '#'));
866
+ }
867
+
868
+ var ctx = {
869
+ anchors: {},
870
+ doc: this,
871
+ indent: '',
872
+ indentStep: ' '.repeat(indentSize),
873
+ stringify: stringify // Requiring directly in nodes would create circular dependencies
874
+
875
+ };
876
+ var chompKeep = false;
877
+ var contentComment = null;
878
+
879
+ if (this.contents) {
880
+ if (this.contents instanceof Node) {
881
+ if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
882
+ if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
883
+
884
+ ctx.forceBlockIndent = !!this.comment;
885
+ contentComment = this.contents.comment;
886
+ }
887
+
888
+ var onChompKeep = contentComment ? null : function () {
889
+ return chompKeep = true;
890
+ };
891
+ var body = stringify(this.contents, ctx, function () {
892
+ return contentComment = null;
893
+ }, onChompKeep);
894
+ lines.push(addComment(body, '', contentComment));
895
+ } else if (this.contents !== undefined) {
896
+ lines.push(stringify(this.contents, ctx));
897
+ }
898
+
899
+ if (this.comment) {
900
+ if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '') lines.push('');
901
+ lines.push(this.comment.replace(/^/gm, '#'));
902
+ }
903
+
904
+ return lines.join('\n') + '\n';
905
+ }
906
+ }]);
907
+
908
+ return Document;
909
+ }();
910
+
911
+ _defineProperty(Document, "defaults", documentOptions);
23
912
 
24
913
  function createNode(value) {
25
914
  var wrapScalars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
@@ -30,59 +919,52 @@ function createNode(value) {
30
919
  wrapScalars = true;
31
920
  }
32
921
 
33
- var options = Object.assign({}, YAMLDocument.defaults[defaultOptions.version], defaultOptions);
922
+ var options = Object.assign({}, Document.defaults[defaultOptions.version], defaultOptions);
34
923
  var schema = new Schema(options);
35
924
  return schema.createNode(value, wrapScalars, tag);
36
925
  }
37
926
 
38
- var Document = /*#__PURE__*/function (_YAMLDocument) {
927
+ var Document$1 = /*#__PURE__*/function (_YAMLDocument) {
39
928
  _inherits(Document, _YAMLDocument);
40
929
 
930
+ var _super = _createSuper(Document);
931
+
41
932
  function Document(options) {
42
933
  _classCallCheck(this, Document);
43
934
 
44
- return _possibleConstructorReturn(this, _getPrototypeOf(Document).call(this, Object.assign({}, defaultOptions, options)));
935
+ return _super.call(this, Object.assign({}, defaultOptions, options));
45
936
  }
46
937
 
47
938
  return Document;
48
- }(YAMLDocument);
939
+ }(Document);
49
940
 
50
941
  function parseAllDocuments(src, options) {
51
942
  var stream = [];
52
943
  var prev;
53
- var _iteratorNormalCompletion = true;
54
- var _didIteratorError = false;
55
- var _iteratorError = undefined;
944
+
945
+ var _iterator = _createForOfIteratorHelper(parse$1(src)),
946
+ _step;
56
947
 
57
948
  try {
58
- for (var _iterator = parseCST(src)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
949
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
59
950
  var cstDoc = _step.value;
60
- var doc = new Document(options);
951
+ var doc = new Document$1(options);
61
952
  doc.parse(cstDoc, prev);
62
953
  stream.push(doc);
63
954
  prev = doc;
64
955
  }
65
956
  } catch (err) {
66
- _didIteratorError = true;
67
- _iteratorError = err;
957
+ _iterator.e(err);
68
958
  } finally {
69
- try {
70
- if (!_iteratorNormalCompletion && _iterator.return != null) {
71
- _iterator.return();
72
- }
73
- } finally {
74
- if (_didIteratorError) {
75
- throw _iteratorError;
76
- }
77
- }
959
+ _iterator.f();
78
960
  }
79
961
 
80
962
  return stream;
81
963
  }
82
964
 
83
965
  function parseDocument(src, options) {
84
- var cst = parseCST(src);
85
- var doc = new Document(options).parse(cst[0]);
966
+ var cst = parse$1(src);
967
+ var doc = new Document$1(options).parse(cst[0]);
86
968
 
87
969
  if (cst.length > 1) {
88
970
  var errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()';
@@ -101,19 +983,22 @@ function parse(src, options) {
101
983
  return doc.toJSON();
102
984
  }
103
985
 
104
- function stringify(value, options) {
105
- var doc = new Document(options);
986
+ function stringify$1(value, options) {
987
+ var doc = new Document$1(options);
106
988
  doc.contents = value;
107
989
  return String(doc);
108
990
  }
109
991
 
110
- export default {
992
+ var YAML = {
111
993
  createNode: createNode,
112
994
  defaultOptions: defaultOptions,
113
- Document: Document,
995
+ Document: Document$1,
114
996
  parse: parse,
115
997
  parseAllDocuments: parseAllDocuments,
116
- parseCST: parseCST,
998
+ parseCST: parse$1,
117
999
  parseDocument: parseDocument,
118
- stringify: stringify
119
- };
1000
+ scalarOptions: scalarOptions,
1001
+ stringify: stringify$1
1002
+ };
1003
+
1004
+ export { YAML };