yaml 1.9.2 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/browser/dist/PlainValue-ff5147c6.js +1277 -0
- package/browser/dist/Schema-2bf2c74e.js +679 -0
- package/browser/dist/index.js +869 -34
- package/browser/dist/legacy-exports.js +3 -0
- package/browser/dist/parse-cst.js +1904 -0
- package/browser/dist/resolveSeq-04825f30.js +2373 -0
- package/browser/dist/types.js +4 -0
- package/browser/dist/util.js +2 -0
- package/browser/dist/warnings-0e4b70d3.js +499 -0
- package/browser/index.js +1 -1
- package/browser/map.js +2 -4
- package/browser/pair.js +2 -4
- package/browser/parse-cst.js +1 -1
- package/browser/scalar.js +2 -4
- package/browser/schema.js +7 -10
- package/browser/seq.js +2 -4
- package/browser/types/binary.js +7 -5
- package/browser/types/omap.js +3 -4
- package/browser/types/pairs.js +3 -4
- package/browser/types/set.js +3 -4
- package/browser/types/timestamp.js +9 -5
- package/browser/types.js +1 -13
- package/browser/util.js +1 -18
- package/dist/Document-2cf6b08c.js +757 -0
- package/dist/PlainValue-ec8e588e.js +876 -0
- package/dist/Schema-42e9705c.js +522 -0
- package/dist/index.js +20 -84
- package/dist/legacy-exports.js +16 -0
- package/dist/parse-cst.js +1747 -0
- package/dist/resolveSeq-4a68b39b.js +2115 -0
- package/dist/test-events.js +11 -9
- package/dist/types.js +23 -0
- package/dist/util.js +19 -0
- package/dist/warnings-39684f17.js +416 -0
- package/index.d.ts +22 -8
- package/map.js +2 -2
- package/package.json +22 -39
- package/pair.js +2 -2
- package/parse-cst.js +1 -1
- package/scalar.js +2 -2
- package/schema.js +8 -6
- package/seq.js +2 -2
- package/types/binary.js +3 -2
- package/types/omap.js +3 -2
- package/types/pairs.js +3 -2
- package/types/set.js +3 -2
- package/types/timestamp.js +6 -6
- package/types.d.ts +113 -99
- package/types.js +16 -11
- package/types.mjs +15 -19
- package/util.js +14 -14
- package/util.mjs +13 -20
- package/browser/dist/Anchors.js +0 -130
- package/browser/dist/Document.js +0 -824
- package/browser/dist/addComment.js +0 -8
- package/browser/dist/constants.js +0 -26
- package/browser/dist/cst/Alias.js +0 -46
- package/browser/dist/cst/BlankLine.js +0 -52
- package/browser/dist/cst/BlockValue.js +0 -251
- package/browser/dist/cst/Collection.js +0 -278
- package/browser/dist/cst/CollectionItem.js +0 -140
- package/browser/dist/cst/Comment.js +0 -44
- package/browser/dist/cst/Directive.js +0 -76
- package/browser/dist/cst/Document.js +0 -286
- package/browser/dist/cst/FlowCollection.js +0 -220
- package/browser/dist/cst/Node.js +0 -386
- package/browser/dist/cst/ParseContext.js +0 -246
- package/browser/dist/cst/PlainValue.js +0 -170
- package/browser/dist/cst/QuoteDouble.js +0 -245
- package/browser/dist/cst/QuoteSingle.js +0 -120
- package/browser/dist/cst/Range.js +0 -64
- package/browser/dist/cst/parse.js +0 -48
- package/browser/dist/cst/source-utils.js +0 -168
- package/browser/dist/errors.js +0 -127
- package/browser/dist/foldFlowLines.js +0 -138
- package/browser/dist/listTagNames.js +0 -28
- package/browser/dist/schema/Alias.js +0 -135
- package/browser/dist/schema/Collection.js +0 -260
- package/browser/dist/schema/Map.js +0 -161
- package/browser/dist/schema/Merge.js +0 -118
- package/browser/dist/schema/Node.js +0 -4
- package/browser/dist/schema/Pair.js +0 -194
- package/browser/dist/schema/Scalar.js +0 -42
- package/browser/dist/schema/Seq.js +0 -116
- package/browser/dist/schema/index.js +0 -368
- package/browser/dist/schema/parseMap.js +0 -312
- package/browser/dist/schema/parseSeq.js +0 -168
- package/browser/dist/schema/parseUtils.js +0 -106
- package/browser/dist/stringify.js +0 -332
- package/browser/dist/tags/core.js +0 -141
- package/browser/dist/tags/failsafe/index.js +0 -4
- package/browser/dist/tags/failsafe/map.js +0 -53
- package/browser/dist/tags/failsafe/seq.js +0 -39
- package/browser/dist/tags/failsafe/string.js +0 -28
- package/browser/dist/tags/index.js +0 -36
- package/browser/dist/tags/json.js +0 -77
- package/browser/dist/tags/options.js +0 -26
- package/browser/dist/tags/yaml-1.1/binary.js +0 -87
- package/browser/dist/tags/yaml-1.1/index.js +0 -189
- package/browser/dist/tags/yaml-1.1/omap.js +0 -137
- package/browser/dist/tags/yaml-1.1/pairs.js +0 -78
- package/browser/dist/tags/yaml-1.1/set.js +0 -118
- package/browser/dist/tags/yaml-1.1/timestamp.js +0 -97
- package/browser/dist/test-events.js +0 -163
- package/browser/dist/toJSON.js +0 -19
- package/browser/dist/warnings.js +0 -39
- package/dist/Anchors.js +0 -120
- package/dist/Document.js +0 -714
- package/dist/addComment.js +0 -14
- package/dist/constants.js +0 -31
- package/dist/cst/Alias.js +0 -33
- package/dist/cst/BlankLine.js +0 -40
- package/dist/cst/BlockValue.js +0 -243
- package/dist/cst/Collection.js +0 -266
- package/dist/cst/CollectionItem.js +0 -135
- package/dist/cst/Comment.js +0 -33
- package/dist/cst/Directive.js +0 -59
- package/dist/cst/Document.js +0 -276
- package/dist/cst/FlowCollection.js +0 -213
- package/dist/cst/Node.js +0 -360
- package/dist/cst/ParseContext.js +0 -253
- package/dist/cst/PlainValue.js +0 -156
- package/dist/cst/QuoteDouble.js +0 -232
- package/dist/cst/QuoteSingle.js +0 -108
- package/dist/cst/Range.js +0 -60
- package/dist/cst/parse.js +0 -50
- package/dist/cst/source-utils.js +0 -175
- package/dist/errors.js +0 -97
- package/dist/foldFlowLines.js +0 -143
- package/dist/listTagNames.js +0 -33
- package/dist/schema/Alias.js +0 -105
- package/dist/schema/Collection.js +0 -184
- package/dist/schema/Map.js +0 -98
- package/dist/schema/Merge.js +0 -75
- package/dist/schema/Node.js +0 -7
- package/dist/schema/Pair.js +0 -174
- package/dist/schema/Scalar.js +0 -26
- package/dist/schema/Seq.js +0 -73
- package/dist/schema/index.js +0 -310
- package/dist/schema/parseMap.js +0 -334
- package/dist/schema/parseSeq.js +0 -175
- package/dist/schema/parseUtils.js +0 -101
- package/dist/stringify.js +0 -352
- package/dist/tags/core.js +0 -121
- package/dist/tags/failsafe/index.js +0 -12
- package/dist/tags/failsafe/map.js +0 -32
- package/dist/tags/failsafe/seq.js +0 -29
- package/dist/tags/failsafe/string.js +0 -37
- package/dist/tags/index.js +0 -53
- package/dist/tags/json.js +0 -64
- package/dist/tags/options.js +0 -36
- package/dist/tags/yaml-1.1/binary.js +0 -94
- package/dist/tags/yaml-1.1/index.js +0 -162
- package/dist/tags/yaml-1.1/omap.js +0 -100
- package/dist/tags/yaml-1.1/pairs.js +0 -75
- package/dist/tags/yaml-1.1/set.js +0 -82
- package/dist/tags/yaml-1.1/timestamp.js +0 -90
- package/dist/toJSON.js +0 -21
- package/dist/warnings.js +0 -48
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var PlainValue = require('./PlainValue-ec8e588e.js');
|
|
4
|
+
var resolveSeq = require('./resolveSeq-4a68b39b.js');
|
|
5
|
+
var warnings = require('./warnings-39684f17.js');
|
|
6
|
+
|
|
7
|
+
function createMap(schema, obj, ctx) {
|
|
8
|
+
const map = new resolveSeq.YAMLMap(schema);
|
|
9
|
+
|
|
10
|
+
if (obj instanceof Map) {
|
|
11
|
+
for (const [key, value] of obj) map.items.push(schema.createPair(key, value, ctx));
|
|
12
|
+
} else if (obj && typeof obj === 'object') {
|
|
13
|
+
for (const key of Object.keys(obj)) map.items.push(schema.createPair(key, obj[key], ctx));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof schema.sortMapEntries === 'function') {
|
|
17
|
+
map.items.sort(schema.sortMapEntries);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return map;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const map = {
|
|
24
|
+
createNode: createMap,
|
|
25
|
+
default: true,
|
|
26
|
+
nodeClass: resolveSeq.YAMLMap,
|
|
27
|
+
tag: 'tag:yaml.org,2002:map',
|
|
28
|
+
resolve: resolveSeq.resolveMap
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function createSeq(schema, obj, ctx) {
|
|
32
|
+
const seq = new resolveSeq.YAMLSeq(schema);
|
|
33
|
+
|
|
34
|
+
if (obj && obj[Symbol.iterator]) {
|
|
35
|
+
for (const it of obj) {
|
|
36
|
+
const v = schema.createNode(it, ctx.wrapScalars, null, ctx);
|
|
37
|
+
seq.items.push(v);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return seq;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const seq = {
|
|
45
|
+
createNode: createSeq,
|
|
46
|
+
default: true,
|
|
47
|
+
nodeClass: resolveSeq.YAMLSeq,
|
|
48
|
+
tag: 'tag:yaml.org,2002:seq',
|
|
49
|
+
resolve: resolveSeq.resolveSeq
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const string = {
|
|
53
|
+
identify: value => typeof value === 'string',
|
|
54
|
+
default: true,
|
|
55
|
+
tag: 'tag:yaml.org,2002:str',
|
|
56
|
+
resolve: resolveSeq.resolveString,
|
|
57
|
+
|
|
58
|
+
stringify(item, ctx, onComment, onChompKeep) {
|
|
59
|
+
ctx = Object.assign({
|
|
60
|
+
actualString: true
|
|
61
|
+
}, ctx);
|
|
62
|
+
return resolveSeq.stringifyString(item, ctx, onComment, onChompKeep);
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
options: resolveSeq.strOptions
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const failsafe = [map, seq, string];
|
|
69
|
+
|
|
70
|
+
/* global BigInt */
|
|
71
|
+
|
|
72
|
+
const intIdentify = value => typeof value === 'bigint' || Number.isInteger(value);
|
|
73
|
+
|
|
74
|
+
const intResolve = (src, part, radix) => resolveSeq.intOptions.asBigInt ? BigInt(src) : parseInt(part, radix);
|
|
75
|
+
|
|
76
|
+
function intStringify(node, radix, prefix) {
|
|
77
|
+
const {
|
|
78
|
+
value
|
|
79
|
+
} = node;
|
|
80
|
+
if (intIdentify(value) && value >= 0) return prefix + value.toString(radix);
|
|
81
|
+
return resolveSeq.stringifyNumber(node);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const nullObj = {
|
|
85
|
+
identify: value => value == null,
|
|
86
|
+
createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq.Scalar(null) : null,
|
|
87
|
+
default: true,
|
|
88
|
+
tag: 'tag:yaml.org,2002:null',
|
|
89
|
+
test: /^(?:~|[Nn]ull|NULL)?$/,
|
|
90
|
+
resolve: () => null,
|
|
91
|
+
options: resolveSeq.nullOptions,
|
|
92
|
+
stringify: () => resolveSeq.nullOptions.nullStr
|
|
93
|
+
};
|
|
94
|
+
const boolObj = {
|
|
95
|
+
identify: value => typeof value === 'boolean',
|
|
96
|
+
default: true,
|
|
97
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
98
|
+
test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
|
|
99
|
+
resolve: str => str[0] === 't' || str[0] === 'T',
|
|
100
|
+
options: resolveSeq.boolOptions,
|
|
101
|
+
stringify: ({
|
|
102
|
+
value
|
|
103
|
+
}) => value ? resolveSeq.boolOptions.trueStr : resolveSeq.boolOptions.falseStr
|
|
104
|
+
};
|
|
105
|
+
const octObj = {
|
|
106
|
+
identify: value => intIdentify(value) && value >= 0,
|
|
107
|
+
default: true,
|
|
108
|
+
tag: 'tag:yaml.org,2002:int',
|
|
109
|
+
format: 'OCT',
|
|
110
|
+
test: /^0o([0-7]+)$/,
|
|
111
|
+
resolve: (str, oct) => intResolve(str, oct, 8),
|
|
112
|
+
options: resolveSeq.intOptions,
|
|
113
|
+
stringify: node => intStringify(node, 8, '0o')
|
|
114
|
+
};
|
|
115
|
+
const intObj = {
|
|
116
|
+
identify: intIdentify,
|
|
117
|
+
default: true,
|
|
118
|
+
tag: 'tag:yaml.org,2002:int',
|
|
119
|
+
test: /^[-+]?[0-9]+$/,
|
|
120
|
+
resolve: str => intResolve(str, str, 10),
|
|
121
|
+
options: resolveSeq.intOptions,
|
|
122
|
+
stringify: resolveSeq.stringifyNumber
|
|
123
|
+
};
|
|
124
|
+
const hexObj = {
|
|
125
|
+
identify: value => intIdentify(value) && value >= 0,
|
|
126
|
+
default: true,
|
|
127
|
+
tag: 'tag:yaml.org,2002:int',
|
|
128
|
+
format: 'HEX',
|
|
129
|
+
test: /^0x([0-9a-fA-F]+)$/,
|
|
130
|
+
resolve: (str, hex) => intResolve(str, hex, 16),
|
|
131
|
+
options: resolveSeq.intOptions,
|
|
132
|
+
stringify: node => intStringify(node, 16, '0x')
|
|
133
|
+
};
|
|
134
|
+
const nanObj = {
|
|
135
|
+
identify: value => typeof value === 'number',
|
|
136
|
+
default: true,
|
|
137
|
+
tag: 'tag:yaml.org,2002:float',
|
|
138
|
+
test: /^(?:[-+]?\.inf|(\.nan))$/i,
|
|
139
|
+
resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
|
|
140
|
+
stringify: resolveSeq.stringifyNumber
|
|
141
|
+
};
|
|
142
|
+
const expObj = {
|
|
143
|
+
identify: value => typeof value === 'number',
|
|
144
|
+
default: true,
|
|
145
|
+
tag: 'tag:yaml.org,2002:float',
|
|
146
|
+
format: 'EXP',
|
|
147
|
+
test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
|
|
148
|
+
resolve: str => parseFloat(str),
|
|
149
|
+
stringify: ({
|
|
150
|
+
value
|
|
151
|
+
}) => Number(value).toExponential()
|
|
152
|
+
};
|
|
153
|
+
const floatObj = {
|
|
154
|
+
identify: value => typeof value === 'number',
|
|
155
|
+
default: true,
|
|
156
|
+
tag: 'tag:yaml.org,2002:float',
|
|
157
|
+
test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/,
|
|
158
|
+
|
|
159
|
+
resolve(str, frac1, frac2) {
|
|
160
|
+
const frac = frac1 || frac2;
|
|
161
|
+
const node = new resolveSeq.Scalar(parseFloat(str));
|
|
162
|
+
if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
|
|
163
|
+
return node;
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
stringify: resolveSeq.stringifyNumber
|
|
167
|
+
};
|
|
168
|
+
const core = failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
|
|
169
|
+
|
|
170
|
+
/* global BigInt */
|
|
171
|
+
|
|
172
|
+
const intIdentify$1 = value => typeof value === 'bigint' || Number.isInteger(value);
|
|
173
|
+
|
|
174
|
+
const stringifyJSON = ({
|
|
175
|
+
value
|
|
176
|
+
}) => JSON.stringify(value);
|
|
177
|
+
|
|
178
|
+
const json = [map, seq, {
|
|
179
|
+
identify: value => typeof value === 'string',
|
|
180
|
+
default: true,
|
|
181
|
+
tag: 'tag:yaml.org,2002:str',
|
|
182
|
+
resolve: resolveSeq.resolveString,
|
|
183
|
+
stringify: stringifyJSON
|
|
184
|
+
}, {
|
|
185
|
+
identify: value => value == null,
|
|
186
|
+
createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq.Scalar(null) : null,
|
|
187
|
+
default: true,
|
|
188
|
+
tag: 'tag:yaml.org,2002:null',
|
|
189
|
+
test: /^null$/,
|
|
190
|
+
resolve: () => null,
|
|
191
|
+
stringify: stringifyJSON
|
|
192
|
+
}, {
|
|
193
|
+
identify: value => typeof value === 'boolean',
|
|
194
|
+
default: true,
|
|
195
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
196
|
+
test: /^true|false$/,
|
|
197
|
+
resolve: str => str === 'true',
|
|
198
|
+
stringify: stringifyJSON
|
|
199
|
+
}, {
|
|
200
|
+
identify: intIdentify$1,
|
|
201
|
+
default: true,
|
|
202
|
+
tag: 'tag:yaml.org,2002:int',
|
|
203
|
+
test: /^-?(?:0|[1-9][0-9]*)$/,
|
|
204
|
+
resolve: str => resolveSeq.intOptions.asBigInt ? BigInt(str) : parseInt(str, 10),
|
|
205
|
+
stringify: ({
|
|
206
|
+
value
|
|
207
|
+
}) => intIdentify$1(value) ? value.toString() : JSON.stringify(value)
|
|
208
|
+
}, {
|
|
209
|
+
identify: value => typeof value === 'number',
|
|
210
|
+
default: true,
|
|
211
|
+
tag: 'tag:yaml.org,2002:float',
|
|
212
|
+
test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
|
|
213
|
+
resolve: str => parseFloat(str),
|
|
214
|
+
stringify: stringifyJSON
|
|
215
|
+
}];
|
|
216
|
+
|
|
217
|
+
json.scalarFallback = str => {
|
|
218
|
+
throw new SyntaxError(`Unresolved plain scalar ${JSON.stringify(str)}`);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/* global BigInt */
|
|
222
|
+
|
|
223
|
+
const boolStringify = ({
|
|
224
|
+
value
|
|
225
|
+
}) => value ? resolveSeq.boolOptions.trueStr : resolveSeq.boolOptions.falseStr;
|
|
226
|
+
|
|
227
|
+
const intIdentify$2 = value => typeof value === 'bigint' || Number.isInteger(value);
|
|
228
|
+
|
|
229
|
+
function intResolve$1(sign, src, radix) {
|
|
230
|
+
let str = src.replace(/_/g, '');
|
|
231
|
+
|
|
232
|
+
if (resolveSeq.intOptions.asBigInt) {
|
|
233
|
+
switch (radix) {
|
|
234
|
+
case 2:
|
|
235
|
+
str = `0b${str}`;
|
|
236
|
+
break;
|
|
237
|
+
|
|
238
|
+
case 8:
|
|
239
|
+
str = `0o${str}`;
|
|
240
|
+
break;
|
|
241
|
+
|
|
242
|
+
case 16:
|
|
243
|
+
str = `0x${str}`;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const n = BigInt(str);
|
|
248
|
+
return sign === '-' ? BigInt(-1) * n : n;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const n = parseInt(str, radix);
|
|
252
|
+
return sign === '-' ? -1 * n : n;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function intStringify$1(node, radix, prefix) {
|
|
256
|
+
const {
|
|
257
|
+
value
|
|
258
|
+
} = node;
|
|
259
|
+
|
|
260
|
+
if (intIdentify$2(value)) {
|
|
261
|
+
const str = value.toString(radix);
|
|
262
|
+
return value < 0 ? '-' + prefix + str.substr(1) : prefix + str;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return resolveSeq.stringifyNumber(node);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const yaml11 = failsafe.concat([{
|
|
269
|
+
identify: value => value == null,
|
|
270
|
+
createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq.Scalar(null) : null,
|
|
271
|
+
default: true,
|
|
272
|
+
tag: 'tag:yaml.org,2002:null',
|
|
273
|
+
test: /^(?:~|[Nn]ull|NULL)?$/,
|
|
274
|
+
resolve: () => null,
|
|
275
|
+
options: resolveSeq.nullOptions,
|
|
276
|
+
stringify: () => resolveSeq.nullOptions.nullStr
|
|
277
|
+
}, {
|
|
278
|
+
identify: value => typeof value === 'boolean',
|
|
279
|
+
default: true,
|
|
280
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
281
|
+
test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
|
|
282
|
+
resolve: () => true,
|
|
283
|
+
options: resolveSeq.boolOptions,
|
|
284
|
+
stringify: boolStringify
|
|
285
|
+
}, {
|
|
286
|
+
identify: value => typeof value === 'boolean',
|
|
287
|
+
default: true,
|
|
288
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
289
|
+
test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
|
|
290
|
+
resolve: () => false,
|
|
291
|
+
options: resolveSeq.boolOptions,
|
|
292
|
+
stringify: boolStringify
|
|
293
|
+
}, {
|
|
294
|
+
identify: intIdentify$2,
|
|
295
|
+
default: true,
|
|
296
|
+
tag: 'tag:yaml.org,2002:int',
|
|
297
|
+
format: 'BIN',
|
|
298
|
+
test: /^([-+]?)0b([0-1_]+)$/,
|
|
299
|
+
resolve: (str, sign, bin) => intResolve$1(sign, bin, 2),
|
|
300
|
+
stringify: node => intStringify$1(node, 2, '0b')
|
|
301
|
+
}, {
|
|
302
|
+
identify: intIdentify$2,
|
|
303
|
+
default: true,
|
|
304
|
+
tag: 'tag:yaml.org,2002:int',
|
|
305
|
+
format: 'OCT',
|
|
306
|
+
test: /^([-+]?)0([0-7_]+)$/,
|
|
307
|
+
resolve: (str, sign, oct) => intResolve$1(sign, oct, 8),
|
|
308
|
+
stringify: node => intStringify$1(node, 8, '0')
|
|
309
|
+
}, {
|
|
310
|
+
identify: intIdentify$2,
|
|
311
|
+
default: true,
|
|
312
|
+
tag: 'tag:yaml.org,2002:int',
|
|
313
|
+
test: /^([-+]?)([0-9][0-9_]*)$/,
|
|
314
|
+
resolve: (str, sign, abs) => intResolve$1(sign, abs, 10),
|
|
315
|
+
stringify: resolveSeq.stringifyNumber
|
|
316
|
+
}, {
|
|
317
|
+
identify: intIdentify$2,
|
|
318
|
+
default: true,
|
|
319
|
+
tag: 'tag:yaml.org,2002:int',
|
|
320
|
+
format: 'HEX',
|
|
321
|
+
test: /^([-+]?)0x([0-9a-fA-F_]+)$/,
|
|
322
|
+
resolve: (str, sign, hex) => intResolve$1(sign, hex, 16),
|
|
323
|
+
stringify: node => intStringify$1(node, 16, '0x')
|
|
324
|
+
}, {
|
|
325
|
+
identify: value => typeof value === 'number',
|
|
326
|
+
default: true,
|
|
327
|
+
tag: 'tag:yaml.org,2002:float',
|
|
328
|
+
test: /^(?:[-+]?\.inf|(\.nan))$/i,
|
|
329
|
+
resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
|
|
330
|
+
stringify: resolveSeq.stringifyNumber
|
|
331
|
+
}, {
|
|
332
|
+
identify: value => typeof value === 'number',
|
|
333
|
+
default: true,
|
|
334
|
+
tag: 'tag:yaml.org,2002:float',
|
|
335
|
+
format: 'EXP',
|
|
336
|
+
test: /^[-+]?([0-9][0-9_]*)?(\.[0-9_]*)?[eE][-+]?[0-9]+$/,
|
|
337
|
+
resolve: str => parseFloat(str.replace(/_/g, '')),
|
|
338
|
+
stringify: ({
|
|
339
|
+
value
|
|
340
|
+
}) => Number(value).toExponential()
|
|
341
|
+
}, {
|
|
342
|
+
identify: value => typeof value === 'number',
|
|
343
|
+
default: true,
|
|
344
|
+
tag: 'tag:yaml.org,2002:float',
|
|
345
|
+
test: /^[-+]?(?:[0-9][0-9_]*)?\.([0-9_]*)$/,
|
|
346
|
+
|
|
347
|
+
resolve(str, frac) {
|
|
348
|
+
const node = new resolveSeq.Scalar(parseFloat(str.replace(/_/g, '')));
|
|
349
|
+
|
|
350
|
+
if (frac) {
|
|
351
|
+
const f = frac.replace(/_/g, '');
|
|
352
|
+
if (f[f.length - 1] === '0') node.minFractionDigits = f.length;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return node;
|
|
356
|
+
},
|
|
357
|
+
|
|
358
|
+
stringify: resolveSeq.stringifyNumber
|
|
359
|
+
}], warnings.binary, warnings.omap, warnings.pairs, warnings.set, warnings.intTime, warnings.floatTime, warnings.timestamp);
|
|
360
|
+
|
|
361
|
+
const schemas = {
|
|
362
|
+
core,
|
|
363
|
+
failsafe,
|
|
364
|
+
json,
|
|
365
|
+
yaml11
|
|
366
|
+
};
|
|
367
|
+
const tags = {
|
|
368
|
+
binary: warnings.binary,
|
|
369
|
+
bool: boolObj,
|
|
370
|
+
float: floatObj,
|
|
371
|
+
floatExp: expObj,
|
|
372
|
+
floatNaN: nanObj,
|
|
373
|
+
floatTime: warnings.floatTime,
|
|
374
|
+
int: intObj,
|
|
375
|
+
intHex: hexObj,
|
|
376
|
+
intOct: octObj,
|
|
377
|
+
intTime: warnings.intTime,
|
|
378
|
+
map,
|
|
379
|
+
null: nullObj,
|
|
380
|
+
omap: warnings.omap,
|
|
381
|
+
pairs: warnings.pairs,
|
|
382
|
+
seq,
|
|
383
|
+
set: warnings.set,
|
|
384
|
+
timestamp: warnings.timestamp
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
function findTagObject(value, tagName, tags) {
|
|
388
|
+
if (tagName) {
|
|
389
|
+
const match = tags.filter(t => t.tag === tagName);
|
|
390
|
+
const tagObj = match.find(t => !t.format) || match[0];
|
|
391
|
+
if (!tagObj) throw new Error(`Tag ${tagName} not found`);
|
|
392
|
+
return tagObj;
|
|
393
|
+
} // TODO: deprecate/remove class check
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
return tags.find(t => (t.identify && t.identify(value) || t.class && value instanceof t.class) && !t.format);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function createNode(value, tagName, ctx) {
|
|
400
|
+
if (value instanceof resolveSeq.Node) return value;
|
|
401
|
+
const {
|
|
402
|
+
defaultPrefix,
|
|
403
|
+
onTagObj,
|
|
404
|
+
prevObjects,
|
|
405
|
+
schema,
|
|
406
|
+
wrapScalars
|
|
407
|
+
} = ctx;
|
|
408
|
+
if (tagName && tagName.startsWith('!!')) tagName = defaultPrefix + tagName.slice(2);
|
|
409
|
+
let tagObj = findTagObject(value, tagName, schema.tags);
|
|
410
|
+
|
|
411
|
+
if (!tagObj) {
|
|
412
|
+
if (typeof value.toJSON === 'function') value = value.toJSON();
|
|
413
|
+
if (typeof value !== 'object') return wrapScalars ? new resolveSeq.Scalar(value) : value;
|
|
414
|
+
tagObj = value instanceof Map ? map : value[Symbol.iterator] ? seq : map;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (onTagObj) {
|
|
418
|
+
onTagObj(tagObj);
|
|
419
|
+
delete ctx.onTagObj;
|
|
420
|
+
} // Detect duplicate references to the same object & use Alias nodes for all
|
|
421
|
+
// after first. The `obj` wrapper allows for circular references to resolve.
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
const obj = {};
|
|
425
|
+
|
|
426
|
+
if (value && typeof value === 'object' && prevObjects) {
|
|
427
|
+
const prev = prevObjects.get(value);
|
|
428
|
+
|
|
429
|
+
if (prev) {
|
|
430
|
+
const alias = new resolveSeq.Alias(prev); // leaves source dirty; must be cleaned by caller
|
|
431
|
+
|
|
432
|
+
ctx.aliasNodes.push(alias); // defined along with prevObjects
|
|
433
|
+
|
|
434
|
+
return alias;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
obj.value = value;
|
|
438
|
+
prevObjects.set(value, obj);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
obj.node = tagObj.createNode ? tagObj.createNode(ctx.schema, value, ctx) : wrapScalars ? new resolveSeq.Scalar(value) : value;
|
|
442
|
+
if (tagName && obj.node instanceof resolveSeq.Node) obj.node.tag = tagName;
|
|
443
|
+
return obj.node;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function getSchemaTags(schemas, knownTags, customTags, schemaId) {
|
|
447
|
+
let tags = schemas[schemaId.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
|
|
448
|
+
|
|
449
|
+
if (!tags) {
|
|
450
|
+
const keys = Object.keys(schemas).map(key => JSON.stringify(key)).join(', ');
|
|
451
|
+
throw new Error(`Unknown schema "${schemaId}"; use one of ${keys}`);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (Array.isArray(customTags)) {
|
|
455
|
+
for (const tag of customTags) tags = tags.concat(tag);
|
|
456
|
+
} else if (typeof customTags === 'function') {
|
|
457
|
+
tags = customTags(tags.slice());
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
for (let i = 0; i < tags.length; ++i) {
|
|
461
|
+
const tag = tags[i];
|
|
462
|
+
|
|
463
|
+
if (typeof tag === 'string') {
|
|
464
|
+
const tagObj = knownTags[tag];
|
|
465
|
+
|
|
466
|
+
if (!tagObj) {
|
|
467
|
+
const keys = Object.keys(knownTags).map(key => JSON.stringify(key)).join(', ');
|
|
468
|
+
throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
tags[i] = tagObj;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
return tags;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
|
|
479
|
+
|
|
480
|
+
class Schema {
|
|
481
|
+
// TODO: remove in v2
|
|
482
|
+
// TODO: remove in v2
|
|
483
|
+
constructor({
|
|
484
|
+
customTags,
|
|
485
|
+
merge,
|
|
486
|
+
schema,
|
|
487
|
+
sortMapEntries,
|
|
488
|
+
tags: deprecatedCustomTags
|
|
489
|
+
}) {
|
|
490
|
+
this.merge = !!merge;
|
|
491
|
+
this.name = schema;
|
|
492
|
+
this.sortMapEntries = sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null;
|
|
493
|
+
if (!customTags && deprecatedCustomTags) warnings.warnOptionDeprecation('tags', 'customTags');
|
|
494
|
+
this.tags = getSchemaTags(schemas, tags, customTags || deprecatedCustomTags, schema);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
createNode(value, wrapScalars, tagName, ctx) {
|
|
498
|
+
const baseCtx = {
|
|
499
|
+
defaultPrefix: Schema.defaultPrefix,
|
|
500
|
+
schema: this,
|
|
501
|
+
wrapScalars
|
|
502
|
+
};
|
|
503
|
+
const createCtx = ctx ? Object.assign(ctx, baseCtx) : baseCtx;
|
|
504
|
+
return createNode(value, tagName, createCtx);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
createPair(key, value, ctx) {
|
|
508
|
+
if (!ctx) ctx = {
|
|
509
|
+
wrapScalars: true
|
|
510
|
+
};
|
|
511
|
+
const k = this.createNode(key, ctx.wrapScalars, null, ctx);
|
|
512
|
+
const v = this.createNode(value, ctx.wrapScalars, null, ctx);
|
|
513
|
+
return new resolveSeq.Pair(k, v);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
PlainValue._defineProperty(Schema, "defaultPrefix", PlainValue.defaultTagPrefix);
|
|
519
|
+
|
|
520
|
+
PlainValue._defineProperty(Schema, "defaultTags", PlainValue.defaultTags);
|
|
521
|
+
|
|
522
|
+
exports.Schema = Schema;
|
package/dist/index.js
CHANGED
|
@@ -1,76 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
var _errors = require("./errors");
|
|
10
|
-
|
|
11
|
-
var _schema = require("./schema");
|
|
12
|
-
|
|
13
|
-
var _options = require("./tags/options");
|
|
14
|
-
|
|
15
|
-
var _warnings = require("./warnings");
|
|
16
|
-
|
|
17
|
-
const defaultOptions = {
|
|
18
|
-
anchorPrefix: 'a',
|
|
19
|
-
customTags: null,
|
|
20
|
-
indent: 2,
|
|
21
|
-
indentSeq: true,
|
|
22
|
-
keepCstNodes: false,
|
|
23
|
-
keepNodeTypes: true,
|
|
24
|
-
keepBlobsInJSON: true,
|
|
25
|
-
mapAsMap: false,
|
|
26
|
-
maxAliasCount: 100,
|
|
27
|
-
prettyErrors: false,
|
|
28
|
-
// TODO Set true in v2
|
|
29
|
-
simpleKeys: false,
|
|
30
|
-
version: '1.2'
|
|
31
|
-
};
|
|
32
|
-
const scalarOptions = {
|
|
33
|
-
get binary() {
|
|
34
|
-
return _options.binaryOptions;
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
set binary(opt) {
|
|
38
|
-
Object.assign(_options.binaryOptions, opt);
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
get bool() {
|
|
42
|
-
return _options.boolOptions;
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
set bool(opt) {
|
|
46
|
-
Object.assign(_options.boolOptions, opt);
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
get int() {
|
|
50
|
-
return _options.intOptions;
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
set int(opt) {
|
|
54
|
-
Object.assign(_options.intOptions, opt);
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
get null() {
|
|
58
|
-
return _options.nullOptions;
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
set null(opt) {
|
|
62
|
-
Object.assign(_options.nullOptions, opt);
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
get str() {
|
|
66
|
-
return _options.strOptions;
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
set str(opt) {
|
|
70
|
-
Object.assign(_options.strOptions, opt);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
};
|
|
3
|
+
var PlainValue = require('./PlainValue-ec8e588e.js');
|
|
4
|
+
var parseCst = require('./parse-cst.js');
|
|
5
|
+
require('./resolveSeq-4a68b39b.js');
|
|
6
|
+
var Document$1 = require('./Document-2cf6b08c.js');
|
|
7
|
+
var Schema = require('./Schema-42e9705c.js');
|
|
8
|
+
var warnings = require('./warnings-39684f17.js');
|
|
74
9
|
|
|
75
10
|
function createNode(value, wrapScalars = true, tag) {
|
|
76
11
|
if (tag === undefined && typeof wrapScalars === 'string') {
|
|
@@ -78,14 +13,14 @@ function createNode(value, wrapScalars = true, tag) {
|
|
|
78
13
|
wrapScalars = true;
|
|
79
14
|
}
|
|
80
15
|
|
|
81
|
-
const options = Object.assign({},
|
|
82
|
-
const schema = new
|
|
16
|
+
const options = Object.assign({}, Document$1.Document.defaults[Document$1.defaultOptions.version], Document$1.defaultOptions);
|
|
17
|
+
const schema = new Schema.Schema(options);
|
|
83
18
|
return schema.createNode(value, wrapScalars, tag);
|
|
84
19
|
}
|
|
85
20
|
|
|
86
|
-
class Document extends
|
|
21
|
+
class Document extends Document$1.Document {
|
|
87
22
|
constructor(options) {
|
|
88
|
-
super(Object.assign({}, defaultOptions, options));
|
|
23
|
+
super(Object.assign({}, Document$1.defaultOptions, options));
|
|
89
24
|
}
|
|
90
25
|
|
|
91
26
|
}
|
|
@@ -94,7 +29,7 @@ function parseAllDocuments(src, options) {
|
|
|
94
29
|
const stream = [];
|
|
95
30
|
let prev;
|
|
96
31
|
|
|
97
|
-
for (const cstDoc of
|
|
32
|
+
for (const cstDoc of parseCst.parse(src)) {
|
|
98
33
|
const doc = new Document(options);
|
|
99
34
|
doc.parse(cstDoc, prev);
|
|
100
35
|
stream.push(doc);
|
|
@@ -105,12 +40,12 @@ function parseAllDocuments(src, options) {
|
|
|
105
40
|
}
|
|
106
41
|
|
|
107
42
|
function parseDocument(src, options) {
|
|
108
|
-
const cst =
|
|
43
|
+
const cst = parseCst.parse(src);
|
|
109
44
|
const doc = new Document(options).parse(cst[0]);
|
|
110
45
|
|
|
111
46
|
if (cst.length > 1) {
|
|
112
47
|
const errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()';
|
|
113
|
-
doc.errors.unshift(new
|
|
48
|
+
doc.errors.unshift(new PlainValue.YAMLSemanticError(cst[1], errMsg));
|
|
114
49
|
}
|
|
115
50
|
|
|
116
51
|
return doc;
|
|
@@ -118,7 +53,7 @@ function parseDocument(src, options) {
|
|
|
118
53
|
|
|
119
54
|
function parse(src, options) {
|
|
120
55
|
const doc = parseDocument(src, options);
|
|
121
|
-
doc.warnings.forEach(warning =>
|
|
56
|
+
doc.warnings.forEach(warning => warnings.warn(warning));
|
|
122
57
|
if (doc.errors.length > 0) throw doc.errors[0];
|
|
123
58
|
return doc.toJSON();
|
|
124
59
|
}
|
|
@@ -131,13 +66,14 @@ function stringify(value, options) {
|
|
|
131
66
|
|
|
132
67
|
const YAML = {
|
|
133
68
|
createNode,
|
|
134
|
-
defaultOptions,
|
|
69
|
+
defaultOptions: Document$1.defaultOptions,
|
|
135
70
|
Document,
|
|
136
71
|
parse,
|
|
137
72
|
parseAllDocuments,
|
|
138
|
-
parseCST:
|
|
73
|
+
parseCST: parseCst.parse,
|
|
139
74
|
parseDocument,
|
|
140
|
-
scalarOptions,
|
|
75
|
+
scalarOptions: Document$1.scalarOptions,
|
|
141
76
|
stringify
|
|
142
77
|
};
|
|
143
|
-
|
|
78
|
+
|
|
79
|
+
exports.YAML = YAML;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('./PlainValue-ec8e588e.js');
|
|
4
|
+
require('./resolveSeq-4a68b39b.js');
|
|
5
|
+
var warnings = require('./warnings-39684f17.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.binary = warnings.binary;
|
|
10
|
+
exports.floatTime = warnings.floatTime;
|
|
11
|
+
exports.intTime = warnings.intTime;
|
|
12
|
+
exports.omap = warnings.omap;
|
|
13
|
+
exports.pairs = warnings.pairs;
|
|
14
|
+
exports.set = warnings.set;
|
|
15
|
+
exports.timestamp = warnings.timestamp;
|
|
16
|
+
exports.warnFileDeprecation = warnings.warnFileDeprecation;
|