yaml 2.0.0-0 → 2.0.0-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,89 @@
1
1
  'use strict';
2
2
 
3
- var PlainValue = require('./PlainValue-ec8e588e.js');
4
- var resolveSeq = require('./resolveSeq-6b2dc4ac.js');
3
+ var _rollupPluginBabelHelpers = require('./_rollupPluginBabelHelpers-eed30217.js');
4
+ var stringifyNumber = require('./stringifyNumber-dea1120c.js');
5
+
6
+ const MERGE_KEY = '<<';
7
+ class Merge extends stringifyNumber.Pair {
8
+ constructor(pair) {
9
+ if (pair instanceof stringifyNumber.Pair) {
10
+ let seq = pair.value;
11
+
12
+ if (!(seq instanceof stringifyNumber.YAMLSeq)) {
13
+ seq = new stringifyNumber.YAMLSeq();
14
+ seq.items.push(pair.value);
15
+ seq.range = pair.value.range;
16
+ }
17
+
18
+ super(pair.key, seq);
19
+ this.range = pair.range;
20
+ } else {
21
+ super(new stringifyNumber.Scalar(MERGE_KEY), new stringifyNumber.YAMLSeq());
22
+ }
23
+
24
+ this.type = stringifyNumber.Pair.Type.MERGE_PAIR;
25
+ } // If the value associated with a merge key is a single mapping node, each of
26
+ // its key/value pairs is inserted into the current mapping, unless the key
27
+ // already exists in it. If the value associated with the merge key is a
28
+ // sequence, then this sequence is expected to contain mapping nodes and each
29
+ // of these nodes is merged in turn according to its order in the sequence.
30
+ // Keys in mapping nodes earlier in the sequence override keys specified in
31
+ // later mapping nodes. -- http://yaml.org/type/merge.html
32
+
33
+
34
+ addToJSMap(ctx, map) {
35
+ for (const {
36
+ source
37
+ } of this.value.items) {
38
+ if (!(source instanceof stringifyNumber.YAMLMap)) throw new Error('Merge sources must be maps');
39
+ const srcMap = source.toJSON(null, ctx, Map);
40
+
41
+ for (const [key, value] of srcMap) {
42
+ if (map instanceof Map) {
43
+ if (!map.has(key)) map.set(key, value);
44
+ } else if (map instanceof Set) {
45
+ map.add(key);
46
+ } else if (!Object.prototype.hasOwnProperty.call(map, key)) {
47
+ Object.defineProperty(map, key, {
48
+ value,
49
+ writable: true,
50
+ enumerable: true,
51
+ configurable: true
52
+ });
53
+ }
54
+ }
55
+ }
56
+
57
+ return map;
58
+ }
59
+
60
+ toString(ctx, onComment) {
61
+ const seq = this.value;
62
+ if (seq.items.length > 1) return super.toString(ctx, onComment);
63
+ this.value = seq.items[0];
64
+ const str = super.toString(ctx, onComment);
65
+ this.value = seq;
66
+ return str;
67
+ }
68
+
69
+ }
5
70
 
6
71
  function createMap(schema, obj, ctx) {
7
- const map = new resolveSeq.YAMLMap(schema);
72
+ const {
73
+ keepUndefined,
74
+ replacer
75
+ } = ctx;
76
+ const map = new stringifyNumber.YAMLMap(schema);
77
+
78
+ const add = (key, value) => {
79
+ if (typeof replacer === 'function') value = replacer.call(obj, key, value);else if (Array.isArray(replacer) && !replacer.includes(key)) return;
80
+ if (value !== undefined || keepUndefined) map.items.push(stringifyNumber.createPair(key, value, ctx));
81
+ };
8
82
 
9
83
  if (obj instanceof Map) {
10
- for (const [key, value] of obj) map.items.push(resolveSeq.createPair(key, value, ctx));
84
+ for (const [key, value] of obj) add(key, value);
11
85
  } else if (obj && typeof obj === 'object') {
12
- for (const key of Object.keys(obj)) {
13
- const value = obj[key];
14
- if (value !== undefined) map.items.push(resolveSeq.createPair(key, value, ctx));
15
- }
86
+ for (const key of Object.keys(obj)) add(key, obj[key]);
16
87
  }
17
88
 
18
89
  if (typeof schema.sortMapEntries === 'function') {
@@ -25,16 +96,28 @@ function createMap(schema, obj, ctx) {
25
96
  const map = {
26
97
  createNode: createMap,
27
98
  default: true,
28
- nodeClass: resolveSeq.YAMLMap,
99
+ nodeClass: stringifyNumber.YAMLMap,
29
100
  tag: 'tag:yaml.org,2002:map',
30
- resolve: resolveSeq.resolveMap
101
+ resolve: map => map
31
102
  };
32
103
 
33
104
  function createSeq(schema, obj, ctx) {
34
- const seq = new resolveSeq.YAMLSeq(schema);
105
+ const {
106
+ replacer
107
+ } = ctx;
108
+ const seq = new stringifyNumber.YAMLSeq(schema);
35
109
 
36
110
  if (obj && obj[Symbol.iterator]) {
37
- for (const it of obj) seq.items.push(resolveSeq.createNode(it, null, ctx));
111
+ let i = 0;
112
+
113
+ for (let it of obj) {
114
+ if (typeof replacer === 'function') {
115
+ const key = obj instanceof Set ? it : String(i++);
116
+ it = replacer.call(obj, key, it);
117
+ }
118
+
119
+ seq.items.push(stringifyNumber.createNode(it, null, ctx));
120
+ }
38
121
  }
39
122
 
40
123
  return seq;
@@ -43,25 +126,25 @@ function createSeq(schema, obj, ctx) {
43
126
  const seq = {
44
127
  createNode: createSeq,
45
128
  default: true,
46
- nodeClass: resolveSeq.YAMLSeq,
129
+ nodeClass: stringifyNumber.YAMLSeq,
47
130
  tag: 'tag:yaml.org,2002:seq',
48
- resolve: resolveSeq.resolveSeq
131
+ resolve: seq => seq
49
132
  };
50
133
 
51
134
  const string = {
52
135
  identify: value => typeof value === 'string',
53
136
  default: true,
54
137
  tag: 'tag:yaml.org,2002:str',
55
- resolve: resolveSeq.resolveString,
138
+ resolve: str => str,
56
139
 
57
140
  stringify(item, ctx, onComment, onChompKeep) {
58
141
  ctx = Object.assign({
59
142
  actualString: true
60
143
  }, ctx);
61
- return resolveSeq.stringifyString(item, ctx, onComment, onChompKeep);
144
+ return stringifyNumber.stringifyString(item, ctx, onComment, onChompKeep);
62
145
  },
63
146
 
64
- options: resolveSeq.strOptions
147
+ options: stringifyNumber.strOptions
65
148
  };
66
149
 
67
150
  const failsafe = [map, seq, string];
@@ -70,25 +153,31 @@ const failsafe = [map, seq, string];
70
153
 
71
154
  const intIdentify = value => typeof value === 'bigint' || Number.isInteger(value);
72
155
 
73
- const intResolve = (src, part, radix) => resolveSeq.intOptions.asBigInt ? BigInt(src) : parseInt(part, radix);
156
+ const intResolve = (src, offset, radix) => stringifyNumber.intOptions.asBigInt ? BigInt(src) : parseInt(src.substring(offset), radix);
74
157
 
75
158
  function intStringify(node, radix, prefix) {
76
159
  const {
77
160
  value
78
161
  } = node;
79
162
  if (intIdentify(value) && value >= 0) return prefix + value.toString(radix);
80
- return resolveSeq.stringifyNumber(node);
163
+ return stringifyNumber.stringifyNumber(node);
81
164
  }
82
165
 
83
166
  const nullObj = {
84
167
  identify: value => value == null,
85
- createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq.Scalar(null) : null,
168
+ createNode: (schema, value, ctx) => ctx.wrapScalars ? new stringifyNumber.Scalar(null) : null,
86
169
  default: true,
87
170
  tag: 'tag:yaml.org,2002:null',
88
171
  test: /^(?:~|[Nn]ull|NULL)?$/,
89
- resolve: () => null,
90
- options: resolveSeq.nullOptions,
91
- stringify: () => resolveSeq.nullOptions.nullStr
172
+ resolve: str => {
173
+ const node = new stringifyNumber.Scalar(null);
174
+ node.sourceStr = str;
175
+ return node;
176
+ },
177
+ options: stringifyNumber.nullOptions,
178
+ stringify: ({
179
+ sourceStr
180
+ }) => sourceStr !== null && sourceStr !== void 0 ? sourceStr : stringifyNumber.nullOptions.nullStr
92
181
  };
93
182
  const boolObj = {
94
183
  identify: value => typeof value === 'boolean',
@@ -96,19 +185,19 @@ const boolObj = {
96
185
  tag: 'tag:yaml.org,2002:bool',
97
186
  test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
98
187
  resolve: str => str[0] === 't' || str[0] === 'T',
99
- options: resolveSeq.boolOptions,
188
+ options: stringifyNumber.boolOptions,
100
189
  stringify: ({
101
190
  value
102
- }) => value ? resolveSeq.boolOptions.trueStr : resolveSeq.boolOptions.falseStr
191
+ }) => value ? stringifyNumber.boolOptions.trueStr : stringifyNumber.boolOptions.falseStr
103
192
  };
104
193
  const octObj = {
105
194
  identify: value => intIdentify(value) && value >= 0,
106
195
  default: true,
107
196
  tag: 'tag:yaml.org,2002:int',
108
197
  format: 'OCT',
109
- test: /^0o([0-7]+)$/,
110
- resolve: (str, oct) => intResolve(str, oct, 8),
111
- options: resolveSeq.intOptions,
198
+ test: /^0o[0-7]+$/,
199
+ resolve: str => intResolve(str, 2, 8),
200
+ options: stringifyNumber.intOptions,
112
201
  stringify: node => intStringify(node, 8, '0o')
113
202
  };
114
203
  const intObj = {
@@ -116,27 +205,27 @@ const intObj = {
116
205
  default: true,
117
206
  tag: 'tag:yaml.org,2002:int',
118
207
  test: /^[-+]?[0-9]+$/,
119
- resolve: str => intResolve(str, str, 10),
120
- options: resolveSeq.intOptions,
121
- stringify: resolveSeq.stringifyNumber
208
+ resolve: str => intResolve(str, 0, 10),
209
+ options: stringifyNumber.intOptions,
210
+ stringify: stringifyNumber.stringifyNumber
122
211
  };
123
212
  const hexObj = {
124
213
  identify: value => intIdentify(value) && value >= 0,
125
214
  default: true,
126
215
  tag: 'tag:yaml.org,2002:int',
127
216
  format: 'HEX',
128
- test: /^0x([0-9a-fA-F]+)$/,
129
- resolve: (str, hex) => intResolve(str, hex, 16),
130
- options: resolveSeq.intOptions,
217
+ test: /^0x[0-9a-fA-F]+$/,
218
+ resolve: str => intResolve(str, 2, 16),
219
+ options: stringifyNumber.intOptions,
131
220
  stringify: node => intStringify(node, 16, '0x')
132
221
  };
133
222
  const nanObj = {
134
223
  identify: value => typeof value === 'number',
135
224
  default: true,
136
225
  tag: 'tag:yaml.org,2002:float',
137
- test: /^(?:[-+]?\.inf|(\.nan))$/i,
138
- resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
139
- stringify: resolveSeq.stringifyNumber
226
+ test: /^(?:[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN))$/,
227
+ resolve: str => str.slice(-3).toLowerCase() === 'nan' ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
228
+ stringify: stringifyNumber.stringifyNumber
140
229
  };
141
230
  const expObj = {
142
231
  identify: value => typeof value === 'number',
@@ -153,16 +242,16 @@ const floatObj = {
153
242
  identify: value => typeof value === 'number',
154
243
  default: true,
155
244
  tag: 'tag:yaml.org,2002:float',
156
- test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/,
245
+ test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
157
246
 
158
- resolve(str, frac1, frac2) {
159
- const frac = frac1 || frac2;
160
- const node = new resolveSeq.Scalar(parseFloat(str));
161
- if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
247
+ resolve(str) {
248
+ const node = new stringifyNumber.Scalar(parseFloat(str));
249
+ const dot = str.indexOf('.');
250
+ if (dot !== -1 && str[str.length - 1] === '0') node.minFractionDigits = str.length - dot - 1;
162
251
  return node;
163
252
  },
164
253
 
165
- stringify: resolveSeq.stringifyNumber
254
+ stringify: stringifyNumber.stringifyNumber
166
255
  };
167
256
  const core = failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
168
257
 
@@ -178,11 +267,11 @@ const json = [map, seq, {
178
267
  identify: value => typeof value === 'string',
179
268
  default: true,
180
269
  tag: 'tag:yaml.org,2002:str',
181
- resolve: resolveSeq.resolveString,
270
+ resolve: str => str,
182
271
  stringify: stringifyJSON
183
272
  }, {
184
273
  identify: value => value == null,
185
- createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq.Scalar(null) : null,
274
+ createNode: (schema, value, ctx) => ctx.wrapScalars ? new stringifyNumber.Scalar(null) : null,
186
275
  default: true,
187
276
  tag: 'tag:yaml.org,2002:null',
188
277
  test: /^null$/,
@@ -200,7 +289,7 @@ const json = [map, seq, {
200
289
  default: true,
201
290
  tag: 'tag:yaml.org,2002:int',
202
291
  test: /^-?(?:0|[1-9][0-9]*)$/,
203
- resolve: str => resolveSeq.intOptions.asBigInt ? BigInt(str) : parseInt(str, 10),
292
+ resolve: str => stringifyNumber.intOptions.asBigInt ? BigInt(str) : parseInt(str, 10),
204
293
  stringify: ({
205
294
  value
206
295
  }) => intIdentify$1(value) ? value.toString() : JSON.stringify(value)
@@ -211,11 +300,16 @@ const json = [map, seq, {
211
300
  test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
212
301
  resolve: str => parseFloat(str),
213
302
  stringify: stringifyJSON
214
- }];
303
+ }, {
304
+ default: true,
305
+ test: /^/,
215
306
 
216
- json.scalarFallback = str => {
217
- throw new SyntaxError(`Unresolved plain scalar ${JSON.stringify(str)}`);
218
- };
307
+ resolve(str, onError) {
308
+ onError(`Unresolved plain scalar ${JSON.stringify(str)}`);
309
+ return str;
310
+ }
311
+
312
+ }];
219
313
 
220
314
  /* global atob, btoa, Buffer */
221
315
  const binary = {
@@ -232,9 +326,7 @@ const binary = {
232
326
  * const blob = new Blob([buffer], { type: 'image/jpeg' })
233
327
  * document.querySelector('#photo').src = URL.createObjectURL(blob)
234
328
  */
235
- resolve: (doc, node) => {
236
- const src = resolveSeq.resolveString(doc, node);
237
-
329
+ resolve(src, onError) {
238
330
  if (typeof Buffer === 'function') {
239
331
  return Buffer.from(src, 'base64');
240
332
  } else if (typeof atob === 'function') {
@@ -246,12 +338,12 @@ const binary = {
246
338
 
247
339
  return buffer;
248
340
  } else {
249
- const msg = 'This environment does not support reading binary tags; either Buffer or atob is required';
250
- doc.errors.push(new PlainValue.YAMLReferenceError(node, msg));
251
- return null;
341
+ onError('This environment does not support reading binary tags; either Buffer or atob is required');
342
+ return src;
252
343
  }
253
344
  },
254
- options: resolveSeq.binaryOptions,
345
+
346
+ options: stringifyNumber.binaryOptions,
255
347
  stringify: ({
256
348
  comment,
257
349
  type,
@@ -271,14 +363,14 @@ const binary = {
271
363
  throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');
272
364
  }
273
365
 
274
- if (!type) type = resolveSeq.binaryOptions.defaultType;
366
+ if (!type) type = stringifyNumber.binaryOptions.defaultType;
275
367
 
276
- if (type === PlainValue.Type.QUOTE_DOUBLE) {
368
+ if (type === _rollupPluginBabelHelpers.Type.QUOTE_DOUBLE) {
277
369
  value = src;
278
370
  } else {
279
371
  const {
280
372
  lineWidth
281
- } = resolveSeq.binaryOptions;
373
+ } = stringifyNumber.binaryOptions;
282
374
  const n = Math.ceil(src.length / lineWidth);
283
375
  const lines = new Array(n);
284
376
 
@@ -286,10 +378,10 @@ const binary = {
286
378
  lines[i] = src.substr(o, lineWidth);
287
379
  }
288
380
 
289
- value = lines.join(type === PlainValue.Type.BLOCK_LITERAL ? '\n' : ' ');
381
+ value = lines.join(type === _rollupPluginBabelHelpers.Type.BLOCK_LITERAL ? '\n' : ' ');
290
382
  }
291
383
 
292
- return resolveSeq.stringifyString({
384
+ return stringifyNumber.stringifyString({
293
385
  comment,
294
386
  type,
295
387
  value
@@ -297,32 +389,33 @@ const binary = {
297
389
  }
298
390
  };
299
391
 
300
- function parsePairs(doc, cst) {
301
- const seq = resolveSeq.resolveSeq(doc, cst);
302
-
303
- for (let i = 0; i < seq.items.length; ++i) {
304
- let item = seq.items[i];
305
- if (item instanceof resolveSeq.Pair) continue;else if (item instanceof resolveSeq.YAMLMap) {
306
- if (item.items.length > 1) {
307
- const msg = 'Each pair must have its own sequence indicator';
308
- throw new PlainValue.YAMLSemanticError(cst, msg);
392
+ function parsePairs(seq, onError) {
393
+ if (seq instanceof stringifyNumber.YAMLSeq) {
394
+ for (let i = 0; i < seq.items.length; ++i) {
395
+ let item = seq.items[i];
396
+ if (item instanceof stringifyNumber.Pair) continue;else if (item instanceof stringifyNumber.YAMLMap) {
397
+ if (item.items.length > 1) onError('Each pair must have its own sequence indicator');
398
+ const pair = item.items[0] || new stringifyNumber.Pair();
399
+ if (item.commentBefore) pair.commentBefore = pair.commentBefore ? `${item.commentBefore}\n${pair.commentBefore}` : item.commentBefore;
400
+ if (item.comment) pair.comment = pair.comment ? `${item.comment}\n${pair.comment}` : item.comment;
401
+ item = pair;
309
402
  }
310
-
311
- const pair = item.items[0] || new resolveSeq.Pair();
312
- if (item.commentBefore) pair.commentBefore = pair.commentBefore ? `${item.commentBefore}\n${pair.commentBefore}` : item.commentBefore;
313
- if (item.comment) pair.comment = pair.comment ? `${item.comment}\n${pair.comment}` : item.comment;
314
- item = pair;
403
+ seq.items[i] = item instanceof stringifyNumber.Pair ? item : new stringifyNumber.Pair(item);
315
404
  }
316
- seq.items[i] = item instanceof resolveSeq.Pair ? item : new resolveSeq.Pair(item);
317
- }
405
+ } else onError('Expected a sequence for this tag');
318
406
 
319
407
  return seq;
320
408
  }
321
409
  function createPairs(schema, iterable, ctx) {
322
- const pairs = new resolveSeq.YAMLSeq(schema);
410
+ const {
411
+ replacer
412
+ } = ctx;
413
+ const pairs = new stringifyNumber.YAMLSeq(schema);
323
414
  pairs.tag = 'tag:yaml.org,2002:pairs';
415
+ let i = 0;
324
416
 
325
- for (const it of iterable) {
417
+ for (let it of iterable) {
418
+ if (typeof replacer === 'function') it = replacer.call(iterable, String(i++), it);
326
419
  let key, value;
327
420
 
328
421
  if (Array.isArray(it)) {
@@ -341,7 +434,7 @@ function createPairs(schema, iterable, ctx) {
341
434
  key = it;
342
435
  }
343
436
 
344
- pairs.items.push(resolveSeq.createPair(key, value, ctx));
437
+ pairs.items.push(stringifyNumber.createPair(key, value, ctx));
345
438
  }
346
439
 
347
440
  return pairs;
@@ -353,19 +446,19 @@ const pairs = {
353
446
  createNode: createPairs
354
447
  };
355
448
 
356
- class YAMLOMap extends resolveSeq.YAMLSeq {
449
+ class YAMLOMap extends stringifyNumber.YAMLSeq {
357
450
  constructor() {
358
451
  super();
359
452
 
360
- PlainValue._defineProperty(this, "add", resolveSeq.YAMLMap.prototype.add.bind(this));
453
+ _rollupPluginBabelHelpers._defineProperty(this, "add", stringifyNumber.YAMLMap.prototype.add.bind(this));
361
454
 
362
- PlainValue._defineProperty(this, "delete", resolveSeq.YAMLMap.prototype.delete.bind(this));
455
+ _rollupPluginBabelHelpers._defineProperty(this, "delete", stringifyNumber.YAMLMap.prototype.delete.bind(this));
363
456
 
364
- PlainValue._defineProperty(this, "get", resolveSeq.YAMLMap.prototype.get.bind(this));
457
+ _rollupPluginBabelHelpers._defineProperty(this, "get", stringifyNumber.YAMLMap.prototype.get.bind(this));
365
458
 
366
- PlainValue._defineProperty(this, "has", resolveSeq.YAMLMap.prototype.has.bind(this));
459
+ _rollupPluginBabelHelpers._defineProperty(this, "has", stringifyNumber.YAMLMap.prototype.has.bind(this));
367
460
 
368
- PlainValue._defineProperty(this, "set", resolveSeq.YAMLMap.prototype.set.bind(this));
461
+ _rollupPluginBabelHelpers._defineProperty(this, "set", stringifyNumber.YAMLMap.prototype.set.bind(this));
369
462
 
370
463
  this.tag = YAMLOMap.tag;
371
464
  }
@@ -377,11 +470,11 @@ class YAMLOMap extends resolveSeq.YAMLSeq {
377
470
  for (const pair of this.items) {
378
471
  let key, value;
379
472
 
380
- if (pair instanceof resolveSeq.Pair) {
381
- key = resolveSeq.toJSON(pair.key, '', ctx);
382
- value = resolveSeq.toJSON(pair.value, key, ctx);
473
+ if (pair instanceof stringifyNumber.Pair) {
474
+ key = stringifyNumber.toJS(pair.key, '', ctx);
475
+ value = stringifyNumber.toJS(pair.value, key, ctx);
383
476
  } else {
384
- key = resolveSeq.toJSON(pair, '', ctx);
477
+ key = stringifyNumber.toJS(pair, '', ctx);
385
478
  }
386
479
 
387
480
  if (map.has(key)) throw new Error('Ordered maps must not include duplicate keys');
@@ -393,19 +486,18 @@ class YAMLOMap extends resolveSeq.YAMLSeq {
393
486
 
394
487
  }
395
488
 
396
- PlainValue._defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap');
489
+ _rollupPluginBabelHelpers._defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap');
397
490
 
398
- function parseOMap(doc, cst) {
399
- const pairs = parsePairs(doc, cst);
491
+ function parseOMap(seq, onError) {
492
+ const pairs = parsePairs(seq, onError);
400
493
  const seenKeys = [];
401
494
 
402
495
  for (const {
403
496
  key
404
497
  } of pairs.items) {
405
- if (key instanceof resolveSeq.Scalar) {
498
+ if (key instanceof stringifyNumber.Scalar) {
406
499
  if (seenKeys.includes(key.value)) {
407
- const msg = 'Ordered maps must not include duplicate keys';
408
- throw new PlainValue.YAMLSemanticError(cst, msg);
500
+ onError(`Ordered maps must not include duplicate keys: ${key.value}`);
409
501
  } else {
410
502
  seenKeys.push(key.value);
411
503
  }
@@ -431,31 +523,31 @@ const omap = {
431
523
  createNode: createOMap
432
524
  };
433
525
 
434
- class YAMLSet extends resolveSeq.YAMLMap {
435
- constructor() {
436
- super();
526
+ class YAMLSet extends stringifyNumber.YAMLMap {
527
+ constructor(schema) {
528
+ super(schema);
437
529
  this.tag = YAMLSet.tag;
438
530
  }
439
531
 
440
532
  add(key) {
441
- const pair = key instanceof resolveSeq.Pair ? key : new resolveSeq.Pair(key);
442
- const prev = resolveSeq.findPair(this.items, pair.key);
533
+ const pair = key instanceof stringifyNumber.Pair ? key : new stringifyNumber.Pair(key);
534
+ const prev = stringifyNumber.findPair(this.items, pair.key);
443
535
  if (!prev) this.items.push(pair);
444
536
  }
445
537
 
446
538
  get(key, keepPair) {
447
- const pair = resolveSeq.findPair(this.items, key);
448
- return !keepPair && pair instanceof resolveSeq.Pair ? pair.key instanceof resolveSeq.Scalar ? pair.key.value : pair.key : pair;
539
+ const pair = stringifyNumber.findPair(this.items, key);
540
+ return !keepPair && pair instanceof stringifyNumber.Pair ? pair.key instanceof stringifyNumber.Scalar ? pair.key.value : pair.key : pair;
449
541
  }
450
542
 
451
543
  set(key, value) {
452
544
  if (typeof value !== 'boolean') throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`);
453
- const prev = resolveSeq.findPair(this.items, key);
545
+ const prev = stringifyNumber.findPair(this.items, key);
454
546
 
455
547
  if (prev && !value) {
456
548
  this.items.splice(this.items.indexOf(prev), 1);
457
549
  } else if (!prev && value) {
458
- this.items.push(new resolveSeq.Pair(key));
550
+ this.items.push(new stringifyNumber.Pair(key));
459
551
  }
460
552
  }
461
553
 
@@ -470,18 +562,26 @@ class YAMLSet extends resolveSeq.YAMLMap {
470
562
 
471
563
  }
472
564
 
473
- PlainValue._defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set');
565
+ _rollupPluginBabelHelpers._defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set');
474
566
 
475
- function parseSet(doc, cst) {
476
- const map = resolveSeq.resolveMap(doc, cst);
477
- if (!map.hasAllNullValues()) throw new PlainValue.YAMLSemanticError(cst, 'Set items must all have null values');
478
- return Object.assign(new YAMLSet(), map);
567
+ function parseSet(map, onError) {
568
+ if (map instanceof stringifyNumber.YAMLMap) {
569
+ if (map.hasAllNullValues()) return Object.assign(new YAMLSet(), map);else onError('Set items must all have null values');
570
+ } else onError('Expected a mapping for this tag');
571
+
572
+ return map;
479
573
  }
480
574
 
481
575
  function createSet(schema, iterable, ctx) {
482
- const set = new YAMLSet();
576
+ const {
577
+ replacer
578
+ } = ctx;
579
+ const set = new YAMLSet(schema);
483
580
 
484
- for (const value of iterable) set.items.push(resolveSeq.createPair(value, null, ctx));
581
+ for (let value of iterable) {
582
+ if (typeof replacer === 'function') value = replacer.call(iterable, value, value);
583
+ set.items.push(stringifyNumber.createPair(value, null, ctx));
584
+ }
485
585
 
486
586
  return set;
487
587
  }
@@ -495,33 +595,44 @@ const set = {
495
595
  createNode: createSet
496
596
  };
497
597
 
498
- const parseSexagesimal = (sign, parts) => {
499
- const n = parts.split(':').reduce((n, p) => n * 60 + Number(p), 0);
500
- return sign === '-' ? -n : n;
598
+ /* global BigInt */
599
+
600
+ const parseSexagesimal = (str, isInt) => {
601
+ const sign = str[0];
602
+ const parts = sign === '-' || sign === '+' ? str.substring(1) : str;
603
+
604
+ const num = n => isInt && stringifyNumber.intOptions.asBigInt ? BigInt(n) : Number(n);
605
+
606
+ const res = parts.replace(/_/g, '').split(':').reduce((res, p) => res * num(60) + num(p), num(0));
607
+ return sign === '-' ? num(-1) * res : res;
501
608
  }; // hhhh:mm:ss.sss
502
609
 
503
610
 
504
611
  const stringifySexagesimal = ({
505
612
  value
506
613
  }) => {
507
- if (isNaN(value) || !isFinite(value)) return resolveSeq.stringifyNumber(value);
614
+ let num = n => n;
615
+
616
+ if (typeof value === 'bigint') num = n => BigInt(n);else if (isNaN(value) || !isFinite(value)) return stringifyNumber.stringifyNumber(value);
508
617
  let sign = '';
509
618
 
510
619
  if (value < 0) {
511
620
  sign = '-';
512
- value = Math.abs(value);
621
+ value *= num(-1);
513
622
  }
514
623
 
515
- const parts = [value % 60]; // seconds, including ms
624
+ const _60 = num(60);
625
+
626
+ const parts = [value % _60]; // seconds, including ms
516
627
 
517
628
  if (value < 60) {
518
629
  parts.unshift(0); // at least one : is required
519
630
  } else {
520
- value = Math.round((value - parts[0]) / 60);
521
- parts.unshift(value % 60); // minutes
631
+ value = (value - parts[0]) / _60;
632
+ parts.unshift(value % _60); // minutes
522
633
 
523
634
  if (value >= 60) {
524
- value = Math.round((value - parts[0]) / 60);
635
+ value = (value - parts[0]) / _60;
525
636
  parts.unshift(value); // hours
526
637
  }
527
638
  }
@@ -531,12 +642,12 @@ const stringifySexagesimal = ({
531
642
  };
532
643
 
533
644
  const intTime = {
534
- identify: value => typeof value === 'number',
645
+ identify: value => typeof value === 'bigint' || Number.isInteger(value),
535
646
  default: true,
536
647
  tag: 'tag:yaml.org,2002:int',
537
648
  format: 'TIME',
538
- test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+)$/,
539
- resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')),
649
+ test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,
650
+ resolve: str => parseSexagesimal(str, true),
540
651
  stringify: stringifySexagesimal
541
652
  };
542
653
  const floatTime = {
@@ -544,8 +655,8 @@ const floatTime = {
544
655
  default: true,
545
656
  tag: 'tag:yaml.org,2002:float',
546
657
  format: 'TIME',
547
- test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*)$/,
548
- resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')),
658
+ test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,
659
+ resolve: str => parseSexagesimal(str, false),
549
660
  stringify: stringifySexagesimal
550
661
  };
551
662
  const timestamp = {
@@ -555,23 +666,27 @@ const timestamp = {
555
666
  // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
556
667
  // may be omitted altogether, resulting in a date format. In such a case, the time part is
557
668
  // assumed to be 00:00:00Z (start of day, UTC).
558
- test: RegExp('^(?:' + '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd
559
- '(?:(?:t|T|[ \\t]+)' + // t | T | whitespace
669
+ test: RegExp('^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd
670
+ '(?:' + // time is optional
671
+ '(?:t|T|[ \\t]+)' + // t | T | whitespace
560
672
  '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)?
561
673
  '(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30
562
- ')?' + ')$'),
563
- resolve: (str, year, month, day, hour, minute, second, millisec, tz) => {
674
+ ')?$'),
675
+
676
+ resolve(str) {
677
+ let [, year, month, day, hour, minute, second, millisec, tz] = str.match(timestamp.test);
564
678
  if (millisec) millisec = (millisec + '00').substr(1, 3);
565
679
  let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0);
566
680
 
567
681
  if (tz && tz !== 'Z') {
568
- let d = parseSexagesimal(tz[0], tz.slice(1));
682
+ let d = parseSexagesimal(tz, false);
569
683
  if (Math.abs(d) < 30) d *= 60;
570
684
  date -= 60000 * d;
571
685
  }
572
686
 
573
687
  return new Date(date);
574
688
  },
689
+
575
690
  stringify: ({
576
691
  value
577
692
  }) => value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '')
@@ -581,14 +696,16 @@ const timestamp = {
581
696
 
582
697
  const boolStringify = ({
583
698
  value
584
- }) => value ? resolveSeq.boolOptions.trueStr : resolveSeq.boolOptions.falseStr;
699
+ }) => value ? stringifyNumber.boolOptions.trueStr : stringifyNumber.boolOptions.falseStr;
585
700
 
586
701
  const intIdentify$2 = value => typeof value === 'bigint' || Number.isInteger(value);
587
702
 
588
- function intResolve$1(sign, src, radix) {
589
- let str = src.replace(/_/g, '');
703
+ function intResolve$1(str, offset, radix) {
704
+ const sign = str[0];
705
+ if (sign === '-' || sign === '+') offset += 1;
706
+ str = str.substring(offset).replace(/_/g, '');
590
707
 
591
- if (resolveSeq.intOptions.asBigInt) {
708
+ if (stringifyNumber.intOptions.asBigInt) {
592
709
  switch (radix) {
593
710
  case 2:
594
711
  str = `0b${str}`;
@@ -621,78 +738,84 @@ function intStringify$1(node, radix, prefix) {
621
738
  return value < 0 ? '-' + prefix + str.substr(1) : prefix + str;
622
739
  }
623
740
 
624
- return resolveSeq.stringifyNumber(node);
741
+ return stringifyNumber.stringifyNumber(node);
625
742
  }
626
743
 
627
744
  const yaml11 = failsafe.concat([{
628
745
  identify: value => value == null,
629
- createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq.Scalar(null) : null,
746
+ createNode: (schema, value, ctx) => ctx.wrapScalars ? new stringifyNumber.Scalar(null) : null,
630
747
  default: true,
631
748
  tag: 'tag:yaml.org,2002:null',
632
749
  test: /^(?:~|[Nn]ull|NULL)?$/,
633
- resolve: () => null,
634
- options: resolveSeq.nullOptions,
635
- stringify: () => resolveSeq.nullOptions.nullStr
750
+ resolve: str => {
751
+ const node = new stringifyNumber.Scalar(null);
752
+ node.sourceStr = str;
753
+ return node;
754
+ },
755
+ options: stringifyNumber.nullOptions,
756
+ stringify: ({
757
+ sourceStr
758
+ }) => sourceStr !== null && sourceStr !== void 0 ? sourceStr : stringifyNumber.nullOptions.nullStr
636
759
  }, {
637
760
  identify: value => typeof value === 'boolean',
638
761
  default: true,
639
762
  tag: 'tag:yaml.org,2002:bool',
640
763
  test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
641
764
  resolve: () => true,
642
- options: resolveSeq.boolOptions,
765
+ options: stringifyNumber.boolOptions,
643
766
  stringify: boolStringify
644
767
  }, {
645
768
  identify: value => typeof value === 'boolean',
646
769
  default: true,
647
770
  tag: 'tag:yaml.org,2002:bool',
648
- test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
771
+ test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
649
772
  resolve: () => false,
650
- options: resolveSeq.boolOptions,
773
+ options: stringifyNumber.boolOptions,
651
774
  stringify: boolStringify
652
775
  }, {
653
776
  identify: intIdentify$2,
654
777
  default: true,
655
778
  tag: 'tag:yaml.org,2002:int',
656
779
  format: 'BIN',
657
- test: /^([-+]?)0b([0-1_]+)$/,
658
- resolve: (str, sign, bin) => intResolve$1(sign, bin, 2),
780
+ test: /^[-+]?0b[0-1_]+$/,
781
+ resolve: str => intResolve$1(str, 2, 2),
659
782
  stringify: node => intStringify$1(node, 2, '0b')
660
783
  }, {
661
784
  identify: intIdentify$2,
662
785
  default: true,
663
786
  tag: 'tag:yaml.org,2002:int',
664
787
  format: 'OCT',
665
- test: /^([-+]?)0([0-7_]+)$/,
666
- resolve: (str, sign, oct) => intResolve$1(sign, oct, 8),
788
+ test: /^[-+]?0[0-7_]+$/,
789
+ resolve: str => intResolve$1(str, 1, 8),
667
790
  stringify: node => intStringify$1(node, 8, '0')
668
791
  }, {
669
792
  identify: intIdentify$2,
670
793
  default: true,
671
794
  tag: 'tag:yaml.org,2002:int',
672
- test: /^([-+]?)([0-9][0-9_]*)$/,
673
- resolve: (str, sign, abs) => intResolve$1(sign, abs, 10),
674
- stringify: resolveSeq.stringifyNumber
795
+ test: /^[-+]?[0-9][0-9_]*$/,
796
+ resolve: str => intResolve$1(str, 0, 10),
797
+ stringify: stringifyNumber.stringifyNumber
675
798
  }, {
676
799
  identify: intIdentify$2,
677
800
  default: true,
678
801
  tag: 'tag:yaml.org,2002:int',
679
802
  format: 'HEX',
680
- test: /^([-+]?)0x([0-9a-fA-F_]+)$/,
681
- resolve: (str, sign, hex) => intResolve$1(sign, hex, 16),
803
+ test: /^[-+]?0x[0-9a-fA-F_]+$/,
804
+ resolve: str => intResolve$1(str, 2, 16),
682
805
  stringify: node => intStringify$1(node, 16, '0x')
683
806
  }, {
684
807
  identify: value => typeof value === 'number',
685
808
  default: true,
686
809
  tag: 'tag:yaml.org,2002:float',
687
- test: /^(?:[-+]?\.inf|(\.nan))$/i,
688
- resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
689
- stringify: resolveSeq.stringifyNumber
810
+ test: /^[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/,
811
+ resolve: str => str.slice(-3).toLowerCase() === 'nan' ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
812
+ stringify: stringifyNumber.stringifyNumber
690
813
  }, {
691
814
  identify: value => typeof value === 'number',
692
815
  default: true,
693
816
  tag: 'tag:yaml.org,2002:float',
694
817
  format: 'EXP',
695
- test: /^[-+]?([0-9][0-9_]*)?(\.[0-9_]*)?[eE][-+]?[0-9]+$/,
818
+ test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
696
819
  resolve: str => parseFloat(str.replace(/_/g, '')),
697
820
  stringify: ({
698
821
  value
@@ -701,20 +824,21 @@ const yaml11 = failsafe.concat([{
701
824
  identify: value => typeof value === 'number',
702
825
  default: true,
703
826
  tag: 'tag:yaml.org,2002:float',
704
- test: /^[-+]?(?:[0-9][0-9_]*)?\.([0-9_]*)$/,
827
+ test: /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,
705
828
 
706
- resolve(str, frac) {
707
- const node = new resolveSeq.Scalar(parseFloat(str.replace(/_/g, '')));
829
+ resolve(str) {
830
+ const node = new stringifyNumber.Scalar(parseFloat(str.replace(/_/g, '')));
831
+ const dot = str.indexOf('.');
708
832
 
709
- if (frac) {
710
- const f = frac.replace(/_/g, '');
833
+ if (dot !== -1) {
834
+ const f = str.substring(dot + 1).replace(/_/g, '');
711
835
  if (f[f.length - 1] === '0') node.minFractionDigits = f.length;
712
836
  }
713
837
 
714
838
  return node;
715
839
  },
716
840
 
717
- stringify: resolveSeq.stringifyNumber
841
+ stringify: stringifyNumber.stringifyNumber
718
842
  }], binary, omap, pairs, set, intTime, floatTime, timestamp);
719
843
 
720
844
  const schemas = {
@@ -805,4 +929,6 @@ class Schema {
805
929
 
806
930
  }
807
931
 
932
+ exports.MERGE_KEY = MERGE_KEY;
933
+ exports.Merge = Merge;
808
934
  exports.Schema = Schema;