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.
- package/README.md +8 -9
- package/browser/dist/{Schema-d14032c2.js → Schema-ea978338.js} +291 -127
- package/browser/dist/{PlainValue-6b68dc0e.js → errors-2634d01a.js} +1 -181
- package/browser/dist/index.js +1085 -73
- package/browser/dist/parse-cst.js +2 -2
- package/browser/dist/{parse-6e806192.js → parse-d1ba890f.js} +182 -2
- package/browser/dist/{resolveSeq-3477c430.js → stringifyNumber-d8af95b1.js} +89 -1069
- package/browser/dist/types.js +3 -3
- package/browser/dist/util.js +2 -2
- package/browser/index.js +1 -1
- package/dist/Document-f89a2614.js +1783 -0
- package/dist/{Schema-fe1471c4.js → Schema-807430ba.js} +289 -163
- package/dist/{PlainValue-ec8e588e.js → _rollupPluginBabelHelpers-eed30217.js} +0 -167
- package/dist/index.js +43 -33
- package/dist/{parse-ab8de154.js → parse-3997f544.js} +313 -146
- package/dist/parse-cst.js +2 -2
- package/dist/{resolveSeq-6b2dc4ac.js → stringifyNumber-dea1120c.js} +107 -1038
- package/dist/test-events.js +5 -5
- package/dist/types.js +16 -16
- package/dist/util.js +12 -14
- package/index.d.ts +67 -23
- package/index.js +1 -1
- package/package.json +12 -12
- package/types.d.ts +9 -9
- package/util.d.ts +2 -12
- package/util.js +0 -2
- package/util.mjs +0 -3
- package/dist/Document-59bd9290.js +0 -803
|
@@ -1,18 +1,89 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
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
|
|
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)
|
|
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:
|
|
99
|
+
nodeClass: stringifyNumber.YAMLMap,
|
|
29
100
|
tag: 'tag:yaml.org,2002:map',
|
|
30
|
-
resolve:
|
|
101
|
+
resolve: map => map
|
|
31
102
|
};
|
|
32
103
|
|
|
33
104
|
function createSeq(schema, obj, ctx) {
|
|
34
|
-
const
|
|
105
|
+
const {
|
|
106
|
+
replacer
|
|
107
|
+
} = ctx;
|
|
108
|
+
const seq = new stringifyNumber.YAMLSeq(schema);
|
|
35
109
|
|
|
36
110
|
if (obj && obj[Symbol.iterator]) {
|
|
37
|
-
|
|
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:
|
|
129
|
+
nodeClass: stringifyNumber.YAMLSeq,
|
|
47
130
|
tag: 'tag:yaml.org,2002:seq',
|
|
48
|
-
resolve:
|
|
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:
|
|
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
|
|
144
|
+
return stringifyNumber.stringifyString(item, ctx, onComment, onChompKeep);
|
|
62
145
|
},
|
|
63
146
|
|
|
64
|
-
options:
|
|
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,
|
|
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
|
|
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
|
|
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:
|
|
90
|
-
|
|
91
|
-
|
|
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:
|
|
188
|
+
options: stringifyNumber.boolOptions,
|
|
100
189
|
stringify: ({
|
|
101
190
|
value
|
|
102
|
-
}) => value ?
|
|
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
|
|
110
|
-
resolve:
|
|
111
|
-
options:
|
|
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,
|
|
120
|
-
options:
|
|
121
|
-
stringify:
|
|
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
|
|
129
|
-
resolve:
|
|
130
|
-
options:
|
|
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|
|
|
138
|
-
resolve:
|
|
139
|
-
stringify:
|
|
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: /^[-+]?(?:\.
|
|
245
|
+
test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
|
|
157
246
|
|
|
158
|
-
resolve(str
|
|
159
|
-
const
|
|
160
|
-
const
|
|
161
|
-
if (
|
|
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:
|
|
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:
|
|
270
|
+
resolve: str => str,
|
|
182
271
|
stringify: stringifyJSON
|
|
183
272
|
}, {
|
|
184
273
|
identify: value => value == null,
|
|
185
|
-
createNode: (schema, value, ctx) => ctx.wrapScalars ? new
|
|
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 =>
|
|
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
|
-
|
|
217
|
-
|
|
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
|
|
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
|
-
|
|
250
|
-
|
|
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
|
-
|
|
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 =
|
|
366
|
+
if (!type) type = stringifyNumber.binaryOptions.defaultType;
|
|
275
367
|
|
|
276
|
-
if (type ===
|
|
368
|
+
if (type === _rollupPluginBabelHelpers.Type.QUOTE_DOUBLE) {
|
|
277
369
|
value = src;
|
|
278
370
|
} else {
|
|
279
371
|
const {
|
|
280
372
|
lineWidth
|
|
281
|
-
} =
|
|
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 ===
|
|
381
|
+
value = lines.join(type === _rollupPluginBabelHelpers.Type.BLOCK_LITERAL ? '\n' : ' ');
|
|
290
382
|
}
|
|
291
383
|
|
|
292
|
-
return
|
|
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(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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
|
-
|
|
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
|
|
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 (
|
|
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(
|
|
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
|
|
449
|
+
class YAMLOMap extends stringifyNumber.YAMLSeq {
|
|
357
450
|
constructor() {
|
|
358
451
|
super();
|
|
359
452
|
|
|
360
|
-
|
|
453
|
+
_rollupPluginBabelHelpers._defineProperty(this, "add", stringifyNumber.YAMLMap.prototype.add.bind(this));
|
|
361
454
|
|
|
362
|
-
|
|
455
|
+
_rollupPluginBabelHelpers._defineProperty(this, "delete", stringifyNumber.YAMLMap.prototype.delete.bind(this));
|
|
363
456
|
|
|
364
|
-
|
|
457
|
+
_rollupPluginBabelHelpers._defineProperty(this, "get", stringifyNumber.YAMLMap.prototype.get.bind(this));
|
|
365
458
|
|
|
366
|
-
|
|
459
|
+
_rollupPluginBabelHelpers._defineProperty(this, "has", stringifyNumber.YAMLMap.prototype.has.bind(this));
|
|
367
460
|
|
|
368
|
-
|
|
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
|
|
381
|
-
key =
|
|
382
|
-
value =
|
|
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 =
|
|
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
|
-
|
|
489
|
+
_rollupPluginBabelHelpers._defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap');
|
|
397
490
|
|
|
398
|
-
function parseOMap(
|
|
399
|
-
const pairs = parsePairs(
|
|
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
|
|
498
|
+
if (key instanceof stringifyNumber.Scalar) {
|
|
406
499
|
if (seenKeys.includes(key.value)) {
|
|
407
|
-
|
|
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
|
|
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
|
|
442
|
-
const prev =
|
|
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 =
|
|
448
|
-
return !keepPair && pair instanceof
|
|
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 =
|
|
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
|
|
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
|
-
|
|
565
|
+
_rollupPluginBabelHelpers._defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set');
|
|
474
566
|
|
|
475
|
-
function parseSet(
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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
|
|
576
|
+
const {
|
|
577
|
+
replacer
|
|
578
|
+
} = ctx;
|
|
579
|
+
const set = new YAMLSet(schema);
|
|
483
580
|
|
|
484
|
-
for (
|
|
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
|
-
|
|
499
|
-
|
|
500
|
-
|
|
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
|
-
|
|
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
|
|
621
|
+
value *= num(-1);
|
|
513
622
|
}
|
|
514
623
|
|
|
515
|
-
const
|
|
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 =
|
|
521
|
-
parts.unshift(value %
|
|
631
|
+
value = (value - parts[0]) / _60;
|
|
632
|
+
parts.unshift(value % _60); // minutes
|
|
522
633
|
|
|
523
634
|
if (value >= 60) {
|
|
524
|
-
value =
|
|
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 === '
|
|
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: /^
|
|
539
|
-
resolve:
|
|
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: /^
|
|
548
|
-
resolve:
|
|
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('^(
|
|
559
|
-
'(?:
|
|
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
|
-
|
|
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
|
|
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 ?
|
|
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(
|
|
589
|
-
|
|
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 (
|
|
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
|
|
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
|
|
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:
|
|
634
|
-
|
|
635
|
-
|
|
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:
|
|
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)
|
|
771
|
+
test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
|
|
649
772
|
resolve: () => false,
|
|
650
|
-
options:
|
|
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: /^
|
|
658
|
-
resolve:
|
|
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: /^
|
|
666
|
-
resolve:
|
|
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: /^
|
|
673
|
-
resolve:
|
|
674
|
-
stringify:
|
|
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: /^
|
|
681
|
-
resolve:
|
|
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: /^
|
|
688
|
-
resolve:
|
|
689
|
-
stringify:
|
|
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_]*)?(
|
|
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_]*)?\.
|
|
827
|
+
test: /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,
|
|
705
828
|
|
|
706
|
-
resolve(str
|
|
707
|
-
const node = new
|
|
829
|
+
resolve(str) {
|
|
830
|
+
const node = new stringifyNumber.Scalar(parseFloat(str.replace(/_/g, '')));
|
|
831
|
+
const dot = str.indexOf('.');
|
|
708
832
|
|
|
709
|
-
if (
|
|
710
|
-
const f =
|
|
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:
|
|
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;
|