yaml 1.10.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 +10 -11
- package/browser/dist/Schema-ea978338.js +1211 -0
- package/browser/dist/{PlainValue-ff5147c6.js → errors-2634d01a.js} +8 -186
- package/browser/dist/index.js +1174 -121
- package/browser/dist/parse-cst.js +2 -1904
- package/browser/dist/parse-d1ba890f.js +2084 -0
- package/browser/dist/{resolveSeq-04825f30.js → stringifyNumber-d8af95b1.js} +197 -1072
- package/browser/dist/types.js +3 -4
- package/browser/dist/util.js +2 -2
- package/browser/index.js +1 -1
- package/dist/Document-f89a2614.js +1783 -0
- package/dist/Schema-807430ba.js +934 -0
- package/dist/{PlainValue-ec8e588e.js → _rollupPluginBabelHelpers-eed30217.js} +0 -167
- package/dist/index.js +58 -44
- package/dist/parse-3997f544.js +1915 -0
- package/dist/parse-cst.js +3 -1742
- package/dist/stringifyNumber-dea1120c.js +1286 -0
- package/dist/test-events.js +6 -7
- package/dist/types.js +16 -17
- package/dist/util.js +12 -14
- package/index.d.ts +103 -20
- package/index.js +1 -1
- package/package.json +16 -26
- package/types.d.ts +19 -47
- package/util.d.ts +2 -12
- package/util.js +0 -2
- package/util.mjs +0 -3
- package/browser/dist/Schema-2bf2c74e.js +0 -679
- package/browser/dist/legacy-exports.js +0 -3
- package/browser/dist/warnings-0e4b70d3.js +0 -499
- package/browser/map.js +0 -2
- package/browser/pair.js +0 -2
- package/browser/scalar.js +0 -2
- package/browser/schema.js +0 -9
- package/browser/seq.js +0 -2
- package/browser/types/binary.js +0 -8
- package/browser/types/omap.js +0 -3
- package/browser/types/pairs.js +0 -3
- package/browser/types/set.js +0 -3
- package/browser/types/timestamp.js +0 -10
- package/dist/Document-2cf6b08c.js +0 -757
- package/dist/Schema-42e9705c.js +0 -522
- package/dist/legacy-exports.js +0 -16
- package/dist/resolveSeq-4a68b39b.js +0 -2115
- package/dist/warnings-39684f17.js +0 -416
- package/map.js +0 -2
- package/pair.js +0 -2
- package/scalar.js +0 -2
- package/schema.js +0 -9
- package/seq.js +0 -2
- package/types/binary.js +0 -8
- package/types/omap.js +0 -3
- package/types/pairs.js +0 -3
- package/types/set.js +0 -3
- package/types/timestamp.js +0 -10
|
@@ -0,0 +1,934 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
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
|
+
}
|
|
70
|
+
|
|
71
|
+
function createMap(schema, obj, ctx) {
|
|
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
|
+
};
|
|
82
|
+
|
|
83
|
+
if (obj instanceof Map) {
|
|
84
|
+
for (const [key, value] of obj) add(key, value);
|
|
85
|
+
} else if (obj && typeof obj === 'object') {
|
|
86
|
+
for (const key of Object.keys(obj)) add(key, obj[key]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (typeof schema.sortMapEntries === 'function') {
|
|
90
|
+
map.items.sort(schema.sortMapEntries);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return map;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const map = {
|
|
97
|
+
createNode: createMap,
|
|
98
|
+
default: true,
|
|
99
|
+
nodeClass: stringifyNumber.YAMLMap,
|
|
100
|
+
tag: 'tag:yaml.org,2002:map',
|
|
101
|
+
resolve: map => map
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
function createSeq(schema, obj, ctx) {
|
|
105
|
+
const {
|
|
106
|
+
replacer
|
|
107
|
+
} = ctx;
|
|
108
|
+
const seq = new stringifyNumber.YAMLSeq(schema);
|
|
109
|
+
|
|
110
|
+
if (obj && obj[Symbol.iterator]) {
|
|
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
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return seq;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const seq = {
|
|
127
|
+
createNode: createSeq,
|
|
128
|
+
default: true,
|
|
129
|
+
nodeClass: stringifyNumber.YAMLSeq,
|
|
130
|
+
tag: 'tag:yaml.org,2002:seq',
|
|
131
|
+
resolve: seq => seq
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const string = {
|
|
135
|
+
identify: value => typeof value === 'string',
|
|
136
|
+
default: true,
|
|
137
|
+
tag: 'tag:yaml.org,2002:str',
|
|
138
|
+
resolve: str => str,
|
|
139
|
+
|
|
140
|
+
stringify(item, ctx, onComment, onChompKeep) {
|
|
141
|
+
ctx = Object.assign({
|
|
142
|
+
actualString: true
|
|
143
|
+
}, ctx);
|
|
144
|
+
return stringifyNumber.stringifyString(item, ctx, onComment, onChompKeep);
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
options: stringifyNumber.strOptions
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const failsafe = [map, seq, string];
|
|
151
|
+
|
|
152
|
+
/* global BigInt */
|
|
153
|
+
|
|
154
|
+
const intIdentify = value => typeof value === 'bigint' || Number.isInteger(value);
|
|
155
|
+
|
|
156
|
+
const intResolve = (src, offset, radix) => stringifyNumber.intOptions.asBigInt ? BigInt(src) : parseInt(src.substring(offset), radix);
|
|
157
|
+
|
|
158
|
+
function intStringify(node, radix, prefix) {
|
|
159
|
+
const {
|
|
160
|
+
value
|
|
161
|
+
} = node;
|
|
162
|
+
if (intIdentify(value) && value >= 0) return prefix + value.toString(radix);
|
|
163
|
+
return stringifyNumber.stringifyNumber(node);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const nullObj = {
|
|
167
|
+
identify: value => value == null,
|
|
168
|
+
createNode: (schema, value, ctx) => ctx.wrapScalars ? new stringifyNumber.Scalar(null) : null,
|
|
169
|
+
default: true,
|
|
170
|
+
tag: 'tag:yaml.org,2002:null',
|
|
171
|
+
test: /^(?:~|[Nn]ull|NULL)?$/,
|
|
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
|
|
181
|
+
};
|
|
182
|
+
const boolObj = {
|
|
183
|
+
identify: value => typeof value === 'boolean',
|
|
184
|
+
default: true,
|
|
185
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
186
|
+
test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
|
|
187
|
+
resolve: str => str[0] === 't' || str[0] === 'T',
|
|
188
|
+
options: stringifyNumber.boolOptions,
|
|
189
|
+
stringify: ({
|
|
190
|
+
value
|
|
191
|
+
}) => value ? stringifyNumber.boolOptions.trueStr : stringifyNumber.boolOptions.falseStr
|
|
192
|
+
};
|
|
193
|
+
const octObj = {
|
|
194
|
+
identify: value => intIdentify(value) && value >= 0,
|
|
195
|
+
default: true,
|
|
196
|
+
tag: 'tag:yaml.org,2002:int',
|
|
197
|
+
format: 'OCT',
|
|
198
|
+
test: /^0o[0-7]+$/,
|
|
199
|
+
resolve: str => intResolve(str, 2, 8),
|
|
200
|
+
options: stringifyNumber.intOptions,
|
|
201
|
+
stringify: node => intStringify(node, 8, '0o')
|
|
202
|
+
};
|
|
203
|
+
const intObj = {
|
|
204
|
+
identify: intIdentify,
|
|
205
|
+
default: true,
|
|
206
|
+
tag: 'tag:yaml.org,2002:int',
|
|
207
|
+
test: /^[-+]?[0-9]+$/,
|
|
208
|
+
resolve: str => intResolve(str, 0, 10),
|
|
209
|
+
options: stringifyNumber.intOptions,
|
|
210
|
+
stringify: stringifyNumber.stringifyNumber
|
|
211
|
+
};
|
|
212
|
+
const hexObj = {
|
|
213
|
+
identify: value => intIdentify(value) && value >= 0,
|
|
214
|
+
default: true,
|
|
215
|
+
tag: 'tag:yaml.org,2002:int',
|
|
216
|
+
format: 'HEX',
|
|
217
|
+
test: /^0x[0-9a-fA-F]+$/,
|
|
218
|
+
resolve: str => intResolve(str, 2, 16),
|
|
219
|
+
options: stringifyNumber.intOptions,
|
|
220
|
+
stringify: node => intStringify(node, 16, '0x')
|
|
221
|
+
};
|
|
222
|
+
const nanObj = {
|
|
223
|
+
identify: value => typeof value === 'number',
|
|
224
|
+
default: true,
|
|
225
|
+
tag: 'tag:yaml.org,2002:float',
|
|
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
|
|
229
|
+
};
|
|
230
|
+
const expObj = {
|
|
231
|
+
identify: value => typeof value === 'number',
|
|
232
|
+
default: true,
|
|
233
|
+
tag: 'tag:yaml.org,2002:float',
|
|
234
|
+
format: 'EXP',
|
|
235
|
+
test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
|
|
236
|
+
resolve: str => parseFloat(str),
|
|
237
|
+
stringify: ({
|
|
238
|
+
value
|
|
239
|
+
}) => Number(value).toExponential()
|
|
240
|
+
};
|
|
241
|
+
const floatObj = {
|
|
242
|
+
identify: value => typeof value === 'number',
|
|
243
|
+
default: true,
|
|
244
|
+
tag: 'tag:yaml.org,2002:float',
|
|
245
|
+
test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
|
|
246
|
+
|
|
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;
|
|
251
|
+
return node;
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
stringify: stringifyNumber.stringifyNumber
|
|
255
|
+
};
|
|
256
|
+
const core = failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
|
|
257
|
+
|
|
258
|
+
/* global BigInt */
|
|
259
|
+
|
|
260
|
+
const intIdentify$1 = value => typeof value === 'bigint' || Number.isInteger(value);
|
|
261
|
+
|
|
262
|
+
const stringifyJSON = ({
|
|
263
|
+
value
|
|
264
|
+
}) => JSON.stringify(value);
|
|
265
|
+
|
|
266
|
+
const json = [map, seq, {
|
|
267
|
+
identify: value => typeof value === 'string',
|
|
268
|
+
default: true,
|
|
269
|
+
tag: 'tag:yaml.org,2002:str',
|
|
270
|
+
resolve: str => str,
|
|
271
|
+
stringify: stringifyJSON
|
|
272
|
+
}, {
|
|
273
|
+
identify: value => value == null,
|
|
274
|
+
createNode: (schema, value, ctx) => ctx.wrapScalars ? new stringifyNumber.Scalar(null) : null,
|
|
275
|
+
default: true,
|
|
276
|
+
tag: 'tag:yaml.org,2002:null',
|
|
277
|
+
test: /^null$/,
|
|
278
|
+
resolve: () => null,
|
|
279
|
+
stringify: stringifyJSON
|
|
280
|
+
}, {
|
|
281
|
+
identify: value => typeof value === 'boolean',
|
|
282
|
+
default: true,
|
|
283
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
284
|
+
test: /^true|false$/,
|
|
285
|
+
resolve: str => str === 'true',
|
|
286
|
+
stringify: stringifyJSON
|
|
287
|
+
}, {
|
|
288
|
+
identify: intIdentify$1,
|
|
289
|
+
default: true,
|
|
290
|
+
tag: 'tag:yaml.org,2002:int',
|
|
291
|
+
test: /^-?(?:0|[1-9][0-9]*)$/,
|
|
292
|
+
resolve: str => stringifyNumber.intOptions.asBigInt ? BigInt(str) : parseInt(str, 10),
|
|
293
|
+
stringify: ({
|
|
294
|
+
value
|
|
295
|
+
}) => intIdentify$1(value) ? value.toString() : JSON.stringify(value)
|
|
296
|
+
}, {
|
|
297
|
+
identify: value => typeof value === 'number',
|
|
298
|
+
default: true,
|
|
299
|
+
tag: 'tag:yaml.org,2002:float',
|
|
300
|
+
test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
|
|
301
|
+
resolve: str => parseFloat(str),
|
|
302
|
+
stringify: stringifyJSON
|
|
303
|
+
}, {
|
|
304
|
+
default: true,
|
|
305
|
+
test: /^/,
|
|
306
|
+
|
|
307
|
+
resolve(str, onError) {
|
|
308
|
+
onError(`Unresolved plain scalar ${JSON.stringify(str)}`);
|
|
309
|
+
return str;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
}];
|
|
313
|
+
|
|
314
|
+
/* global atob, btoa, Buffer */
|
|
315
|
+
const binary = {
|
|
316
|
+
identify: value => value instanceof Uint8Array,
|
|
317
|
+
// Buffer inherits from Uint8Array
|
|
318
|
+
default: false,
|
|
319
|
+
tag: 'tag:yaml.org,2002:binary',
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Returns a Buffer in node and an Uint8Array in browsers
|
|
323
|
+
*
|
|
324
|
+
* To use the resulting buffer as an image, you'll want to do something like:
|
|
325
|
+
*
|
|
326
|
+
* const blob = new Blob([buffer], { type: 'image/jpeg' })
|
|
327
|
+
* document.querySelector('#photo').src = URL.createObjectURL(blob)
|
|
328
|
+
*/
|
|
329
|
+
resolve(src, onError) {
|
|
330
|
+
if (typeof Buffer === 'function') {
|
|
331
|
+
return Buffer.from(src, 'base64');
|
|
332
|
+
} else if (typeof atob === 'function') {
|
|
333
|
+
// On IE 11, atob() can't handle newlines
|
|
334
|
+
const str = atob(src.replace(/[\n\r]/g, ''));
|
|
335
|
+
const buffer = new Uint8Array(str.length);
|
|
336
|
+
|
|
337
|
+
for (let i = 0; i < str.length; ++i) buffer[i] = str.charCodeAt(i);
|
|
338
|
+
|
|
339
|
+
return buffer;
|
|
340
|
+
} else {
|
|
341
|
+
onError('This environment does not support reading binary tags; either Buffer or atob is required');
|
|
342
|
+
return src;
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
options: stringifyNumber.binaryOptions,
|
|
347
|
+
stringify: ({
|
|
348
|
+
comment,
|
|
349
|
+
type,
|
|
350
|
+
value
|
|
351
|
+
}, ctx, onComment, onChompKeep) => {
|
|
352
|
+
let src;
|
|
353
|
+
|
|
354
|
+
if (typeof Buffer === 'function') {
|
|
355
|
+
src = value instanceof Buffer ? value.toString('base64') : Buffer.from(value.buffer).toString('base64');
|
|
356
|
+
} else if (typeof btoa === 'function') {
|
|
357
|
+
let s = '';
|
|
358
|
+
|
|
359
|
+
for (let i = 0; i < value.length; ++i) s += String.fromCharCode(value[i]);
|
|
360
|
+
|
|
361
|
+
src = btoa(s);
|
|
362
|
+
} else {
|
|
363
|
+
throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (!type) type = stringifyNumber.binaryOptions.defaultType;
|
|
367
|
+
|
|
368
|
+
if (type === _rollupPluginBabelHelpers.Type.QUOTE_DOUBLE) {
|
|
369
|
+
value = src;
|
|
370
|
+
} else {
|
|
371
|
+
const {
|
|
372
|
+
lineWidth
|
|
373
|
+
} = stringifyNumber.binaryOptions;
|
|
374
|
+
const n = Math.ceil(src.length / lineWidth);
|
|
375
|
+
const lines = new Array(n);
|
|
376
|
+
|
|
377
|
+
for (let i = 0, o = 0; i < n; ++i, o += lineWidth) {
|
|
378
|
+
lines[i] = src.substr(o, lineWidth);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
value = lines.join(type === _rollupPluginBabelHelpers.Type.BLOCK_LITERAL ? '\n' : ' ');
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return stringifyNumber.stringifyString({
|
|
385
|
+
comment,
|
|
386
|
+
type,
|
|
387
|
+
value
|
|
388
|
+
}, ctx, onComment, onChompKeep);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
|
|
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;
|
|
402
|
+
}
|
|
403
|
+
seq.items[i] = item instanceof stringifyNumber.Pair ? item : new stringifyNumber.Pair(item);
|
|
404
|
+
}
|
|
405
|
+
} else onError('Expected a sequence for this tag');
|
|
406
|
+
|
|
407
|
+
return seq;
|
|
408
|
+
}
|
|
409
|
+
function createPairs(schema, iterable, ctx) {
|
|
410
|
+
const {
|
|
411
|
+
replacer
|
|
412
|
+
} = ctx;
|
|
413
|
+
const pairs = new stringifyNumber.YAMLSeq(schema);
|
|
414
|
+
pairs.tag = 'tag:yaml.org,2002:pairs';
|
|
415
|
+
let i = 0;
|
|
416
|
+
|
|
417
|
+
for (let it of iterable) {
|
|
418
|
+
if (typeof replacer === 'function') it = replacer.call(iterable, String(i++), it);
|
|
419
|
+
let key, value;
|
|
420
|
+
|
|
421
|
+
if (Array.isArray(it)) {
|
|
422
|
+
if (it.length === 2) {
|
|
423
|
+
key = it[0];
|
|
424
|
+
value = it[1];
|
|
425
|
+
} else throw new TypeError(`Expected [key, value] tuple: ${it}`);
|
|
426
|
+
} else if (it && it instanceof Object) {
|
|
427
|
+
const keys = Object.keys(it);
|
|
428
|
+
|
|
429
|
+
if (keys.length === 1) {
|
|
430
|
+
key = keys[0];
|
|
431
|
+
value = it[key];
|
|
432
|
+
} else throw new TypeError(`Expected { key: value } tuple: ${it}`);
|
|
433
|
+
} else {
|
|
434
|
+
key = it;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
pairs.items.push(stringifyNumber.createPair(key, value, ctx));
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return pairs;
|
|
441
|
+
}
|
|
442
|
+
const pairs = {
|
|
443
|
+
default: false,
|
|
444
|
+
tag: 'tag:yaml.org,2002:pairs',
|
|
445
|
+
resolve: parsePairs,
|
|
446
|
+
createNode: createPairs
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
class YAMLOMap extends stringifyNumber.YAMLSeq {
|
|
450
|
+
constructor() {
|
|
451
|
+
super();
|
|
452
|
+
|
|
453
|
+
_rollupPluginBabelHelpers._defineProperty(this, "add", stringifyNumber.YAMLMap.prototype.add.bind(this));
|
|
454
|
+
|
|
455
|
+
_rollupPluginBabelHelpers._defineProperty(this, "delete", stringifyNumber.YAMLMap.prototype.delete.bind(this));
|
|
456
|
+
|
|
457
|
+
_rollupPluginBabelHelpers._defineProperty(this, "get", stringifyNumber.YAMLMap.prototype.get.bind(this));
|
|
458
|
+
|
|
459
|
+
_rollupPluginBabelHelpers._defineProperty(this, "has", stringifyNumber.YAMLMap.prototype.has.bind(this));
|
|
460
|
+
|
|
461
|
+
_rollupPluginBabelHelpers._defineProperty(this, "set", stringifyNumber.YAMLMap.prototype.set.bind(this));
|
|
462
|
+
|
|
463
|
+
this.tag = YAMLOMap.tag;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
toJSON(_, ctx) {
|
|
467
|
+
const map = new Map();
|
|
468
|
+
if (ctx && ctx.onCreate) ctx.onCreate(map);
|
|
469
|
+
|
|
470
|
+
for (const pair of this.items) {
|
|
471
|
+
let key, value;
|
|
472
|
+
|
|
473
|
+
if (pair instanceof stringifyNumber.Pair) {
|
|
474
|
+
key = stringifyNumber.toJS(pair.key, '', ctx);
|
|
475
|
+
value = stringifyNumber.toJS(pair.value, key, ctx);
|
|
476
|
+
} else {
|
|
477
|
+
key = stringifyNumber.toJS(pair, '', ctx);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (map.has(key)) throw new Error('Ordered maps must not include duplicate keys');
|
|
481
|
+
map.set(key, value);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
return map;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
_rollupPluginBabelHelpers._defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap');
|
|
490
|
+
|
|
491
|
+
function parseOMap(seq, onError) {
|
|
492
|
+
const pairs = parsePairs(seq, onError);
|
|
493
|
+
const seenKeys = [];
|
|
494
|
+
|
|
495
|
+
for (const {
|
|
496
|
+
key
|
|
497
|
+
} of pairs.items) {
|
|
498
|
+
if (key instanceof stringifyNumber.Scalar) {
|
|
499
|
+
if (seenKeys.includes(key.value)) {
|
|
500
|
+
onError(`Ordered maps must not include duplicate keys: ${key.value}`);
|
|
501
|
+
} else {
|
|
502
|
+
seenKeys.push(key.value);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
return Object.assign(new YAMLOMap(), pairs);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function createOMap(schema, iterable, ctx) {
|
|
511
|
+
const pairs = createPairs(schema, iterable, ctx);
|
|
512
|
+
const omap = new YAMLOMap();
|
|
513
|
+
omap.items = pairs.items;
|
|
514
|
+
return omap;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
const omap = {
|
|
518
|
+
identify: value => value instanceof Map,
|
|
519
|
+
nodeClass: YAMLOMap,
|
|
520
|
+
default: false,
|
|
521
|
+
tag: 'tag:yaml.org,2002:omap',
|
|
522
|
+
resolve: parseOMap,
|
|
523
|
+
createNode: createOMap
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
class YAMLSet extends stringifyNumber.YAMLMap {
|
|
527
|
+
constructor(schema) {
|
|
528
|
+
super(schema);
|
|
529
|
+
this.tag = YAMLSet.tag;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
add(key) {
|
|
533
|
+
const pair = key instanceof stringifyNumber.Pair ? key : new stringifyNumber.Pair(key);
|
|
534
|
+
const prev = stringifyNumber.findPair(this.items, pair.key);
|
|
535
|
+
if (!prev) this.items.push(pair);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
get(key, keepPair) {
|
|
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;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
set(key, value) {
|
|
544
|
+
if (typeof value !== 'boolean') throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`);
|
|
545
|
+
const prev = stringifyNumber.findPair(this.items, key);
|
|
546
|
+
|
|
547
|
+
if (prev && !value) {
|
|
548
|
+
this.items.splice(this.items.indexOf(prev), 1);
|
|
549
|
+
} else if (!prev && value) {
|
|
550
|
+
this.items.push(new stringifyNumber.Pair(key));
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
toJSON(_, ctx) {
|
|
555
|
+
return super.toJSON(_, ctx, Set);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
toString(ctx, onComment, onChompKeep) {
|
|
559
|
+
if (!ctx) return JSON.stringify(this);
|
|
560
|
+
if (this.hasAllNullValues()) return super.toString(ctx, onComment, onChompKeep);else throw new Error('Set items must all have null values');
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
_rollupPluginBabelHelpers._defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set');
|
|
566
|
+
|
|
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;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function createSet(schema, iterable, ctx) {
|
|
576
|
+
const {
|
|
577
|
+
replacer
|
|
578
|
+
} = ctx;
|
|
579
|
+
const set = new YAMLSet(schema);
|
|
580
|
+
|
|
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
|
+
}
|
|
585
|
+
|
|
586
|
+
return set;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const set = {
|
|
590
|
+
identify: value => value instanceof Set,
|
|
591
|
+
nodeClass: YAMLSet,
|
|
592
|
+
default: false,
|
|
593
|
+
tag: 'tag:yaml.org,2002:set',
|
|
594
|
+
resolve: parseSet,
|
|
595
|
+
createNode: createSet
|
|
596
|
+
};
|
|
597
|
+
|
|
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;
|
|
608
|
+
}; // hhhh:mm:ss.sss
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
const stringifySexagesimal = ({
|
|
612
|
+
value
|
|
613
|
+
}) => {
|
|
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);
|
|
617
|
+
let sign = '';
|
|
618
|
+
|
|
619
|
+
if (value < 0) {
|
|
620
|
+
sign = '-';
|
|
621
|
+
value *= num(-1);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const _60 = num(60);
|
|
625
|
+
|
|
626
|
+
const parts = [value % _60]; // seconds, including ms
|
|
627
|
+
|
|
628
|
+
if (value < 60) {
|
|
629
|
+
parts.unshift(0); // at least one : is required
|
|
630
|
+
} else {
|
|
631
|
+
value = (value - parts[0]) / _60;
|
|
632
|
+
parts.unshift(value % _60); // minutes
|
|
633
|
+
|
|
634
|
+
if (value >= 60) {
|
|
635
|
+
value = (value - parts[0]) / _60;
|
|
636
|
+
parts.unshift(value); // hours
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
return sign + parts.map(n => n < 10 ? '0' + String(n) : String(n)).join(':').replace(/000000\d*$/, '') // % 60 may introduce error
|
|
641
|
+
;
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
const intTime = {
|
|
645
|
+
identify: value => typeof value === 'bigint' || Number.isInteger(value),
|
|
646
|
+
default: true,
|
|
647
|
+
tag: 'tag:yaml.org,2002:int',
|
|
648
|
+
format: 'TIME',
|
|
649
|
+
test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,
|
|
650
|
+
resolve: str => parseSexagesimal(str, true),
|
|
651
|
+
stringify: stringifySexagesimal
|
|
652
|
+
};
|
|
653
|
+
const floatTime = {
|
|
654
|
+
identify: value => typeof value === 'number',
|
|
655
|
+
default: true,
|
|
656
|
+
tag: 'tag:yaml.org,2002:float',
|
|
657
|
+
format: 'TIME',
|
|
658
|
+
test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,
|
|
659
|
+
resolve: str => parseSexagesimal(str, false),
|
|
660
|
+
stringify: stringifySexagesimal
|
|
661
|
+
};
|
|
662
|
+
const timestamp = {
|
|
663
|
+
identify: value => value instanceof Date,
|
|
664
|
+
default: true,
|
|
665
|
+
tag: 'tag:yaml.org,2002:timestamp',
|
|
666
|
+
// If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
|
|
667
|
+
// may be omitted altogether, resulting in a date format. In such a case, the time part is
|
|
668
|
+
// assumed to be 00:00:00Z (start of day, UTC).
|
|
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
|
|
672
|
+
'([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)?
|
|
673
|
+
'(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30
|
|
674
|
+
')?$'),
|
|
675
|
+
|
|
676
|
+
resolve(str) {
|
|
677
|
+
let [, year, month, day, hour, minute, second, millisec, tz] = str.match(timestamp.test);
|
|
678
|
+
if (millisec) millisec = (millisec + '00').substr(1, 3);
|
|
679
|
+
let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0);
|
|
680
|
+
|
|
681
|
+
if (tz && tz !== 'Z') {
|
|
682
|
+
let d = parseSexagesimal(tz, false);
|
|
683
|
+
if (Math.abs(d) < 30) d *= 60;
|
|
684
|
+
date -= 60000 * d;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
return new Date(date);
|
|
688
|
+
},
|
|
689
|
+
|
|
690
|
+
stringify: ({
|
|
691
|
+
value
|
|
692
|
+
}) => value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '')
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
/* global BigInt */
|
|
696
|
+
|
|
697
|
+
const boolStringify = ({
|
|
698
|
+
value
|
|
699
|
+
}) => value ? stringifyNumber.boolOptions.trueStr : stringifyNumber.boolOptions.falseStr;
|
|
700
|
+
|
|
701
|
+
const intIdentify$2 = value => typeof value === 'bigint' || Number.isInteger(value);
|
|
702
|
+
|
|
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, '');
|
|
707
|
+
|
|
708
|
+
if (stringifyNumber.intOptions.asBigInt) {
|
|
709
|
+
switch (radix) {
|
|
710
|
+
case 2:
|
|
711
|
+
str = `0b${str}`;
|
|
712
|
+
break;
|
|
713
|
+
|
|
714
|
+
case 8:
|
|
715
|
+
str = `0o${str}`;
|
|
716
|
+
break;
|
|
717
|
+
|
|
718
|
+
case 16:
|
|
719
|
+
str = `0x${str}`;
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
const n = BigInt(str);
|
|
724
|
+
return sign === '-' ? BigInt(-1) * n : n;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
const n = parseInt(str, radix);
|
|
728
|
+
return sign === '-' ? -1 * n : n;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
function intStringify$1(node, radix, prefix) {
|
|
732
|
+
const {
|
|
733
|
+
value
|
|
734
|
+
} = node;
|
|
735
|
+
|
|
736
|
+
if (intIdentify$2(value)) {
|
|
737
|
+
const str = value.toString(radix);
|
|
738
|
+
return value < 0 ? '-' + prefix + str.substr(1) : prefix + str;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
return stringifyNumber.stringifyNumber(node);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
const yaml11 = failsafe.concat([{
|
|
745
|
+
identify: value => value == null,
|
|
746
|
+
createNode: (schema, value, ctx) => ctx.wrapScalars ? new stringifyNumber.Scalar(null) : null,
|
|
747
|
+
default: true,
|
|
748
|
+
tag: 'tag:yaml.org,2002:null',
|
|
749
|
+
test: /^(?:~|[Nn]ull|NULL)?$/,
|
|
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
|
|
759
|
+
}, {
|
|
760
|
+
identify: value => typeof value === 'boolean',
|
|
761
|
+
default: true,
|
|
762
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
763
|
+
test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
|
|
764
|
+
resolve: () => true,
|
|
765
|
+
options: stringifyNumber.boolOptions,
|
|
766
|
+
stringify: boolStringify
|
|
767
|
+
}, {
|
|
768
|
+
identify: value => typeof value === 'boolean',
|
|
769
|
+
default: true,
|
|
770
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
771
|
+
test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
|
|
772
|
+
resolve: () => false,
|
|
773
|
+
options: stringifyNumber.boolOptions,
|
|
774
|
+
stringify: boolStringify
|
|
775
|
+
}, {
|
|
776
|
+
identify: intIdentify$2,
|
|
777
|
+
default: true,
|
|
778
|
+
tag: 'tag:yaml.org,2002:int',
|
|
779
|
+
format: 'BIN',
|
|
780
|
+
test: /^[-+]?0b[0-1_]+$/,
|
|
781
|
+
resolve: str => intResolve$1(str, 2, 2),
|
|
782
|
+
stringify: node => intStringify$1(node, 2, '0b')
|
|
783
|
+
}, {
|
|
784
|
+
identify: intIdentify$2,
|
|
785
|
+
default: true,
|
|
786
|
+
tag: 'tag:yaml.org,2002:int',
|
|
787
|
+
format: 'OCT',
|
|
788
|
+
test: /^[-+]?0[0-7_]+$/,
|
|
789
|
+
resolve: str => intResolve$1(str, 1, 8),
|
|
790
|
+
stringify: node => intStringify$1(node, 8, '0')
|
|
791
|
+
}, {
|
|
792
|
+
identify: intIdentify$2,
|
|
793
|
+
default: true,
|
|
794
|
+
tag: 'tag:yaml.org,2002:int',
|
|
795
|
+
test: /^[-+]?[0-9][0-9_]*$/,
|
|
796
|
+
resolve: str => intResolve$1(str, 0, 10),
|
|
797
|
+
stringify: stringifyNumber.stringifyNumber
|
|
798
|
+
}, {
|
|
799
|
+
identify: intIdentify$2,
|
|
800
|
+
default: true,
|
|
801
|
+
tag: 'tag:yaml.org,2002:int',
|
|
802
|
+
format: 'HEX',
|
|
803
|
+
test: /^[-+]?0x[0-9a-fA-F_]+$/,
|
|
804
|
+
resolve: str => intResolve$1(str, 2, 16),
|
|
805
|
+
stringify: node => intStringify$1(node, 16, '0x')
|
|
806
|
+
}, {
|
|
807
|
+
identify: value => typeof value === 'number',
|
|
808
|
+
default: true,
|
|
809
|
+
tag: 'tag:yaml.org,2002:float',
|
|
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
|
|
813
|
+
}, {
|
|
814
|
+
identify: value => typeof value === 'number',
|
|
815
|
+
default: true,
|
|
816
|
+
tag: 'tag:yaml.org,2002:float',
|
|
817
|
+
format: 'EXP',
|
|
818
|
+
test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
|
|
819
|
+
resolve: str => parseFloat(str.replace(/_/g, '')),
|
|
820
|
+
stringify: ({
|
|
821
|
+
value
|
|
822
|
+
}) => Number(value).toExponential()
|
|
823
|
+
}, {
|
|
824
|
+
identify: value => typeof value === 'number',
|
|
825
|
+
default: true,
|
|
826
|
+
tag: 'tag:yaml.org,2002:float',
|
|
827
|
+
test: /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,
|
|
828
|
+
|
|
829
|
+
resolve(str) {
|
|
830
|
+
const node = new stringifyNumber.Scalar(parseFloat(str.replace(/_/g, '')));
|
|
831
|
+
const dot = str.indexOf('.');
|
|
832
|
+
|
|
833
|
+
if (dot !== -1) {
|
|
834
|
+
const f = str.substring(dot + 1).replace(/_/g, '');
|
|
835
|
+
if (f[f.length - 1] === '0') node.minFractionDigits = f.length;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
return node;
|
|
839
|
+
},
|
|
840
|
+
|
|
841
|
+
stringify: stringifyNumber.stringifyNumber
|
|
842
|
+
}], binary, omap, pairs, set, intTime, floatTime, timestamp);
|
|
843
|
+
|
|
844
|
+
const schemas = {
|
|
845
|
+
core,
|
|
846
|
+
failsafe,
|
|
847
|
+
json,
|
|
848
|
+
yaml11
|
|
849
|
+
};
|
|
850
|
+
const tags = {
|
|
851
|
+
binary,
|
|
852
|
+
bool: boolObj,
|
|
853
|
+
float: floatObj,
|
|
854
|
+
floatExp: expObj,
|
|
855
|
+
floatNaN: nanObj,
|
|
856
|
+
floatTime,
|
|
857
|
+
int: intObj,
|
|
858
|
+
intHex: hexObj,
|
|
859
|
+
intOct: octObj,
|
|
860
|
+
intTime,
|
|
861
|
+
map,
|
|
862
|
+
null: nullObj,
|
|
863
|
+
omap,
|
|
864
|
+
pairs,
|
|
865
|
+
seq,
|
|
866
|
+
set,
|
|
867
|
+
timestamp
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
function getSchemaTags(schemas, knownTags, customTags, schemaId) {
|
|
871
|
+
let tags = schemas[schemaId.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
|
|
872
|
+
|
|
873
|
+
if (!tags) {
|
|
874
|
+
const keys = Object.keys(schemas).map(key => JSON.stringify(key)).join(', ');
|
|
875
|
+
throw new Error(`Unknown schema "${schemaId}"; use one of ${keys}`);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
if (Array.isArray(customTags)) {
|
|
879
|
+
for (const tag of customTags) tags = tags.concat(tag);
|
|
880
|
+
} else if (typeof customTags === 'function') {
|
|
881
|
+
tags = customTags(tags.slice());
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
for (let i = 0; i < tags.length; ++i) {
|
|
885
|
+
const tag = tags[i];
|
|
886
|
+
|
|
887
|
+
if (typeof tag === 'string') {
|
|
888
|
+
const tagObj = knownTags[tag];
|
|
889
|
+
|
|
890
|
+
if (!tagObj) {
|
|
891
|
+
const keys = Object.keys(knownTags).map(key => JSON.stringify(key)).join(', ');
|
|
892
|
+
throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
tags[i] = tagObj;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
return tags;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
|
|
903
|
+
|
|
904
|
+
const coreKnownTags = {
|
|
905
|
+
'tag:yaml.org,2002:binary': tags.binary,
|
|
906
|
+
'tag:yaml.org,2002:omap': tags.omap,
|
|
907
|
+
'tag:yaml.org,2002:pairs': tags.pairs,
|
|
908
|
+
'tag:yaml.org,2002:set': tags.set,
|
|
909
|
+
'tag:yaml.org,2002:timestamp': tags.timestamp
|
|
910
|
+
};
|
|
911
|
+
class Schema {
|
|
912
|
+
constructor({
|
|
913
|
+
customTags,
|
|
914
|
+
merge,
|
|
915
|
+
resolveKnownTags,
|
|
916
|
+
schema,
|
|
917
|
+
sortMapEntries
|
|
918
|
+
}) {
|
|
919
|
+
this.merge = !!merge;
|
|
920
|
+
this.name = schema;
|
|
921
|
+
this.knownTags = resolveKnownTags ? coreKnownTags : {};
|
|
922
|
+
this.tags = getSchemaTags(schemas, tags, customTags, schema); // Used by createNode(), to avoid circular dependencies
|
|
923
|
+
|
|
924
|
+
this.map = tags.map;
|
|
925
|
+
this.seq = tags.seq; // Used by createMap()
|
|
926
|
+
|
|
927
|
+
this.sortMapEntries = sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
exports.MERGE_KEY = MERGE_KEY;
|
|
933
|
+
exports.Merge = Merge;
|
|
934
|
+
exports.Schema = Schema;
|