yaml 1.8.2 → 1.9.2

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 (142) hide show
  1. package/browser/dist/Anchors.js +10 -13
  2. package/browser/dist/Document.js +72 -67
  3. package/browser/dist/addComment.js +1 -1
  4. package/browser/dist/cst/Alias.js +12 -8
  5. package/browser/dist/cst/BlankLine.js +16 -20
  6. package/browser/dist/cst/BlockValue.js +14 -10
  7. package/browser/dist/cst/Collection.js +17 -13
  8. package/browser/dist/cst/CollectionItem.js +15 -11
  9. package/browser/dist/cst/Comment.js +13 -9
  10. package/browser/dist/cst/Directive.js +13 -9
  11. package/browser/dist/cst/Document.js +17 -13
  12. package/browser/dist/cst/FlowCollection.js +17 -13
  13. package/browser/dist/cst/Node.js +3 -5
  14. package/browser/dist/cst/ParseContext.js +12 -14
  15. package/browser/dist/cst/PlainValue.js +12 -8
  16. package/browser/dist/cst/QuoteDouble.js +13 -9
  17. package/browser/dist/cst/QuoteSingle.js +13 -9
  18. package/browser/dist/cst/Range.js +2 -5
  19. package/browser/dist/cst/parse.js +3 -3
  20. package/browser/dist/errors.js +23 -8
  21. package/browser/dist/foldFlowLines.js +1 -1
  22. package/browser/dist/index.js +71 -21
  23. package/browser/dist/listTagNames.js +5 -5
  24. package/browser/dist/schema/Alias.js +30 -34
  25. package/browser/dist/schema/Collection.js +40 -47
  26. package/browser/dist/schema/Map.js +39 -56
  27. package/browser/dist/schema/Merge.js +37 -46
  28. package/browser/dist/schema/Node.js +2 -5
  29. package/browser/dist/schema/Pair.js +36 -13
  30. package/browser/dist/schema/Scalar.js +13 -9
  31. package/browser/dist/schema/Seq.js +27 -25
  32. package/browser/dist/schema/index.js +25 -39
  33. package/browser/dist/schema/parseMap.js +8 -8
  34. package/browser/dist/schema/parseSeq.js +5 -5
  35. package/browser/dist/schema/parseUtils.js +11 -15
  36. package/browser/dist/stringify.js +2 -1
  37. package/browser/dist/tags/core.js +39 -23
  38. package/browser/dist/tags/failsafe/index.js +4 -4
  39. package/browser/dist/tags/failsafe/map.js +15 -18
  40. package/browser/dist/tags/failsafe/seq.js +14 -18
  41. package/browser/dist/tags/failsafe/string.js +1 -1
  42. package/browser/dist/tags/index.js +10 -10
  43. package/browser/dist/tags/json.js +27 -26
  44. package/browser/dist/tags/options.js +3 -0
  45. package/browser/dist/tags/yaml-1.1/binary.js +10 -8
  46. package/browser/dist/tags/yaml-1.1/index.js +75 -43
  47. package/browser/dist/tags/yaml-1.1/omap.js +34 -39
  48. package/browser/dist/tags/yaml-1.1/pairs.js +17 -20
  49. package/browser/dist/tags/yaml-1.1/set.js +27 -23
  50. package/browser/dist/test-events.js +4 -4
  51. package/browser/dist/toJSON.js +3 -4
  52. package/browser/dist/warnings.js +29 -18
  53. package/browser/index.js +1 -1
  54. package/browser/map.js +4 -2
  55. package/browser/pair.js +4 -2
  56. package/browser/parse-cst.js +1 -1
  57. package/browser/scalar.js +4 -2
  58. package/browser/schema.js +11 -6
  59. package/browser/seq.js +4 -2
  60. package/browser/types/binary.js +5 -6
  61. package/browser/types/omap.js +4 -2
  62. package/browser/types/pairs.js +4 -2
  63. package/browser/types/set.js +4 -2
  64. package/browser/types/timestamp.js +5 -9
  65. package/browser/types.js +12 -10
  66. package/browser/util.js +16 -13
  67. package/dist/Anchors.js +13 -18
  68. package/dist/Document.js +52 -48
  69. package/dist/addComment.js +1 -4
  70. package/dist/constants.js +0 -3
  71. package/dist/cst/Alias.js +8 -13
  72. package/dist/cst/BlankLine.js +8 -24
  73. package/dist/cst/BlockValue.js +12 -17
  74. package/dist/cst/Collection.js +22 -27
  75. package/dist/cst/CollectionItem.js +16 -21
  76. package/dist/cst/Comment.js +6 -11
  77. package/dist/cst/Directive.js +7 -12
  78. package/dist/cst/Document.js +23 -28
  79. package/dist/cst/FlowCollection.js +21 -26
  80. package/dist/cst/Node.js +4 -9
  81. package/dist/cst/ParseContext.js +38 -43
  82. package/dist/cst/PlainValue.js +10 -15
  83. package/dist/cst/QuoteDouble.js +9 -14
  84. package/dist/cst/QuoteSingle.js +9 -14
  85. package/dist/cst/Range.js +2 -5
  86. package/dist/cst/parse.js +5 -10
  87. package/dist/cst/source-utils.js +0 -3
  88. package/dist/errors.js +4 -9
  89. package/dist/foldFlowLines.js +1 -4
  90. package/dist/index.js +59 -17
  91. package/dist/listTagNames.js +9 -14
  92. package/dist/schema/Alias.js +12 -17
  93. package/dist/schema/Collection.js +16 -20
  94. package/dist/schema/Map.js +12 -17
  95. package/dist/schema/Merge.js +13 -18
  96. package/dist/schema/Node.js +2 -5
  97. package/dist/schema/Pair.js +44 -31
  98. package/dist/schema/Scalar.js +6 -11
  99. package/dist/schema/Seq.js +9 -14
  100. package/dist/schema/index.js +22 -27
  101. package/dist/schema/parseMap.js +19 -28
  102. package/dist/schema/parseSeq.js +10 -15
  103. package/dist/schema/parseUtils.js +0 -3
  104. package/dist/stringify.js +6 -12
  105. package/dist/tags/core.js +34 -26
  106. package/dist/tags/failsafe/index.js +6 -11
  107. package/dist/tags/failsafe/map.js +8 -13
  108. package/dist/tags/failsafe/seq.js +8 -13
  109. package/dist/tags/failsafe/string.js +3 -6
  110. package/dist/tags/index.js +20 -29
  111. package/dist/tags/json.js +26 -22
  112. package/dist/tags/options.js +5 -4
  113. package/dist/tags/yaml-1.1/binary.js +11 -11
  114. package/dist/tags/yaml-1.1/index.js +69 -38
  115. package/dist/tags/yaml-1.1/omap.js +19 -24
  116. package/dist/tags/yaml-1.1/pairs.js +12 -17
  117. package/dist/tags/yaml-1.1/set.js +12 -21
  118. package/dist/tags/yaml-1.1/timestamp.js +0 -3
  119. package/dist/test-events.js +4 -9
  120. package/dist/toJSON.js +3 -5
  121. package/dist/warnings.js +31 -22
  122. package/index.d.ts +358 -0
  123. package/index.js +1 -1
  124. package/map.js +1 -1
  125. package/package.json +29 -23
  126. package/pair.js +1 -1
  127. package/parse-cst.d.ts +187 -0
  128. package/parse-cst.js +1 -1
  129. package/scalar.js +1 -1
  130. package/schema.js +2 -2
  131. package/seq.js +1 -1
  132. package/types/binary.js +1 -1
  133. package/types/omap.js +1 -1
  134. package/types/pairs.js +1 -1
  135. package/types/set.js +1 -1
  136. package/types/timestamp.js +1 -1
  137. package/types.d.ts +393 -0
  138. package/types.js +7 -6
  139. package/types.mjs +6 -5
  140. package/util.d.ts +86 -0
  141. package/util.js +6 -5
  142. package/util.mjs +4 -3
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
3
+ exports.Schema = void 0;
7
4
 
8
5
  var _warnings = require("../warnings");
9
6
 
@@ -17,17 +14,15 @@ var _tags = require("../tags");
17
14
 
18
15
  var _string = require("../tags/failsafe/string");
19
16
 
20
- var _Alias = _interopRequireDefault(require("./Alias"));
17
+ var _Alias = require("./Alias");
21
18
 
22
- var _Collection = _interopRequireDefault(require("./Collection"));
19
+ var _Collection = require("./Collection");
23
20
 
24
- var _Node = _interopRequireDefault(require("./Node"));
21
+ var _Node = require("./Node");
25
22
 
26
- var _Pair = _interopRequireDefault(require("./Pair"));
23
+ var _Pair = require("./Pair");
27
24
 
28
- var _Scalar = _interopRequireDefault(require("./Scalar"));
29
-
30
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+ var _Scalar = require("./Scalar");
31
26
 
32
27
  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
28
 
@@ -85,7 +80,7 @@ class Schema {
85
80
  }
86
81
 
87
82
  createNode(value, wrapScalars, tag, ctx) {
88
- if (value instanceof _Node.default) return value;
83
+ if (value instanceof _Node.Node) return value;
89
84
  let tagObj;
90
85
 
91
86
  if (tag) {
@@ -99,7 +94,7 @@ class Schema {
99
94
 
100
95
  if (!tagObj) {
101
96
  if (typeof value.toJSON === 'function') value = value.toJSON();
102
- if (typeof value !== 'object') return wrapScalars ? new _Scalar.default(value) : value;
97
+ if (typeof value !== 'object') return wrapScalars ? new _Scalar.Scalar(value) : value;
103
98
  tagObj = value instanceof Map ? _tags.tags.map : value[Symbol.iterator] ? _tags.tags.seq : _tags.tags.map;
104
99
  }
105
100
  }
@@ -119,7 +114,7 @@ class Schema {
119
114
  const prev = ctx.prevObjects.get(value);
120
115
 
121
116
  if (prev) {
122
- const alias = new _Alias.default(prev); // leaves source dirty; must be cleaned by caller
117
+ const alias = new _Alias.Alias(prev); // leaves source dirty; must be cleaned by caller
123
118
 
124
119
  ctx.aliasNodes.push(alias);
125
120
  return alias;
@@ -129,15 +124,15 @@ class Schema {
129
124
  ctx.prevObjects.set(value, obj);
130
125
  }
131
126
 
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;
127
+ obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new _Scalar.Scalar(value) : value;
128
+ if (tag && obj.node instanceof _Node.Node) obj.node.tag = tag;
134
129
  return obj.node;
135
130
  }
136
131
 
137
132
  createPair(key, value, ctx) {
138
133
  const k = this.createNode(key, ctx.wrapScalars, null, ctx);
139
134
  const v = this.createNode(value, ctx.wrapScalars, null, ctx);
140
- return new _Pair.default(k, v);
135
+ return new _Pair.Pair(k, v);
141
136
  } // falls back to string on no match
142
137
 
143
138
 
@@ -156,7 +151,7 @@ class Schema {
156
151
 
157
152
  if (match) {
158
153
  let res = resolve.apply(null, match);
159
- if (!(res instanceof _Scalar.default)) res = new _Scalar.default(res);
154
+ if (!(res instanceof _Scalar.Scalar)) res = new _Scalar.Scalar(res);
160
155
  if (format) res.format = format;
161
156
  return res;
162
157
  }
@@ -164,7 +159,7 @@ class Schema {
164
159
  }
165
160
 
166
161
  if (this.tags.scalarFallback) str = this.tags.scalarFallback(str);
167
- return new _Scalar.default(str);
162
+ return new _Scalar.Scalar(str);
168
163
  } // sets node.resolved on success
169
164
 
170
165
 
@@ -180,7 +175,7 @@ class Schema {
180
175
  try {
181
176
  if (generic) {
182
177
  let res = generic.resolve(doc, node);
183
- if (!(res instanceof _Collection.default)) res = new _Scalar.default(res);
178
+ if (!(res instanceof _Collection.Collection)) res = new _Scalar.Scalar(res);
184
179
  node.resolved = res;
185
180
  } else {
186
181
  const str = (0, _string.resolveString)(doc, node);
@@ -219,7 +214,7 @@ class Schema {
219
214
  }
220
215
 
221
216
  getTagObject(item) {
222
- if (item instanceof _Alias.default) return _Alias.default;
217
+ if (item instanceof _Alias.Alias) return _Alias.Alias;
223
218
 
224
219
  if (item.tag) {
225
220
  const match = this.tags.filter(t => t.tag === item.tag);
@@ -228,7 +223,7 @@ class Schema {
228
223
 
229
224
  let tagObj, obj;
230
225
 
231
- if (item instanceof _Scalar.default) {
226
+ if (item instanceof _Scalar.Scalar) {
232
227
  obj = item.value; // TODO: deprecate/remove class check
233
228
 
234
229
  const match = this.tags.filter(t => t.identify && t.identify(obj) || t.class && obj instanceof t.class);
@@ -271,7 +266,7 @@ class Schema {
271
266
  stringify(item, ctx, onComment, onChompKeep) {
272
267
  let tagObj;
273
268
 
274
- if (!(item instanceof _Node.default)) {
269
+ if (!(item instanceof _Node.Node)) {
275
270
  const createCtx = {
276
271
  aliasNodes: [],
277
272
  onTagObj: o => tagObj = o,
@@ -294,17 +289,17 @@ class Schema {
294
289
  }
295
290
 
296
291
  ctx.tags = this;
297
- if (item instanceof _Pair.default) return item.toString(ctx, onComment, onChompKeep);
292
+ if (item instanceof _Pair.Pair) return item.toString(ctx, onComment, onChompKeep);
298
293
  if (!tagObj) tagObj = this.getTagObject(item);
299
294
  const props = this.stringifyProps(item, tagObj, ctx);
300
295
  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;
296
+ const str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof _Collection.Collection ? item.toString(ctx, onComment, onChompKeep) : (0, _stringify.stringifyString)(item, ctx, onComment, onChompKeep);
297
+ return props ? item instanceof _Collection.Collection && str[0] !== '{' && str[0] !== '[' ? `${props}\n${ctx.indent}${str}` : `${props} ${str}` : str;
303
298
  }
304
299
 
305
300
  }
306
301
 
307
- exports.default = Schema;
302
+ exports.Schema = Schema;
308
303
 
309
304
  _defineProperty(Schema, "defaultPrefix", 'tag:yaml.org,2002:');
310
305
 
@@ -1,33 +1,24 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = parseMap;
3
+ exports.parseMap = parseMap;
7
4
 
8
5
  var _constants = require("../constants");
9
6
 
10
- var _PlainValue = _interopRequireDefault(require("../cst/PlainValue"));
7
+ var _PlainValue = require("../cst/PlainValue");
11
8
 
12
9
  var _errors = require("../errors");
13
10
 
14
- var _Map = _interopRequireDefault(require("./Map"));
11
+ var _Map = require("./Map");
15
12
 
16
- var _Merge = _interopRequireWildcard(require("./Merge"));
13
+ var _Merge = require("./Merge");
17
14
 
18
- var _Pair = _interopRequireDefault(require("./Pair"));
15
+ var _Pair = require("./Pair");
19
16
 
20
17
  var _parseUtils = require("./parseUtils");
21
18
 
22
- var _Alias = _interopRequireDefault(require("./Alias"));
19
+ var _Alias = require("./Alias");
23
20
 
24
- var _Collection = _interopRequireDefault(require("./Collection"));
25
-
26
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
27
-
28
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
-
30
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+ var _Collection = require("./Collection");
31
22
 
32
23
  function parseMap(doc, cst) {
33
24
  if (cst.type !== _constants.Type.MAP && cst.type !== _constants.Type.FLOW_MAP) {
@@ -40,7 +31,7 @@ function parseMap(doc, cst) {
40
31
  comments,
41
32
  items
42
33
  } = cst.type === _constants.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst);
43
- const map = new _Map.default();
34
+ const map = new _Map.YAMLMap();
44
35
  map.items = items;
45
36
  (0, _parseUtils.resolveComments)(map, comments);
46
37
  let hasCollectionKey = false;
@@ -49,14 +40,14 @@ function parseMap(doc, cst) {
49
40
  const {
50
41
  key: iKey
51
42
  } = items[i];
52
- if (iKey instanceof _Collection.default) hasCollectionKey = true;
43
+ if (iKey instanceof _Collection.Collection) hasCollectionKey = true;
53
44
 
54
45
  if (doc.schema.merge && iKey && iKey.value === _Merge.MERGE_KEY) {
55
- items[i] = new _Merge.default(items[i]);
46
+ items[i] = new _Merge.Merge(items[i]);
56
47
  const sources = items[i].value.items;
57
48
  let error = null;
58
49
  sources.some(node => {
59
- if (node instanceof _Alias.default) {
50
+ if (node instanceof _Alias.Alias) {
60
51
  // During parsing, alias sources are CST nodes; to account for
61
52
  // circular references their resolved values can't be used here.
62
53
  const {
@@ -160,7 +151,7 @@ function resolveBlockMapItems(doc, cst) {
160
151
  break;
161
152
 
162
153
  case _constants.Type.MAP_KEY:
163
- if (key !== undefined) items.push(new _Pair.default(key));
154
+ if (key !== undefined) items.push(new _Pair.Pair(key));
164
155
  if (item.error) doc.errors.push(item.error);
165
156
  key = doc.resolveNode(item.node);
166
157
  keyStart = null;
@@ -182,7 +173,7 @@ function resolveBlockMapItems(doc, cst) {
182
173
  // Comments on an empty mapping value need to be preserved, so we
183
174
  // need to construct a minimal empty node here to use instead of the
184
175
  // missing `item.node`. -- eemeli/yaml#19
185
- valueNode = new _PlainValue.default(_constants.Type.PLAIN, []);
176
+ valueNode = new _PlainValue.PlainValue(_constants.Type.PLAIN, []);
186
177
  valueNode.context = {
187
178
  parent: item,
188
179
  src: item.context.src
@@ -204,7 +195,7 @@ function resolveBlockMapItems(doc, cst) {
204
195
  }
205
196
  }
206
197
 
207
- const pair = new _Pair.default(key, doc.resolveNode(valueNode));
198
+ const pair = new _Pair.Pair(key, doc.resolveNode(valueNode));
208
199
  resolvePairComment(item, pair);
209
200
  items.push(pair);
210
201
  (0, _parseUtils.checkKeyLength)(doc.errors, cst, i, key, keyStart);
@@ -214,7 +205,7 @@ function resolveBlockMapItems(doc, cst) {
214
205
  break;
215
206
 
216
207
  default:
217
- if (key !== undefined) items.push(new _Pair.default(key));
208
+ if (key !== undefined) items.push(new _Pair.Pair(key));
218
209
  key = doc.resolveNode(item);
219
210
  keyStart = item.range.start;
220
211
  if (item.error) doc.errors.push(item.error);
@@ -244,7 +235,7 @@ function resolveBlockMapItems(doc, cst) {
244
235
  }
245
236
  }
246
237
 
247
- if (key !== undefined) items.push(new _Pair.default(key));
238
+ if (key !== undefined) items.push(new _Pair.Pair(key));
248
239
  return {
249
240
  comments,
250
241
  items
@@ -289,7 +280,7 @@ function resolveFlowMapItems(doc, cst) {
289
280
  }
290
281
 
291
282
  if (key !== undefined) {
292
- items.push(new _Pair.default(key));
283
+ items.push(new _Pair.Pair(key));
293
284
  key = undefined;
294
285
  keyStart = null;
295
286
 
@@ -328,14 +319,14 @@ function resolveFlowMapItems(doc, cst) {
328
319
  keyStart = explicitKey ? null : item.range.start; // TODO: add error for non-explicit multiline plain key
329
320
  } else {
330
321
  if (next !== ',') doc.errors.push(new _errors.YAMLSemanticError(item, 'Indicator : missing in flow map entry'));
331
- items.push(new _Pair.default(key, doc.resolveNode(item)));
322
+ items.push(new _Pair.Pair(key, doc.resolveNode(item)));
332
323
  key = undefined;
333
324
  explicitKey = false;
334
325
  }
335
326
  }
336
327
 
337
328
  (0, _parseUtils.checkFlowCollectionEnd)(doc.errors, cst);
338
- if (key !== undefined) items.push(new _Pair.default(key));
329
+ if (key !== undefined) items.push(new _Pair.Pair(key));
339
330
  return {
340
331
  comments,
341
332
  items
@@ -1,23 +1,18 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = parseSeq;
3
+ exports.parseSeq = parseSeq;
7
4
 
8
5
  var _constants = require("../constants");
9
6
 
10
7
  var _errors = require("../errors");
11
8
 
12
- var _Pair = _interopRequireDefault(require("./Pair"));
9
+ var _Pair = require("./Pair");
13
10
 
14
11
  var _parseUtils = require("./parseUtils");
15
12
 
16
- var _Seq = _interopRequireDefault(require("./Seq"));
13
+ var _Seq = require("./Seq");
17
14
 
18
- var _Collection = _interopRequireDefault(require("./Collection"));
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ var _Collection = require("./Collection");
21
16
 
22
17
  function parseSeq(doc, cst) {
23
18
  if (cst.type !== _constants.Type.SEQ && cst.type !== _constants.Type.FLOW_SEQ) {
@@ -30,11 +25,11 @@ function parseSeq(doc, cst) {
30
25
  comments,
31
26
  items
32
27
  } = cst.type === _constants.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst);
33
- const seq = new _Seq.default();
28
+ const seq = new _Seq.YAMLSeq();
34
29
  seq.items = items;
35
30
  (0, _parseUtils.resolveComments)(seq, comments);
36
31
 
37
- if (!doc.options.mapAsMap && items.some(it => it instanceof _Pair.default && it.key instanceof _Collection.default)) {
32
+ if (!doc.options.mapAsMap && items.some(it => it instanceof _Pair.Pair && it.key instanceof _Collection.Collection)) {
38
33
  const warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
39
34
  doc.warnings.push(new _errors.YAMLWarning(cst, warn));
40
35
  }
@@ -106,7 +101,7 @@ function resolveFlowSeqItems(doc, cst) {
106
101
 
107
102
  if (char !== ':' && (explicitKey || key !== undefined)) {
108
103
  if (explicitKey && key === undefined) key = next ? items.pop() : null;
109
- items.push(new _Pair.default(key));
104
+ items.push(new _Pair.Pair(key));
110
105
  explicitKey = false;
111
106
  key = undefined;
112
107
  keyStart = null;
@@ -120,7 +115,7 @@ function resolveFlowSeqItems(doc, cst) {
120
115
  if (next === ',') {
121
116
  key = items.pop();
122
117
 
123
- if (key instanceof _Pair.default) {
118
+ if (key instanceof _Pair.Pair) {
124
119
  const msg = 'Chaining flow sequence pairs is invalid';
125
120
  const err = new _errors.YAMLSemanticError(cst, msg);
126
121
  err.offset = offset;
@@ -162,7 +157,7 @@ function resolveFlowSeqItems(doc, cst) {
162
157
  if (key === undefined) {
163
158
  items.push(value);
164
159
  } else {
165
- items.push(new _Pair.default(key, value));
160
+ items.push(new _Pair.Pair(key, value));
166
161
  key = undefined;
167
162
  }
168
163
 
@@ -172,7 +167,7 @@ function resolveFlowSeqItems(doc, cst) {
172
167
  }
173
168
 
174
169
  (0, _parseUtils.checkFlowCollectionEnd)(doc.errors, cst);
175
- if (key !== undefined) items.push(new _Pair.default(key));
170
+ if (key !== undefined) items.push(new _Pair.Pair(key));
176
171
  return {
177
172
  comments,
178
173
  items
@@ -1,8 +1,5 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
3
  exports.checkFlowCollectionEnd = checkFlowCollectionEnd;
7
4
  exports.checkKeyLength = checkKeyLength;
8
5
  exports.resolveComments = resolveComments;
package/dist/stringify.js CHANGED
@@ -1,8 +1,5 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
3
  exports.stringifyNumber = stringifyNumber;
7
4
  exports.stringifyString = stringifyString;
8
5
 
@@ -10,14 +7,10 @@ var _addComment = require("./addComment");
10
7
 
11
8
  var _constants = require("./constants");
12
9
 
13
- var _foldFlowLines = _interopRequireWildcard(require("./foldFlowLines"));
10
+ var _foldFlowLines = require("./foldFlowLines");
14
11
 
15
12
  var _options = require("./tags/options");
16
13
 
17
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
18
-
19
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
-
21
14
  const getFoldOptions = ({
22
15
  indentAtStart
23
16
  }) => indentAtStart ? Object.assign({
@@ -30,6 +23,7 @@ function stringifyNumber({
30
23
  tag,
31
24
  value
32
25
  }) {
26
+ if (typeof value === 'bigint') return String(value);
33
27
  if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
34
28
  let n = JSON.stringify(value);
35
29
 
@@ -162,7 +156,7 @@ function doubleQuotedString(value, ctx) {
162
156
  }
163
157
 
164
158
  str = start ? str + json.slice(start) : json;
165
- return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx));
159
+ return implicitKey ? str : (0, _foldFlowLines.foldFlowLines)(str, indent, _foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx));
166
160
  }
167
161
 
168
162
  function singleQuotedString(value, ctx) {
@@ -179,7 +173,7 @@ function singleQuotedString(value, ctx) {
179
173
  }
180
174
 
181
175
  const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
182
- return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
176
+ return implicitKey ? res : (0, _foldFlowLines.foldFlowLines)(res, indent, _foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
183
177
  }
184
178
 
185
179
  function blockString({
@@ -244,7 +238,7 @@ function blockString({
244
238
  value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
245
239
  // ^ ind.line ^ empty ^ capture next empty lines only at end of indent
246
240
  .replace(/\n+/g, `$&${indent}`);
247
- const body = (0, _foldFlowLines.default)(`${wsStart}${value}${wsEnd}`, indent, _foldFlowLines.FOLD_BLOCK, _options.strOptions.fold);
241
+ const body = (0, _foldFlowLines.foldFlowLines)(`${wsStart}${value}${wsEnd}`, indent, _foldFlowLines.FOLD_BLOCK, _options.strOptions.fold);
248
242
  return `${header}\n${indent}${body}`;
249
243
  }
250
244
 
@@ -289,7 +283,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
289
283
  return doubleQuotedString(value, ctx);
290
284
  }
291
285
 
292
- const body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
286
+ const body = implicitKey ? str : (0, _foldFlowLines.foldFlowLines)(str, indent, _foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
293
287
 
294
288
  if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
295
289
  if (onComment) onComment();
package/dist/tags/core.js CHANGED
@@ -1,23 +1,31 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.floatObj = exports.expObj = exports.nanObj = exports.hexObj = exports.intObj = exports.octObj = exports.boolObj = exports.nullObj = void 0;
3
+ exports.core = exports.floatObj = exports.expObj = exports.nanObj = exports.hexObj = exports.intObj = exports.octObj = exports.boolObj = exports.nullObj = void 0;
7
4
 
8
- var _Scalar = _interopRequireDefault(require("../schema/Scalar"));
5
+ var _Scalar = require("../schema/Scalar");
9
6
 
10
7
  var _stringify = require("../stringify");
11
8
 
12
- var _failsafe = _interopRequireDefault(require("./failsafe"));
9
+ var _failsafe = require("./failsafe");
13
10
 
14
11
  var _options = require("./options");
15
12
 
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ /* global BigInt */
14
+ const intIdentify = value => typeof value === 'bigint' || Number.isInteger(value);
15
+
16
+ const intResolve = (src, part, radix) => _options.intOptions.asBigInt ? BigInt(src) : parseInt(part, radix);
17
+
18
+ function intStringify(node, radix, prefix) {
19
+ const {
20
+ value
21
+ } = node;
22
+ if (intIdentify(value) && value >= 0) return prefix + value.toString(radix);
23
+ return (0, _stringify.stringifyNumber)(node);
24
+ }
17
25
 
18
26
  const nullObj = {
19
27
  identify: value => value == null,
20
- createNode: (schema, value, ctx) => ctx.wrapScalars ? new _Scalar.default(null) : null,
28
+ createNode: (schema, value, ctx) => ctx.wrapScalars ? new _Scalar.Scalar(null) : null,
21
29
  default: true,
22
30
  tag: 'tag:yaml.org,2002:null',
23
31
  test: /^(?:~|[Nn]ull|NULL)?$/,
@@ -39,36 +47,35 @@ const boolObj = {
39
47
  };
40
48
  exports.boolObj = boolObj;
41
49
  const octObj = {
42
- identify: value => typeof value === 'number',
50
+ identify: value => intIdentify(value) && value >= 0,
43
51
  default: true,
44
52
  tag: 'tag:yaml.org,2002:int',
45
53
  format: 'OCT',
46
54
  test: /^0o([0-7]+)$/,
47
- resolve: (str, oct) => parseInt(oct, 8),
48
- stringify: ({
49
- value
50
- }) => '0o' + value.toString(8)
55
+ resolve: (str, oct) => intResolve(str, oct, 8),
56
+ options: _options.intOptions,
57
+ stringify: node => intStringify(node, 8, '0o')
51
58
  };
52
59
  exports.octObj = octObj;
53
60
  const intObj = {
54
- identify: value => typeof value === 'number',
61
+ identify: intIdentify,
55
62
  default: true,
56
63
  tag: 'tag:yaml.org,2002:int',
57
64
  test: /^[-+]?[0-9]+$/,
58
- resolve: str => parseInt(str, 10),
65
+ resolve: str => intResolve(str, str, 10),
66
+ options: _options.intOptions,
59
67
  stringify: _stringify.stringifyNumber
60
68
  };
61
69
  exports.intObj = intObj;
62
70
  const hexObj = {
63
- identify: value => typeof value === 'number',
71
+ identify: value => intIdentify(value) && value >= 0,
64
72
  default: true,
65
73
  tag: 'tag:yaml.org,2002:int',
66
74
  format: 'HEX',
67
75
  test: /^0x([0-9a-fA-F]+)$/,
68
- resolve: (str, hex) => parseInt(hex, 16),
69
- stringify: ({
70
- value
71
- }) => '0x' + value.toString(16)
76
+ resolve: (str, hex) => intResolve(str, hex, 16),
77
+ options: _options.intOptions,
78
+ stringify: node => intStringify(node, 16, '0x')
72
79
  };
73
80
  exports.hexObj = hexObj;
74
81
  const nanObj = {
@@ -85,7 +92,7 @@ const expObj = {
85
92
  default: true,
86
93
  tag: 'tag:yaml.org,2002:float',
87
94
  format: 'EXP',
88
- test: /^[-+]?(?:0|[1-9][0-9]*)(\.[0-9]*)?[eE][-+]?[0-9]+$/,
95
+ test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
89
96
  resolve: str => parseFloat(str),
90
97
  stringify: ({
91
98
  value
@@ -96,10 +103,11 @@ const floatObj = {
96
103
  identify: value => typeof value === 'number',
97
104
  default: true,
98
105
  tag: 'tag:yaml.org,2002:float',
99
- test: /^[-+]?(?:0|[1-9][0-9]*)\.([0-9]*)$/,
106
+ test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/,
100
107
 
101
- resolve(str, frac) {
102
- const node = new _Scalar.default(parseFloat(str));
108
+ resolve(str, frac1, frac2) {
109
+ const frac = frac1 || frac2;
110
+ const node = new _Scalar.Scalar(parseFloat(str));
103
111
  if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
104
112
  return node;
105
113
  },
@@ -108,6 +116,6 @@ const floatObj = {
108
116
  };
109
117
  exports.floatObj = floatObj;
110
118
 
111
- var _default = _failsafe.default.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
119
+ const core = _failsafe.failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
112
120
 
113
- exports.default = _default;
121
+ exports.core = core;
@@ -1,17 +1,12 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
3
+ exports.failsafe = void 0;
7
4
 
8
- var _map = _interopRequireDefault(require("./map"));
5
+ var _map = require("./map");
9
6
 
10
- var _seq = _interopRequireDefault(require("./seq"));
7
+ var _seq = require("./seq");
11
8
 
12
- var _string = _interopRequireDefault(require("./string"));
9
+ var _string = require("./string");
13
10
 
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- var _default = [_map.default, _seq.default, _string.default];
17
- exports.default = _default;
11
+ const failsafe = [_map.map, _seq.seq, _string.string];
12
+ exports.failsafe = failsafe;
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
3
+ exports.map = void 0;
7
4
 
8
- var _Map = _interopRequireDefault(require("../../schema/Map"));
5
+ var _Map = require("../../schema/Map");
9
6
 
10
- var _parseMap = _interopRequireDefault(require("../../schema/parseMap"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ var _parseMap = require("../../schema/parseMap");
13
8
 
14
9
  function createMap(schema, obj, ctx) {
15
- const map = new _Map.default(schema);
10
+ const map = new _Map.YAMLMap(schema);
16
11
 
17
12
  if (obj instanceof Map) {
18
13
  for (const [key, value] of obj) map.items.push(schema.createPair(key, value, ctx));
@@ -27,11 +22,11 @@ function createMap(schema, obj, ctx) {
27
22
  return map;
28
23
  }
29
24
 
30
- var _default = {
25
+ const map = {
31
26
  createNode: createMap,
32
27
  default: true,
33
- nodeClass: _Map.default,
28
+ nodeClass: _Map.YAMLMap,
34
29
  tag: 'tag:yaml.org,2002:map',
35
- resolve: _parseMap.default
30
+ resolve: _parseMap.parseMap
36
31
  };
37
- exports.default = _default;
32
+ exports.map = map;
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
3
+ exports.seq = void 0;
7
4
 
8
- var _parseSeq = _interopRequireDefault(require("../../schema/parseSeq"));
5
+ var _parseSeq = require("../../schema/parseSeq");
9
6
 
10
- var _Seq = _interopRequireDefault(require("../../schema/Seq"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ var _Seq = require("../../schema/Seq");
13
8
 
14
9
  function createSeq(schema, obj, ctx) {
15
- const seq = new _Seq.default(schema);
10
+ const seq = new _Seq.YAMLSeq(schema);
16
11
 
17
12
  if (obj && obj[Symbol.iterator]) {
18
13
  for (const it of obj) {
@@ -24,11 +19,11 @@ function createSeq(schema, obj, ctx) {
24
19
  return seq;
25
20
  }
26
21
 
27
- var _default = {
22
+ const seq = {
28
23
  createNode: createSeq,
29
24
  default: true,
30
- nodeClass: _Seq.default,
25
+ nodeClass: _Seq.YAMLSeq,
31
26
  tag: 'tag:yaml.org,2002:seq',
32
- resolve: _parseSeq.default
27
+ resolve: _parseSeq.parseSeq
33
28
  };
34
- exports.default = _default;
29
+ exports.seq = seq;