yaml 1.4.0 → 1.5.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 +3 -5
- package/browser/dist/Anchors.js +1 -3
- package/browser/dist/Document.js +94 -37
- package/browser/dist/constants.js +34 -0
- package/browser/dist/cst/Alias.js +1 -3
- package/browser/dist/cst/BlankLine.js +5 -7
- package/browser/dist/cst/BlockValue.js +4 -4
- package/browser/dist/cst/Collection.js +7 -7
- package/browser/dist/cst/CollectionItem.js +6 -8
- package/browser/dist/cst/Comment.js +5 -7
- package/browser/dist/cst/Directive.js +5 -7
- package/browser/dist/cst/Document.js +8 -10
- package/browser/dist/cst/FlowCollection.js +5 -7
- package/browser/dist/cst/Node.js +12 -40
- package/browser/dist/cst/ParseContext.js +32 -34
- package/browser/dist/cst/PlainValue.js +1 -3
- package/browser/dist/cst/QuoteDouble.js +1 -3
- package/browser/dist/cst/QuoteSingle.js +1 -3
- package/browser/dist/cst/Range.js +1 -3
- package/browser/dist/cst/getLinePos.js +1 -4
- package/browser/dist/cst/parse.js +1 -4
- package/browser/dist/deprecation.js +34 -0
- package/browser/dist/errors.js +50 -59
- package/browser/dist/index.js +5 -4
- package/browser/dist/listTagNames.js +1 -3
- package/browser/dist/schema/Alias.js +85 -10
- package/browser/dist/schema/Map.js +14 -121
- package/browser/dist/schema/Merge.js +74 -1
- package/browser/dist/schema/Node.js +1 -3
- package/browser/dist/schema/Pair.js +36 -22
- package/browser/dist/schema/Scalar.js +1 -3
- package/browser/dist/schema/Seq.js +1 -3
- package/browser/dist/schema/index.js +61 -45
- package/browser/dist/schema/parseMap.js +18 -21
- package/browser/dist/schema/parseSeq.js +9 -12
- package/browser/dist/stringify.js +54 -39
- package/browser/dist/{schema → tags}/core.js +32 -20
- package/browser/dist/tags/failsafe/index.js +17 -0
- package/browser/dist/tags/failsafe/map.js +65 -0
- package/browser/dist/tags/failsafe/seq.js +54 -0
- package/browser/dist/{schema/_string.js → tags/failsafe/string.js} +11 -11
- package/browser/dist/tags/index.js +50 -0
- package/browser/dist/{schema → tags}/json.js +8 -8
- package/browser/dist/tags/options.js +35 -0
- package/browser/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +16 -22
- package/browser/dist/{schema/yaml-1.1.js → tags/yaml-1.1/index.js} +43 -29
- package/browser/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +8 -11
- package/browser/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +8 -12
- package/browser/dist/tags/yaml-1.1/set.js +140 -0
- package/browser/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +4 -7
- package/browser/dist/test-events.js +1 -4
- package/browser/dist/toJSON.js +1 -4
- package/browser/index.js +1 -0
- package/browser/map.js +2 -1
- package/browser/pair.js +2 -1
- package/browser/parse-cst.js +1 -1
- package/browser/scalar.js +2 -1
- package/browser/schema.js +7 -4
- package/browser/seq.js +2 -1
- package/browser/types/binary.js +7 -1
- package/browser/types/omap.js +2 -1
- package/browser/types/pairs.js +2 -1
- package/browser/types/set.js +2 -1
- package/browser/types/timestamp.js +10 -1
- package/browser/types.js +11 -0
- package/browser/util.js +15 -0
- package/dist/Anchors.js +1 -3
- package/dist/Document.js +38 -25
- package/dist/constants.js +34 -0
- package/dist/cst/Alias.js +1 -3
- package/dist/cst/BlankLine.js +5 -7
- package/dist/cst/BlockValue.js +4 -4
- package/dist/cst/Collection.js +7 -7
- package/dist/cst/CollectionItem.js +6 -8
- package/dist/cst/Comment.js +5 -7
- package/dist/cst/Directive.js +5 -7
- package/dist/cst/Document.js +8 -10
- package/dist/cst/FlowCollection.js +5 -7
- package/dist/cst/Node.js +12 -40
- package/dist/cst/ParseContext.js +32 -34
- package/dist/cst/PlainValue.js +1 -3
- package/dist/cst/QuoteDouble.js +1 -3
- package/dist/cst/QuoteSingle.js +1 -3
- package/dist/cst/Range.js +1 -3
- package/dist/cst/getLinePos.js +1 -4
- package/dist/cst/parse.js +1 -4
- package/dist/deprecation.js +34 -0
- package/dist/errors.js +29 -35
- package/dist/index.js +5 -4
- package/dist/listTagNames.js +1 -3
- package/dist/schema/Alias.js +66 -12
- package/dist/schema/Map.js +9 -77
- package/dist/schema/Merge.js +31 -0
- package/dist/schema/Node.js +1 -3
- package/dist/schema/Pair.js +29 -15
- package/dist/schema/Scalar.js +1 -3
- package/dist/schema/Seq.js +1 -3
- package/dist/schema/index.js +55 -45
- package/dist/schema/parseMap.js +18 -21
- package/dist/schema/parseSeq.js +9 -12
- package/dist/stringify.js +46 -32
- package/dist/{schema → tags}/core.js +32 -19
- package/dist/tags/failsafe/index.js +17 -0
- package/dist/tags/failsafe/map.js +33 -0
- package/dist/tags/failsafe/seq.js +34 -0
- package/dist/tags/failsafe/string.js +40 -0
- package/dist/tags/index.js +50 -0
- package/dist/{schema → tags}/json.js +8 -8
- package/dist/tags/options.js +35 -0
- package/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +15 -21
- package/dist/{schema/yaml-1.1.js → tags/yaml-1.1/index.js} +43 -30
- package/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +8 -9
- package/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +8 -10
- package/dist/{schema/_set.js → tags/yaml-1.1/set.js} +9 -42
- package/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +4 -7
- package/dist/test-events.js +1 -4
- package/dist/toJSON.js +1 -4
- package/index.js +1 -0
- package/map.js +2 -1
- package/package.json +17 -15
- package/pair.js +2 -1
- package/parse-cst.js +1 -1
- package/scalar.js +2 -1
- package/schema.js +7 -4
- package/seq.js +2 -1
- package/types/binary.js +7 -1
- package/types/omap.js +2 -1
- package/types/pairs.js +2 -1
- package/types/set.js +2 -1
- package/types/timestamp.js +10 -1
- package/types.js +11 -0
- package/util.js +15 -0
- package/browser/dist/schema/_set.js +0 -215
- package/browser/dist/schema/failsafe.js +0 -125
- package/dist/schema/_string.js +0 -40
- package/dist/schema/failsafe.js +0 -74
package/dist/schema/index.js
CHANGED
|
@@ -5,65 +5,80 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _deprecation = require("../deprecation");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _constants = require("../constants");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _errors = require("../errors");
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _stringify = require("../stringify");
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _tags = require("../tags");
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _string = require("../tags/failsafe/string");
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var _Alias = _interopRequireDefault(require("./Alias"));
|
|
21
21
|
|
|
22
|
-
var
|
|
22
|
+
var _Collection = _interopRequireDefault(require("./Collection"));
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var _Node = _interopRequireDefault(require("./Node"));
|
|
25
25
|
|
|
26
26
|
var _Pair = _interopRequireDefault(require("./Pair"));
|
|
27
27
|
|
|
28
28
|
var _Scalar = _interopRequireDefault(require("./Scalar"));
|
|
29
29
|
|
|
30
|
-
var _string = require("./_string");
|
|
31
|
-
|
|
32
|
-
var _yaml = _interopRequireDefault(require("./yaml-1.1"));
|
|
33
|
-
|
|
34
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
35
|
-
|
|
36
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
31
|
|
|
38
32
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
39
33
|
|
|
40
34
|
const isMap = ({
|
|
41
35
|
type
|
|
42
|
-
}) => type ===
|
|
36
|
+
}) => type === _constants.Type.FLOW_MAP || type === _constants.Type.MAP;
|
|
43
37
|
|
|
44
38
|
const isSeq = ({
|
|
45
39
|
type
|
|
46
|
-
}) => type ===
|
|
40
|
+
}) => type === _constants.Type.FLOW_SEQ || type === _constants.Type.SEQ;
|
|
47
41
|
|
|
48
42
|
class Schema {
|
|
49
43
|
constructor({
|
|
44
|
+
customTags,
|
|
50
45
|
merge,
|
|
51
46
|
schema,
|
|
52
|
-
tags
|
|
47
|
+
tags: deprecatedCustomTags
|
|
53
48
|
}) {
|
|
54
49
|
this.merge = !!merge;
|
|
55
50
|
this.name = schema;
|
|
56
|
-
this.tags =
|
|
51
|
+
this.tags = _tags.schemas[schema.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
|
|
57
52
|
|
|
58
53
|
if (!this.tags) {
|
|
59
|
-
const keys = Object.keys(
|
|
60
|
-
throw new Error(`Unknown schema; use one of ${keys
|
|
54
|
+
const keys = Object.keys(_tags.schemas).map(key => JSON.stringify(key)).join(', ');
|
|
55
|
+
throw new Error(`Unknown schema "${schema}"; use one of ${keys}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!customTags && deprecatedCustomTags) {
|
|
59
|
+
customTags = deprecatedCustomTags;
|
|
60
|
+
(0, _deprecation.warnOptionDeprecation)('tags', 'customTags');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (Array.isArray(customTags)) {
|
|
64
|
+
for (const tag of customTags) this.tags = this.tags.concat(tag);
|
|
65
|
+
} else if (typeof customTags === 'function') {
|
|
66
|
+
this.tags = customTags(this.tags.slice());
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
for (let i = 0; i < this.tags.length; ++i) {
|
|
70
|
+
const tag = this.tags[i];
|
|
71
|
+
|
|
72
|
+
if (typeof tag === 'string') {
|
|
73
|
+
const tagObj = _tags.tags[tag];
|
|
74
|
+
|
|
75
|
+
if (!tagObj) {
|
|
76
|
+
const keys = Object.keys(_tags.tags).map(key => JSON.stringify(key)).join(', ');
|
|
77
|
+
throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.tags[i] = tagObj;
|
|
81
|
+
}
|
|
67
82
|
}
|
|
68
83
|
}
|
|
69
84
|
|
|
@@ -82,7 +97,7 @@ class Schema {
|
|
|
82
97
|
if (!tagObj) {
|
|
83
98
|
if (typeof value.toJSON === 'function') value = value.toJSON();
|
|
84
99
|
if (typeof value !== 'object') return wrapScalars ? new _Scalar.default(value) : value;
|
|
85
|
-
tagObj = value instanceof Map ?
|
|
100
|
+
tagObj = value instanceof Map ? _tags.tags.map : value[Symbol.iterator] ? _tags.tags.seq : _tags.tags.map;
|
|
86
101
|
}
|
|
87
102
|
}
|
|
88
103
|
|
|
@@ -113,6 +128,12 @@ class Schema {
|
|
|
113
128
|
|
|
114
129
|
obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new _Scalar.default(value) : value;
|
|
115
130
|
return obj.node;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
createPair(key, value, ctx) {
|
|
134
|
+
const k = this.createNode(key, ctx.wrapScalars, null, ctx);
|
|
135
|
+
const v = this.createNode(value, ctx.wrapScalars, null, ctx);
|
|
136
|
+
return new _Pair.default(k, v);
|
|
116
137
|
} // falls back to string on no match
|
|
117
138
|
|
|
118
139
|
|
|
@@ -130,7 +151,8 @@ class Schema {
|
|
|
130
151
|
const match = str.match(test);
|
|
131
152
|
|
|
132
153
|
if (match) {
|
|
133
|
-
|
|
154
|
+
let res = resolve.apply(null, match);
|
|
155
|
+
if (!(res instanceof _Scalar.default)) res = new _Scalar.default(res);
|
|
134
156
|
if (format) res.format = format;
|
|
135
157
|
return res;
|
|
136
158
|
}
|
|
@@ -157,7 +179,7 @@ class Schema {
|
|
|
157
179
|
if (!(res instanceof _Collection.default)) res = new _Scalar.default(res);
|
|
158
180
|
node.resolved = res;
|
|
159
181
|
} else {
|
|
160
|
-
const str = (0, _string.
|
|
182
|
+
const str = (0, _string.resolveString)(doc, node);
|
|
161
183
|
|
|
162
184
|
if (typeof str === 'string' && tags.length > 0) {
|
|
163
185
|
node.resolved = this.resolveScalar(str, tags);
|
|
@@ -170,7 +192,7 @@ class Schema {
|
|
|
170
192
|
}
|
|
171
193
|
|
|
172
194
|
if (!node.resolved) return null;
|
|
173
|
-
if (tagName) node.resolved.tag = tagName;
|
|
195
|
+
if (tagName && node.tag) node.resolved.tag = tagName;
|
|
174
196
|
return node.resolved;
|
|
175
197
|
}
|
|
176
198
|
|
|
@@ -232,7 +254,7 @@ class Schema {
|
|
|
232
254
|
props.push(`&${anchor}`);
|
|
233
255
|
}
|
|
234
256
|
|
|
235
|
-
if (node.tag
|
|
257
|
+
if (node.tag) {
|
|
236
258
|
props.push(doc.stringifyTag(node.tag));
|
|
237
259
|
} else if (!tagObj.default) {
|
|
238
260
|
props.push(doc.stringifyTag(tagObj.tag));
|
|
@@ -244,7 +266,7 @@ class Schema {
|
|
|
244
266
|
stringify(item, ctx, onComment, onChompKeep) {
|
|
245
267
|
let tagObj;
|
|
246
268
|
|
|
247
|
-
if (!(item instanceof
|
|
269
|
+
if (!(item instanceof _Node.default)) {
|
|
248
270
|
const createCtx = {
|
|
249
271
|
aliasNodes: [],
|
|
250
272
|
onTagObj: o => tagObj = o,
|
|
@@ -270,9 +292,7 @@ class Schema {
|
|
|
270
292
|
if (item instanceof _Pair.default) return item.toString(ctx, onComment, onChompKeep);
|
|
271
293
|
if (!tagObj) tagObj = this.getTagObject(item);
|
|
272
294
|
const props = this.stringifyProps(item, tagObj, ctx);
|
|
273
|
-
|
|
274
|
-
const str = (tagObj.stringify || _stringify.default)(item, ctx, onComment, onChompKeep);
|
|
275
|
-
|
|
295
|
+
const str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof _Collection.default ? item.toString(ctx, onComment, onChompKeep) : (0, _stringify.stringifyString)(item, ctx, onComment, onChompKeep);
|
|
276
296
|
return props ? item instanceof _Collection.default && str[0] !== '{' && str[0] !== '[' ? `${props}\n${ctx.indent}${str}` : `${props} ${str}` : str;
|
|
277
297
|
}
|
|
278
298
|
|
|
@@ -286,14 +306,4 @@ _defineProperty(Schema, "defaultTags", {
|
|
|
286
306
|
MAP: 'tag:yaml.org,2002:map',
|
|
287
307
|
SEQ: 'tag:yaml.org,2002:seq',
|
|
288
308
|
STR: 'tag:yaml.org,2002:str'
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
_defineProperty(Schema, "tags", {
|
|
292
|
-
core: _core.default,
|
|
293
|
-
failsafe: _failsafe.default,
|
|
294
|
-
json: _json.default,
|
|
295
|
-
'yaml-1.1': _yaml.default
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
module.exports = exports.default;
|
|
299
|
-
module.exports.default = exports.default;
|
|
309
|
+
});
|
package/dist/schema/parseMap.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = parseMap;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _constants = require("../constants");
|
|
9
9
|
|
|
10
10
|
var _PlainValue = _interopRequireDefault(require("../cst/PlainValue"));
|
|
11
11
|
|
|
@@ -26,7 +26,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
26
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
27
|
|
|
28
28
|
function parseMap(doc, cst) {
|
|
29
|
-
if (cst.type !==
|
|
29
|
+
if (cst.type !== _constants.Type.MAP && cst.type !== _constants.Type.FLOW_MAP) {
|
|
30
30
|
const msg = `A ${cst.type} node cannot be resolved as a mapping`;
|
|
31
31
|
doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
|
|
32
32
|
return null;
|
|
@@ -35,7 +35,7 @@ function parseMap(doc, cst) {
|
|
|
35
35
|
const {
|
|
36
36
|
comments,
|
|
37
37
|
items
|
|
38
|
-
} = cst.type ===
|
|
38
|
+
} = cst.type === _constants.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst);
|
|
39
39
|
const map = new _Map.default();
|
|
40
40
|
map.items = items;
|
|
41
41
|
(0, _parseUtils.resolveComments)(map, comments);
|
|
@@ -56,7 +56,7 @@ function parseMap(doc, cst) {
|
|
|
56
56
|
const {
|
|
57
57
|
type
|
|
58
58
|
} = node.source;
|
|
59
|
-
if (type ===
|
|
59
|
+
if (type === _constants.Type.MAP || type === _constants.Type.FLOW_MAP) return false;
|
|
60
60
|
return error = 'Merge nodes aliases can only point to maps';
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -95,7 +95,7 @@ const valueHasPairComment = ({
|
|
|
95
95
|
start
|
|
96
96
|
} = props[0];
|
|
97
97
|
if (node && start > node.valueRange.start) return false;
|
|
98
|
-
if (src[start] !==
|
|
98
|
+
if (src[start] !== _constants.Char.COMMENT) return false;
|
|
99
99
|
|
|
100
100
|
for (let i = lineStart; i < start; ++i) if (src[i] === '\n') return false;
|
|
101
101
|
|
|
@@ -104,7 +104,7 @@ const valueHasPairComment = ({
|
|
|
104
104
|
|
|
105
105
|
function resolvePairComment(item, pair) {
|
|
106
106
|
if (!valueHasPairComment(item)) return;
|
|
107
|
-
const comment = item.getPropValue(0,
|
|
107
|
+
const comment = item.getPropValue(0, _constants.Char.COMMENT, true);
|
|
108
108
|
let found = false;
|
|
109
109
|
const cb = pair.value.commentBefore;
|
|
110
110
|
|
|
@@ -133,14 +133,14 @@ function resolveBlockMapItems(doc, cst) {
|
|
|
133
133
|
const item = cst.items[i];
|
|
134
134
|
|
|
135
135
|
switch (item.type) {
|
|
136
|
-
case
|
|
136
|
+
case _constants.Type.BLANK_LINE:
|
|
137
137
|
comments.push({
|
|
138
138
|
afterKey: !!key,
|
|
139
139
|
before: items.length
|
|
140
140
|
});
|
|
141
141
|
break;
|
|
142
142
|
|
|
143
|
-
case
|
|
143
|
+
case _constants.Type.COMMENT:
|
|
144
144
|
comments.push({
|
|
145
145
|
afterKey: !!key,
|
|
146
146
|
before: items.length,
|
|
@@ -148,19 +148,19 @@ function resolveBlockMapItems(doc, cst) {
|
|
|
148
148
|
});
|
|
149
149
|
break;
|
|
150
150
|
|
|
151
|
-
case
|
|
151
|
+
case _constants.Type.MAP_KEY:
|
|
152
152
|
if (key !== undefined) items.push(new _Pair.default(key));
|
|
153
153
|
if (item.error) doc.errors.push(item.error);
|
|
154
154
|
key = doc.resolveNode(item.node);
|
|
155
155
|
keyStart = null;
|
|
156
156
|
break;
|
|
157
157
|
|
|
158
|
-
case
|
|
158
|
+
case _constants.Type.MAP_VALUE:
|
|
159
159
|
{
|
|
160
160
|
if (key === undefined) key = null;
|
|
161
161
|
if (item.error) doc.errors.push(item.error);
|
|
162
162
|
|
|
163
|
-
if (!item.context.atLineStart && item.node && item.node.type ===
|
|
163
|
+
if (!item.context.atLineStart && item.node && item.node.type === _constants.Type.MAP && !item.node.context.atLineStart) {
|
|
164
164
|
const msg = 'Nested mappings are not allowed in compact mappings';
|
|
165
165
|
doc.errors.push(new _errors.YAMLSemanticError(item.node, msg));
|
|
166
166
|
}
|
|
@@ -171,7 +171,7 @@ function resolveBlockMapItems(doc, cst) {
|
|
|
171
171
|
// Comments on an empty mapping value need to be preserved, so we
|
|
172
172
|
// need to construct a minimal empty node here to use instead of the
|
|
173
173
|
// missing `item.node`. -- eemeli/yaml#19
|
|
174
|
-
valueNode = new _PlainValue.default(
|
|
174
|
+
valueNode = new _PlainValue.default(_constants.Type.PLAIN, []);
|
|
175
175
|
valueNode.context = {
|
|
176
176
|
parent: item,
|
|
177
177
|
src: item.context.src
|
|
@@ -212,11 +212,11 @@ function resolveBlockMapItems(doc, cst) {
|
|
|
212
212
|
const nextItem = cst.items[j];
|
|
213
213
|
|
|
214
214
|
switch (nextItem && nextItem.type) {
|
|
215
|
-
case
|
|
216
|
-
case
|
|
215
|
+
case _constants.Type.BLANK_LINE:
|
|
216
|
+
case _constants.Type.COMMENT:
|
|
217
217
|
continue next;
|
|
218
218
|
|
|
219
|
-
case
|
|
219
|
+
case _constants.Type.MAP_VALUE:
|
|
220
220
|
break next;
|
|
221
221
|
|
|
222
222
|
default:
|
|
@@ -296,12 +296,12 @@ function resolveFlowMapItems(doc, cst) {
|
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
doc.errors.push(new _errors.YAMLSyntaxError(cst, `Flow map contains an unexpected ${char}`));
|
|
299
|
-
} else if (item.type ===
|
|
299
|
+
} else if (item.type === _constants.Type.BLANK_LINE) {
|
|
300
300
|
comments.push({
|
|
301
301
|
afterKey: !!key,
|
|
302
302
|
before: items.length
|
|
303
303
|
});
|
|
304
|
-
} else if (item.type ===
|
|
304
|
+
} else if (item.type === _constants.Type.COMMENT) {
|
|
305
305
|
comments.push({
|
|
306
306
|
afterKey: !!key,
|
|
307
307
|
before: items.length,
|
|
@@ -325,7 +325,4 @@ function resolveFlowMapItems(doc, cst) {
|
|
|
325
325
|
comments,
|
|
326
326
|
items
|
|
327
327
|
};
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
module.exports = exports.default;
|
|
331
|
-
module.exports.default = exports.default;
|
|
328
|
+
}
|
package/dist/schema/parseSeq.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = parseSeq;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _constants = require("../constants");
|
|
9
9
|
|
|
10
10
|
var _errors = require("../errors");
|
|
11
11
|
|
|
@@ -18,7 +18,7 @@ var _Seq = _interopRequireDefault(require("./Seq"));
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
|
|
20
20
|
function parseSeq(doc, cst) {
|
|
21
|
-
if (cst.type !==
|
|
21
|
+
if (cst.type !== _constants.Type.SEQ && cst.type !== _constants.Type.FLOW_SEQ) {
|
|
22
22
|
const msg = `A ${cst.type} node cannot be resolved as a sequence`;
|
|
23
23
|
doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
|
|
24
24
|
return null;
|
|
@@ -27,7 +27,7 @@ function parseSeq(doc, cst) {
|
|
|
27
27
|
const {
|
|
28
28
|
comments,
|
|
29
29
|
items
|
|
30
|
-
} = cst.type ===
|
|
30
|
+
} = cst.type === _constants.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst);
|
|
31
31
|
const seq = new _Seq.default();
|
|
32
32
|
seq.items = items;
|
|
33
33
|
(0, _parseUtils.resolveComments)(seq, comments);
|
|
@@ -43,20 +43,20 @@ function resolveBlockSeqItems(doc, cst) {
|
|
|
43
43
|
const item = cst.items[i];
|
|
44
44
|
|
|
45
45
|
switch (item.type) {
|
|
46
|
-
case
|
|
46
|
+
case _constants.Type.BLANK_LINE:
|
|
47
47
|
comments.push({
|
|
48
48
|
before: items.length
|
|
49
49
|
});
|
|
50
50
|
break;
|
|
51
51
|
|
|
52
|
-
case
|
|
52
|
+
case _constants.Type.COMMENT:
|
|
53
53
|
comments.push({
|
|
54
54
|
comment: item.comment,
|
|
55
55
|
before: items.length
|
|
56
56
|
});
|
|
57
57
|
break;
|
|
58
58
|
|
|
59
|
-
case
|
|
59
|
+
case _constants.Type.SEQ_ITEM:
|
|
60
60
|
if (item.error) doc.errors.push(item.error);
|
|
61
61
|
items.push(doc.resolveNode(item.node));
|
|
62
62
|
|
|
@@ -129,11 +129,11 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
129
129
|
const msg = `Flow sequence contains an unexpected ${char}`;
|
|
130
130
|
doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
|
|
131
131
|
}
|
|
132
|
-
} else if (item.type ===
|
|
132
|
+
} else if (item.type === _constants.Type.BLANK_LINE) {
|
|
133
133
|
comments.push({
|
|
134
134
|
before: items.length
|
|
135
135
|
});
|
|
136
|
-
} else if (item.type ===
|
|
136
|
+
} else if (item.type === _constants.Type.COMMENT) {
|
|
137
137
|
comments.push({
|
|
138
138
|
comment: item.comment,
|
|
139
139
|
before: items.length
|
|
@@ -164,7 +164,4 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
164
164
|
comments,
|
|
165
165
|
items
|
|
166
166
|
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
module.exports = exports.default;
|
|
170
|
-
module.exports.default = exports.default;
|
|
167
|
+
}
|
package/dist/stringify.js
CHANGED
|
@@ -3,29 +3,43 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
6
|
+
exports.stringifyNumber = stringifyNumber;
|
|
7
|
+
exports.stringifyString = stringifyString;
|
|
8
8
|
|
|
9
9
|
var _addComment = require("./addComment");
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _constants = require("./constants");
|
|
12
12
|
|
|
13
13
|
var _foldFlowLines = _interopRequireWildcard(require("./foldFlowLines"));
|
|
14
14
|
|
|
15
|
+
var _options = require("./tags/options");
|
|
16
|
+
|
|
15
17
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
function stringifyNumber({
|
|
20
|
+
format,
|
|
21
|
+
minFractionDigits,
|
|
22
|
+
tag,
|
|
23
|
+
value
|
|
24
|
+
}) {
|
|
25
|
+
if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
|
|
26
|
+
let n = JSON.stringify(value);
|
|
27
|
+
|
|
28
|
+
if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && /^\d/.test(n)) {
|
|
29
|
+
let i = n.indexOf('.');
|
|
30
|
+
|
|
31
|
+
if (i < 0) {
|
|
32
|
+
i = n.length;
|
|
33
|
+
n += '.';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let d = minFractionDigits - (n.length - i - 1);
|
|
37
|
+
|
|
38
|
+
while (d-- > 0) n += '0';
|
|
26
39
|
}
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
|
|
41
|
+
return n;
|
|
42
|
+
}
|
|
29
43
|
|
|
30
44
|
function lineLengthOverLimit(str, limit) {
|
|
31
45
|
const strLen = str.length;
|
|
@@ -49,7 +63,7 @@ function doubleQuotedString(value, {
|
|
|
49
63
|
const {
|
|
50
64
|
jsonEncoding,
|
|
51
65
|
minMultiLineLength
|
|
52
|
-
} = strOptions.doubleQuoted;
|
|
66
|
+
} = _options.strOptions.doubleQuoted;
|
|
53
67
|
const json = JSON.stringify(value);
|
|
54
68
|
if (jsonEncoding) return json;
|
|
55
69
|
let str = '';
|
|
@@ -139,7 +153,7 @@ function doubleQuotedString(value, {
|
|
|
139
153
|
}
|
|
140
154
|
|
|
141
155
|
str = start ? str + json.slice(start) : json;
|
|
142
|
-
return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, strOptions.fold);
|
|
156
|
+
return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, _options.strOptions.fold);
|
|
143
157
|
}
|
|
144
158
|
|
|
145
159
|
function singleQuotedString(value, ctx) {
|
|
@@ -156,7 +170,7 @@ function singleQuotedString(value, ctx) {
|
|
|
156
170
|
}
|
|
157
171
|
|
|
158
172
|
const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
|
|
159
|
-
return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, strOptions.fold);
|
|
173
|
+
return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold);
|
|
160
174
|
}
|
|
161
175
|
|
|
162
176
|
function blockString({
|
|
@@ -173,7 +187,7 @@ function blockString({
|
|
|
173
187
|
const indent = ctx.indent || (ctx.forceBlockIndent ? ' ' : '');
|
|
174
188
|
const indentSize = indent ? '2' : '1'; // root is at -1
|
|
175
189
|
|
|
176
|
-
const literal = type ===
|
|
190
|
+
const literal = type === _constants.Type.BLOCK_FOLDED ? false : type === _constants.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, _options.strOptions.fold.lineWidth - indent.length);
|
|
177
191
|
let header = literal ? '|' : '>';
|
|
178
192
|
if (!value) return header + '\n';
|
|
179
193
|
let wsStart = '';
|
|
@@ -221,7 +235,7 @@ function blockString({
|
|
|
221
235
|
value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
|
|
222
236
|
// ^ ind.line ^ empty ^ capture next empty lines only at end of indent
|
|
223
237
|
.replace(/\n+/g, `$&${indent}`);
|
|
224
|
-
const body = (0, _foldFlowLines.default)(`${wsStart}${value}${wsEnd}`, indent, _foldFlowLines.FOLD_BLOCK, strOptions.fold);
|
|
238
|
+
const body = (0, _foldFlowLines.default)(`${wsStart}${value}${wsEnd}`, indent, _foldFlowLines.FOLD_BLOCK, _options.strOptions.fold);
|
|
225
239
|
return `${header}\n${indent}${body}`;
|
|
226
240
|
}
|
|
227
241
|
|
|
@@ -253,7 +267,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
253
267
|
return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
|
|
254
268
|
}
|
|
255
269
|
|
|
256
|
-
if (!implicitKey && !inFlow && type !==
|
|
270
|
+
if (!implicitKey && !inFlow && type !== _constants.Type.PLAIN && value.indexOf('\n') !== -1) {
|
|
257
271
|
// Where allowed & type not set explicitly, prefer block style for multiline strings
|
|
258
272
|
return blockString(item, ctx, onComment, onChompKeep);
|
|
259
273
|
}
|
|
@@ -265,7 +279,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
265
279
|
return doubleQuotedString(value, ctx);
|
|
266
280
|
}
|
|
267
281
|
|
|
268
|
-
const body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, strOptions.fold);
|
|
282
|
+
const body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold);
|
|
269
283
|
|
|
270
284
|
if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
|
|
271
285
|
if (onComment) onComment();
|
|
@@ -275,10 +289,10 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
275
289
|
return body;
|
|
276
290
|
}
|
|
277
291
|
|
|
278
|
-
function
|
|
292
|
+
function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
279
293
|
const {
|
|
280
294
|
defaultType
|
|
281
|
-
} = strOptions;
|
|
295
|
+
} = _options.strOptions;
|
|
282
296
|
const {
|
|
283
297
|
implicitKey,
|
|
284
298
|
inFlow
|
|
@@ -297,17 +311,17 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
297
311
|
|
|
298
312
|
const _stringify = _type => {
|
|
299
313
|
switch (_type) {
|
|
300
|
-
case
|
|
301
|
-
case
|
|
314
|
+
case _constants.Type.BLOCK_FOLDED:
|
|
315
|
+
case _constants.Type.BLOCK_LITERAL:
|
|
302
316
|
return blockString(item, ctx, onComment, onChompKeep);
|
|
303
317
|
|
|
304
|
-
case
|
|
318
|
+
case _constants.Type.QUOTE_DOUBLE:
|
|
305
319
|
return doubleQuotedString(value, ctx);
|
|
306
320
|
|
|
307
|
-
case
|
|
321
|
+
case _constants.Type.QUOTE_SINGLE:
|
|
308
322
|
return singleQuotedString(value, ctx);
|
|
309
323
|
|
|
310
|
-
case
|
|
324
|
+
case _constants.Type.PLAIN:
|
|
311
325
|
return plainString(item, ctx, onComment, onChompKeep);
|
|
312
326
|
|
|
313
327
|
default:
|
|
@@ -315,12 +329,12 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
315
329
|
}
|
|
316
330
|
};
|
|
317
331
|
|
|
318
|
-
if (type !==
|
|
332
|
+
if (type !== _constants.Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
|
|
319
333
|
// force double quotes on control characters
|
|
320
|
-
type =
|
|
321
|
-
} else if ((implicitKey || inFlow) && (type ===
|
|
334
|
+
type = _constants.Type.QUOTE_DOUBLE;
|
|
335
|
+
} else if ((implicitKey || inFlow) && (type === _constants.Type.BLOCK_FOLDED || type === _constants.Type.BLOCK_LITERAL)) {
|
|
322
336
|
// should not happen; blocks are not valid inside flow containers
|
|
323
|
-
type =
|
|
337
|
+
type = _constants.Type.QUOTE_DOUBLE;
|
|
324
338
|
}
|
|
325
339
|
|
|
326
340
|
let res = _stringify(type);
|
|
@@ -3,23 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _Scalar = _interopRequireDefault(require("../schema/Scalar"));
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _stringify = require("../stringify");
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
var _failsafe = _interopRequireDefault(require("./failsafe"));
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
value
|
|
16
|
-
}) => isFinite(value) ? JSON.stringify(value) : isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
|
|
14
|
+
var _options = require("./options");
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
const nullOptions = {
|
|
20
|
-
nullStr: 'null'
|
|
21
|
-
};
|
|
22
|
-
exports.nullOptions = nullOptions;
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
17
|
|
|
24
18
|
var _default = _failsafe.default.concat([{
|
|
25
19
|
identify: value => value == null,
|
|
@@ -28,15 +22,18 @@ var _default = _failsafe.default.concat([{
|
|
|
28
22
|
tag: 'tag:yaml.org,2002:null',
|
|
29
23
|
test: /^(?:~|[Nn]ull|NULL)?$/,
|
|
30
24
|
resolve: () => null,
|
|
31
|
-
options: nullOptions,
|
|
32
|
-
stringify: () => nullOptions.nullStr
|
|
25
|
+
options: _options.nullOptions,
|
|
26
|
+
stringify: () => _options.nullOptions.nullStr
|
|
33
27
|
}, {
|
|
34
28
|
identify: value => typeof value === 'boolean',
|
|
35
29
|
default: true,
|
|
36
30
|
tag: 'tag:yaml.org,2002:bool',
|
|
37
31
|
test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
|
|
38
32
|
resolve: str => str[0] === 't' || str[0] === 'T',
|
|
39
|
-
|
|
33
|
+
options: _options.boolOptions,
|
|
34
|
+
stringify: ({
|
|
35
|
+
value
|
|
36
|
+
}) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr
|
|
40
37
|
}, {
|
|
41
38
|
identify: value => typeof value === 'number',
|
|
42
39
|
default: true,
|
|
@@ -53,7 +50,7 @@ var _default = _failsafe.default.concat([{
|
|
|
53
50
|
tag: 'tag:yaml.org,2002:int',
|
|
54
51
|
test: /^[-+]?[0-9]+$/,
|
|
55
52
|
resolve: str => parseInt(str, 10),
|
|
56
|
-
stringify: stringifyNumber
|
|
53
|
+
stringify: _stringify.stringifyNumber
|
|
57
54
|
}, {
|
|
58
55
|
identify: value => typeof value === 'number',
|
|
59
56
|
default: true,
|
|
@@ -70,14 +67,30 @@ var _default = _failsafe.default.concat([{
|
|
|
70
67
|
tag: 'tag:yaml.org,2002:float',
|
|
71
68
|
test: /^(?:[-+]?\.inf|(\.nan))$/i,
|
|
72
69
|
resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
|
|
73
|
-
stringify: stringifyNumber
|
|
70
|
+
stringify: _stringify.stringifyNumber
|
|
74
71
|
}, {
|
|
75
72
|
identify: value => typeof value === 'number',
|
|
76
73
|
default: true,
|
|
77
74
|
tag: 'tag:yaml.org,2002:float',
|
|
78
|
-
|
|
75
|
+
format: 'EXP',
|
|
76
|
+
test: /^[-+]?(?:0|[1-9][0-9]*)(\.[0-9]*)?[eE][-+]?[0-9]+$/,
|
|
79
77
|
resolve: str => parseFloat(str),
|
|
80
|
-
stringify:
|
|
78
|
+
stringify: ({
|
|
79
|
+
value
|
|
80
|
+
}) => Number(value).toExponential()
|
|
81
|
+
}, {
|
|
82
|
+
identify: value => typeof value === 'number',
|
|
83
|
+
default: true,
|
|
84
|
+
tag: 'tag:yaml.org,2002:float',
|
|
85
|
+
test: /^[-+]?(?:0|[1-9][0-9]*)\.([0-9]*)$/,
|
|
86
|
+
|
|
87
|
+
resolve(str, frac) {
|
|
88
|
+
const node = new _Scalar.default(parseFloat(str));
|
|
89
|
+
if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
|
|
90
|
+
return node;
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
stringify: _stringify.stringifyNumber
|
|
81
94
|
}]);
|
|
82
95
|
|
|
83
96
|
exports.default = _default;
|