yaml 1.7.2 → 1.8.3
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/browser/dist/Anchors.js +24 -39
- package/browser/dist/Document.js +86 -110
- package/browser/dist/addComment.js +2 -11
- package/browser/dist/constants.js +3 -11
- package/browser/dist/cst/Alias.js +19 -36
- package/browser/dist/cst/BlankLine.js +25 -38
- package/browser/dist/cst/BlockValue.js +29 -51
- package/browser/dist/cst/Collection.js +42 -65
- package/browser/dist/cst/CollectionItem.js +33 -55
- package/browser/dist/cst/Comment.js +19 -35
- package/browser/dist/cst/Directive.js +20 -56
- package/browser/dist/cst/Document.js +47 -71
- package/browser/dist/cst/FlowCollection.js +38 -61
- package/browser/dist/cst/Node.js +26 -46
- package/browser/dist/cst/ParseContext.js +100 -140
- package/browser/dist/cst/PlainValue.js +21 -38
- package/browser/dist/cst/QuoteDouble.js +26 -42
- package/browser/dist/cst/QuoteSingle.js +25 -41
- package/browser/dist/cst/Range.js +9 -19
- package/browser/dist/cst/parse.js +5 -16
- package/browser/dist/cst/source-utils.js +3 -14
- package/browser/dist/errors.js +42 -78
- package/browser/dist/foldFlowLines.js +4 -15
- package/browser/dist/index.js +24 -44
- package/browser/dist/listTagNames.js +10 -24
- package/browser/dist/schema/Alias.js +32 -49
- package/browser/dist/schema/Collection.js +54 -65
- package/browser/dist/schema/Map.js +39 -49
- package/browser/dist/schema/Merge.js +32 -52
- package/browser/dist/schema/Node.js +3 -12
- package/browser/dist/schema/Pair.js +40 -58
- package/browser/dist/schema/Scalar.js +18 -33
- package/browser/dist/schema/Seq.js +23 -40
- package/browser/dist/schema/index.js +66 -81
- package/browser/dist/schema/parseMap.js +52 -72
- package/browser/dist/schema/parseSeq.js +30 -45
- package/browser/dist/schema/parseUtils.js +12 -25
- package/browser/dist/stringify.js +39 -45
- package/browser/dist/tags/core.js +34 -40
- package/browser/dist/tags/failsafe/index.js +4 -17
- package/browser/dist/tags/failsafe/map.js +15 -24
- package/browser/dist/tags/failsafe/seq.js +7 -18
- package/browser/dist/tags/failsafe/string.js +7 -19
- package/browser/dist/tags/index.js +35 -49
- package/browser/dist/tags/json.js +11 -38
- package/browser/dist/tags/options.js +8 -20
- package/browser/dist/tags/yaml-1.1/binary.js +22 -33
- package/browser/dist/tags/yaml-1.1/index.js +34 -54
- package/browser/dist/tags/yaml-1.1/omap.js +39 -58
- package/browser/dist/tags/yaml-1.1/pairs.js +15 -34
- package/browser/dist/tags/yaml-1.1/set.js +35 -61
- package/browser/dist/tags/yaml-1.1/timestamp.js +6 -16
- package/browser/dist/test-events.js +7 -19
- package/browser/dist/toJSON.js +1 -8
- package/browser/dist/warnings.js +3 -15
- package/dist/Document.js +1 -1
- package/dist/cst/BlankLine.js +4 -0
- package/dist/cst/BlockValue.js +1 -1
- package/dist/cst/Directive.js +0 -16
- package/dist/cst/Node.js +0 -5
- package/dist/cst/ParseContext.js +41 -55
- package/dist/schema/Alias.js +1 -0
- package/dist/schema/Collection.js +22 -5
- package/dist/schema/Map.js +12 -5
- package/dist/schema/Pair.js +1 -0
- package/dist/schema/index.js +10 -5
- package/dist/schema/parseMap.js +1 -1
- package/dist/stringify.js +15 -8
- package/dist/tags/core.js +31 -13
- package/dist/tags/failsafe/map.js +5 -1
- package/dist/tags/failsafe/seq.js +1 -1
- package/dist/tags/index.js +13 -1
- package/dist/tags/json.js +2 -9
- package/dist/tags/yaml-1.1/binary.js +8 -5
- package/dist/tags/yaml-1.1/index.js +6 -6
- package/dist/tags/yaml-1.1/pairs.js +1 -1
- package/dist/tags/yaml-1.1/set.js +1 -1
- package/package.json +43 -17
- package/types.mjs +20 -0
- package/util.mjs +24 -0
package/dist/cst/ParseContext.js
CHANGED
|
@@ -33,6 +33,41 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
33
33
|
|
|
34
34
|
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; }
|
|
35
35
|
|
|
36
|
+
function createNewNode(type, props) {
|
|
37
|
+
switch (type) {
|
|
38
|
+
case _constants.Type.ALIAS:
|
|
39
|
+
return new _Alias.default(type, props);
|
|
40
|
+
|
|
41
|
+
case _constants.Type.BLOCK_FOLDED:
|
|
42
|
+
case _constants.Type.BLOCK_LITERAL:
|
|
43
|
+
return new _BlockValue.default(type, props);
|
|
44
|
+
|
|
45
|
+
case _constants.Type.FLOW_MAP:
|
|
46
|
+
case _constants.Type.FLOW_SEQ:
|
|
47
|
+
return new _FlowCollection.default(type, props);
|
|
48
|
+
|
|
49
|
+
case _constants.Type.MAP_KEY:
|
|
50
|
+
case _constants.Type.MAP_VALUE:
|
|
51
|
+
case _constants.Type.SEQ_ITEM:
|
|
52
|
+
return new _CollectionItem.default(type, props);
|
|
53
|
+
|
|
54
|
+
case _constants.Type.COMMENT:
|
|
55
|
+
case _constants.Type.PLAIN:
|
|
56
|
+
return new _PlainValue.default(type, props);
|
|
57
|
+
|
|
58
|
+
case _constants.Type.QUOTE_DOUBLE:
|
|
59
|
+
return new _QuoteDouble.default(type, props);
|
|
60
|
+
|
|
61
|
+
case _constants.Type.QUOTE_SINGLE:
|
|
62
|
+
return new _QuoteSingle.default(type, props);
|
|
63
|
+
|
|
64
|
+
/* istanbul ignore next */
|
|
65
|
+
|
|
66
|
+
default:
|
|
67
|
+
return null;
|
|
68
|
+
// should never happen
|
|
69
|
+
}
|
|
70
|
+
}
|
|
36
71
|
/**
|
|
37
72
|
* @param {boolean} atLineStart - Node starts at beginning of line
|
|
38
73
|
* @param {boolean} inFlow - true if currently in a flow context
|
|
@@ -42,6 +77,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
42
77
|
* @param {Node} parent - The parent of the node
|
|
43
78
|
* @param {string} src - Source of the YAML document
|
|
44
79
|
*/
|
|
80
|
+
|
|
81
|
+
|
|
45
82
|
class ParseContext {
|
|
46
83
|
static parseType(src, offset, inFlow) {
|
|
47
84
|
switch (src[offset]) {
|
|
@@ -96,52 +133,14 @@ class ParseContext {
|
|
|
96
133
|
type,
|
|
97
134
|
valueStart
|
|
98
135
|
} = context.parseProps(start);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
switch (type) {
|
|
102
|
-
case _constants.Type.ALIAS:
|
|
103
|
-
node = new _Alias.default(type, props);
|
|
104
|
-
break;
|
|
105
|
-
|
|
106
|
-
case _constants.Type.BLOCK_FOLDED:
|
|
107
|
-
case _constants.Type.BLOCK_LITERAL:
|
|
108
|
-
node = new _BlockValue.default(type, props);
|
|
109
|
-
break;
|
|
110
|
-
|
|
111
|
-
case _constants.Type.FLOW_MAP:
|
|
112
|
-
case _constants.Type.FLOW_SEQ:
|
|
113
|
-
node = new _FlowCollection.default(type, props);
|
|
114
|
-
break;
|
|
115
|
-
|
|
116
|
-
case _constants.Type.MAP_KEY:
|
|
117
|
-
case _constants.Type.MAP_VALUE:
|
|
118
|
-
case _constants.Type.SEQ_ITEM:
|
|
119
|
-
node = new _CollectionItem.default(type, props);
|
|
120
|
-
break;
|
|
121
|
-
|
|
122
|
-
case _constants.Type.COMMENT:
|
|
123
|
-
case _constants.Type.PLAIN:
|
|
124
|
-
node = new _PlainValue.default(type, props);
|
|
125
|
-
break;
|
|
126
|
-
|
|
127
|
-
case _constants.Type.QUOTE_DOUBLE:
|
|
128
|
-
node = new _QuoteDouble.default(type, props);
|
|
129
|
-
break;
|
|
130
|
-
|
|
131
|
-
case _constants.Type.QUOTE_SINGLE:
|
|
132
|
-
node = new _QuoteSingle.default(type, props);
|
|
133
|
-
break;
|
|
134
|
-
|
|
135
|
-
default:
|
|
136
|
-
node.error = new _errors.YAMLSyntaxError(node, `Unknown node type: ${JSON.stringify(type)}`);
|
|
137
|
-
node.range = new _Range.default(start, start + 1);
|
|
138
|
-
return node;
|
|
139
|
-
}
|
|
140
|
-
|
|
136
|
+
const node = createNewNode(type, props);
|
|
141
137
|
let offset = node.parse(context, valueStart);
|
|
142
138
|
node.range = new _Range.default(start, offset);
|
|
139
|
+
/* istanbul ignore if */
|
|
143
140
|
|
|
144
141
|
if (offset <= start) {
|
|
142
|
+
// This should never happen, but if it does, let's make sure to at least
|
|
143
|
+
// step one character forward to avoid a busy loop.
|
|
145
144
|
node.error = new Error(`Node#parse consumed no characters`);
|
|
146
145
|
node.error.parseEnd = offset;
|
|
147
146
|
node.error.source = node;
|
|
@@ -170,19 +169,6 @@ class ParseContext {
|
|
|
170
169
|
this.parent = parent != null ? parent : orig.parent || {};
|
|
171
170
|
this.root = orig.root;
|
|
172
171
|
this.src = orig.src;
|
|
173
|
-
} // for logging
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
get pretty() {
|
|
177
|
-
const obj = {
|
|
178
|
-
start: `${this.lineStart} + ${this.indent}`,
|
|
179
|
-
in: [],
|
|
180
|
-
parent: this.parent.type
|
|
181
|
-
};
|
|
182
|
-
if (!this.atLineStart) obj.start += ' + N';
|
|
183
|
-
if (this.inCollection) obj.in.push('collection');
|
|
184
|
-
if (this.inFlow) obj.in.push('flow');
|
|
185
|
-
return obj;
|
|
186
172
|
}
|
|
187
173
|
|
|
188
174
|
nodeStartsCollection(node) {
|
package/dist/schema/Alias.js
CHANGED
|
@@ -77,6 +77,7 @@ class Alias extends _Node.default {
|
|
|
77
77
|
maxAliasCount
|
|
78
78
|
} = ctx;
|
|
79
79
|
const anchor = anchors.find(a => a.node === this.source);
|
|
80
|
+
/* istanbul ignore if */
|
|
80
81
|
|
|
81
82
|
if (!anchor || anchor.res === undefined) {
|
|
82
83
|
const msg = 'This should not happen: Alias anchor was not resolved?';
|
|
@@ -17,23 +17,38 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
17
17
|
|
|
18
18
|
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; }
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
function collectionFromPath(schema, path, value) {
|
|
21
|
+
let v = value;
|
|
22
|
+
|
|
23
|
+
for (let i = path.length - 1; i >= 0; --i) {
|
|
24
|
+
const k = path[i];
|
|
25
|
+
const o = Number.isInteger(k) && k >= 0 ? [] : {};
|
|
26
|
+
o[k] = v;
|
|
27
|
+
v = o;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return schema.createNode(v, false);
|
|
31
|
+
} // null, undefined, or an empty non-string iterable (e.g. [])
|
|
32
|
+
|
|
33
|
+
|
|
21
34
|
const isEmptyPath = path => path == null || typeof path === 'object' && path[Symbol.iterator]().next().done;
|
|
22
35
|
|
|
23
36
|
exports.isEmptyPath = isEmptyPath;
|
|
24
37
|
|
|
25
38
|
class Collection extends _Node.default {
|
|
26
|
-
constructor(
|
|
27
|
-
super(
|
|
39
|
+
constructor(schema) {
|
|
40
|
+
super();
|
|
28
41
|
|
|
29
42
|
_defineProperty(this, "items", []);
|
|
43
|
+
|
|
44
|
+
this.schema = schema;
|
|
30
45
|
}
|
|
31
46
|
|
|
32
47
|
addIn(path, value) {
|
|
33
48
|
if (isEmptyPath(path)) this.add(value);else {
|
|
34
49
|
const [key, ...rest] = path;
|
|
35
50
|
const node = this.get(key, true);
|
|
36
|
-
if (node instanceof Collection) node.addIn(rest, value);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
51
|
+
if (node instanceof Collection) node.addIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
37
52
|
}
|
|
38
53
|
}
|
|
39
54
|
|
|
@@ -67,10 +82,12 @@ class Collection extends _Node.default {
|
|
|
67
82
|
this.set(key, value);
|
|
68
83
|
} else {
|
|
69
84
|
const node = this.get(key, true);
|
|
70
|
-
if (node instanceof Collection) node.setIn(rest, value);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
85
|
+
if (node instanceof Collection) node.setIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
71
86
|
}
|
|
72
87
|
} // overridden in implementations
|
|
73
88
|
|
|
89
|
+
/* istanbul ignore next */
|
|
90
|
+
|
|
74
91
|
|
|
75
92
|
toJSON() {
|
|
76
93
|
return null;
|
package/dist/schema/Map.js
CHANGED
|
@@ -28,11 +28,19 @@ function findPair(items, key) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
class YAMLMap extends _Collection.default {
|
|
31
|
-
add(pair) {
|
|
31
|
+
add(pair, overwrite) {
|
|
32
32
|
if (!pair) pair = new _Pair.default(pair);else if (!(pair instanceof _Pair.default)) pair = new _Pair.default(pair.key || pair, pair.value);
|
|
33
33
|
const prev = findPair(this.items, pair.key);
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const sortEntries = this.schema && this.schema.sortMapEntries;
|
|
35
|
+
|
|
36
|
+
if (prev) {
|
|
37
|
+
if (overwrite) prev.value = pair.value;else throw new Error(`Key ${pair.key} already set`);
|
|
38
|
+
} else if (sortEntries) {
|
|
39
|
+
const i = this.items.findIndex(item => sortEntries(pair, item) < 0);
|
|
40
|
+
if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair);
|
|
41
|
+
} else {
|
|
42
|
+
this.items.push(pair);
|
|
43
|
+
}
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
delete(key) {
|
|
@@ -53,8 +61,7 @@ class YAMLMap extends _Collection.default {
|
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
set(key, value) {
|
|
56
|
-
|
|
57
|
-
if (prev) prev.value = value;else this.items.push(new _Pair.default(key, value));
|
|
64
|
+
this.add(new _Pair.default(key, value), true);
|
|
58
65
|
}
|
|
59
66
|
/**
|
|
60
67
|
* @param {*} arg ignored
|
package/dist/schema/Pair.js
CHANGED
|
@@ -140,6 +140,7 @@ class Pair extends _Node.default {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
ctx.implicitKey = false;
|
|
143
|
+
if (!explicitKey && !this.comment && value instanceof _Scalar.default) ctx.indentAtStart = str.length + 1;
|
|
143
144
|
chompKeep = false;
|
|
144
145
|
const valueStr = doc.schema.stringify(value, ctx, () => valueComment = null, () => chompKeep = true);
|
|
145
146
|
let ws = ' ';
|
package/dist/schema/index.js
CHANGED
|
@@ -44,10 +44,12 @@ class Schema {
|
|
|
44
44
|
customTags,
|
|
45
45
|
merge,
|
|
46
46
|
schema,
|
|
47
|
+
sortMapEntries,
|
|
47
48
|
tags: deprecatedCustomTags
|
|
48
49
|
}) {
|
|
49
50
|
this.merge = !!merge;
|
|
50
51
|
this.name = schema;
|
|
52
|
+
this.sortMapEntries = sortMapEntries === true ? (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0 : sortMapEntries || null;
|
|
51
53
|
this.tags = _tags.schemas[schema.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
|
|
52
54
|
|
|
53
55
|
if (!this.tags) {
|
|
@@ -114,7 +116,7 @@ class Schema {
|
|
|
114
116
|
const obj = {};
|
|
115
117
|
|
|
116
118
|
if (value && typeof value === 'object' && ctx.prevObjects) {
|
|
117
|
-
const prev = ctx.prevObjects.
|
|
119
|
+
const prev = ctx.prevObjects.get(value);
|
|
118
120
|
|
|
119
121
|
if (prev) {
|
|
120
122
|
const alias = new _Alias.default(prev); // leaves source dirty; must be cleaned by caller
|
|
@@ -124,10 +126,11 @@ class Schema {
|
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
obj.value = value;
|
|
127
|
-
ctx.prevObjects.
|
|
129
|
+
ctx.prevObjects.set(value, obj);
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new _Scalar.default(value) : value;
|
|
133
|
+
if (tag && obj.node instanceof _Node.default) obj.node.tag = tag;
|
|
131
134
|
return obj.node;
|
|
132
135
|
}
|
|
133
136
|
|
|
@@ -187,6 +190,7 @@ class Schema {
|
|
|
187
190
|
}
|
|
188
191
|
}
|
|
189
192
|
} catch (error) {
|
|
193
|
+
/* istanbul ignore if */
|
|
190
194
|
if (!error.source) error.source = node;
|
|
191
195
|
doc.errors.push(error);
|
|
192
196
|
node.resolved = null;
|
|
@@ -201,6 +205,7 @@ class Schema {
|
|
|
201
205
|
const res = this.resolveNode(doc, node, tagName);
|
|
202
206
|
if (Object.prototype.hasOwnProperty.call(node, 'resolved')) return res;
|
|
203
207
|
const fallback = isMap(node) ? Schema.defaultTags.MAP : isSeq(node) ? Schema.defaultTags.SEQ : Schema.defaultTags.STR;
|
|
208
|
+
/* istanbul ignore else */
|
|
204
209
|
|
|
205
210
|
if (fallback) {
|
|
206
211
|
doc.warnings.push(new _errors.YAMLWarning(node, `The tag ${tagName} is unavailable, falling back to ${fallback}`));
|
|
@@ -209,9 +214,8 @@ class Schema {
|
|
|
209
214
|
return res;
|
|
210
215
|
} else {
|
|
211
216
|
doc.errors.push(new _errors.YAMLReferenceError(node, `The tag ${tagName} is unavailable`));
|
|
217
|
+
return null;
|
|
212
218
|
}
|
|
213
|
-
|
|
214
|
-
return null;
|
|
215
219
|
}
|
|
216
220
|
|
|
217
221
|
getTagObject(item) {
|
|
@@ -271,7 +275,7 @@ class Schema {
|
|
|
271
275
|
const createCtx = {
|
|
272
276
|
aliasNodes: [],
|
|
273
277
|
onTagObj: o => tagObj = o,
|
|
274
|
-
prevObjects:
|
|
278
|
+
prevObjects: new Map()
|
|
275
279
|
};
|
|
276
280
|
item = this.createNode(item, true, null, createCtx);
|
|
277
281
|
const {
|
|
@@ -293,6 +297,7 @@ class Schema {
|
|
|
293
297
|
if (item instanceof _Pair.default) return item.toString(ctx, onComment, onChompKeep);
|
|
294
298
|
if (!tagObj) tagObj = this.getTagObject(item);
|
|
295
299
|
const props = this.stringifyProps(item, tagObj, ctx);
|
|
300
|
+
if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1;
|
|
296
301
|
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);
|
|
297
302
|
return props ? item instanceof _Collection.default && str[0] !== '{' && str[0] !== '[' ? `${props}\n${ctx.indent}${str}` : `${props} ${str}` : str;
|
|
298
303
|
}
|
package/dist/schema/parseMap.js
CHANGED
|
@@ -25,7 +25,7 @@ var _Collection = _interopRequireDefault(require("./Collection"));
|
|
|
25
25
|
|
|
26
26
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
27
27
|
|
|
28
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {};
|
|
28
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
29
|
|
|
30
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
31
|
|
package/dist/stringify.js
CHANGED
|
@@ -16,7 +16,13 @@ var _options = require("./tags/options");
|
|
|
16
16
|
|
|
17
17
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
18
18
|
|
|
19
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {};
|
|
19
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
|
+
|
|
21
|
+
const getFoldOptions = ({
|
|
22
|
+
indentAtStart
|
|
23
|
+
}) => indentAtStart ? Object.assign({
|
|
24
|
+
indentAtStart
|
|
25
|
+
}, _options.strOptions.fold) : _options.strOptions.fold;
|
|
20
26
|
|
|
21
27
|
function stringifyNumber({
|
|
22
28
|
format,
|
|
@@ -58,10 +64,11 @@ function lineLengthOverLimit(str, limit) {
|
|
|
58
64
|
return true;
|
|
59
65
|
}
|
|
60
66
|
|
|
61
|
-
function doubleQuotedString(value, {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
function doubleQuotedString(value, ctx) {
|
|
68
|
+
const {
|
|
69
|
+
implicitKey,
|
|
70
|
+
indent
|
|
71
|
+
} = ctx;
|
|
65
72
|
const {
|
|
66
73
|
jsonEncoding,
|
|
67
74
|
minMultiLineLength
|
|
@@ -155,7 +162,7 @@ function doubleQuotedString(value, {
|
|
|
155
162
|
}
|
|
156
163
|
|
|
157
164
|
str = start ? str + json.slice(start) : json;
|
|
158
|
-
return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED,
|
|
165
|
+
return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx));
|
|
159
166
|
}
|
|
160
167
|
|
|
161
168
|
function singleQuotedString(value, ctx) {
|
|
@@ -172,7 +179,7 @@ function singleQuotedString(value, ctx) {
|
|
|
172
179
|
}
|
|
173
180
|
|
|
174
181
|
const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
|
|
175
|
-
return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW,
|
|
182
|
+
return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
|
|
176
183
|
}
|
|
177
184
|
|
|
178
185
|
function blockString({
|
|
@@ -282,7 +289,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
282
289
|
return doubleQuotedString(value, ctx);
|
|
283
290
|
}
|
|
284
291
|
|
|
285
|
-
const body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW,
|
|
292
|
+
const body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
|
|
286
293
|
|
|
287
294
|
if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
|
|
288
295
|
if (onComment) onComment();
|
package/dist/tags/core.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.floatObj = exports.expObj = exports.nanObj = exports.hexObj = exports.intObj = exports.octObj = exports.boolObj = exports.nullObj = void 0;
|
|
7
7
|
|
|
8
8
|
var _Scalar = _interopRequireDefault(require("../schema/Scalar"));
|
|
9
9
|
|
|
@@ -15,7 +15,7 @@ var _options = require("./options");
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const nullObj = {
|
|
19
19
|
identify: value => value == null,
|
|
20
20
|
createNode: (schema, value, ctx) => ctx.wrapScalars ? new _Scalar.default(null) : null,
|
|
21
21
|
default: true,
|
|
@@ -24,7 +24,9 @@ var _default = _failsafe.default.concat([{
|
|
|
24
24
|
resolve: () => null,
|
|
25
25
|
options: _options.nullOptions,
|
|
26
26
|
stringify: () => _options.nullOptions.nullStr
|
|
27
|
-
}
|
|
27
|
+
};
|
|
28
|
+
exports.nullObj = nullObj;
|
|
29
|
+
const boolObj = {
|
|
28
30
|
identify: value => typeof value === 'boolean',
|
|
29
31
|
default: true,
|
|
30
32
|
tag: 'tag:yaml.org,2002:bool',
|
|
@@ -34,7 +36,9 @@ var _default = _failsafe.default.concat([{
|
|
|
34
36
|
stringify: ({
|
|
35
37
|
value
|
|
36
38
|
}) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr
|
|
37
|
-
}
|
|
39
|
+
};
|
|
40
|
+
exports.boolObj = boolObj;
|
|
41
|
+
const octObj = {
|
|
38
42
|
identify: value => typeof value === 'number',
|
|
39
43
|
default: true,
|
|
40
44
|
tag: 'tag:yaml.org,2002:int',
|
|
@@ -44,14 +48,18 @@ var _default = _failsafe.default.concat([{
|
|
|
44
48
|
stringify: ({
|
|
45
49
|
value
|
|
46
50
|
}) => '0o' + value.toString(8)
|
|
47
|
-
}
|
|
51
|
+
};
|
|
52
|
+
exports.octObj = octObj;
|
|
53
|
+
const intObj = {
|
|
48
54
|
identify: value => typeof value === 'number',
|
|
49
55
|
default: true,
|
|
50
56
|
tag: 'tag:yaml.org,2002:int',
|
|
51
57
|
test: /^[-+]?[0-9]+$/,
|
|
52
58
|
resolve: str => parseInt(str, 10),
|
|
53
59
|
stringify: _stringify.stringifyNumber
|
|
54
|
-
}
|
|
60
|
+
};
|
|
61
|
+
exports.intObj = intObj;
|
|
62
|
+
const hexObj = {
|
|
55
63
|
identify: value => typeof value === 'number',
|
|
56
64
|
default: true,
|
|
57
65
|
tag: 'tag:yaml.org,2002:int',
|
|
@@ -61,36 +69,46 @@ var _default = _failsafe.default.concat([{
|
|
|
61
69
|
stringify: ({
|
|
62
70
|
value
|
|
63
71
|
}) => '0x' + value.toString(16)
|
|
64
|
-
}
|
|
72
|
+
};
|
|
73
|
+
exports.hexObj = hexObj;
|
|
74
|
+
const nanObj = {
|
|
65
75
|
identify: value => typeof value === 'number',
|
|
66
76
|
default: true,
|
|
67
77
|
tag: 'tag:yaml.org,2002:float',
|
|
68
78
|
test: /^(?:[-+]?\.inf|(\.nan))$/i,
|
|
69
79
|
resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
|
|
70
80
|
stringify: _stringify.stringifyNumber
|
|
71
|
-
}
|
|
81
|
+
};
|
|
82
|
+
exports.nanObj = nanObj;
|
|
83
|
+
const expObj = {
|
|
72
84
|
identify: value => typeof value === 'number',
|
|
73
85
|
default: true,
|
|
74
86
|
tag: 'tag:yaml.org,2002:float',
|
|
75
87
|
format: 'EXP',
|
|
76
|
-
test: /^[-+]?(
|
|
88
|
+
test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
|
|
77
89
|
resolve: str => parseFloat(str),
|
|
78
90
|
stringify: ({
|
|
79
91
|
value
|
|
80
92
|
}) => Number(value).toExponential()
|
|
81
|
-
}
|
|
93
|
+
};
|
|
94
|
+
exports.expObj = expObj;
|
|
95
|
+
const floatObj = {
|
|
82
96
|
identify: value => typeof value === 'number',
|
|
83
97
|
default: true,
|
|
84
98
|
tag: 'tag:yaml.org,2002:float',
|
|
85
|
-
test: /^[-+]?(
|
|
99
|
+
test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/,
|
|
86
100
|
|
|
87
|
-
resolve(str,
|
|
101
|
+
resolve(str, frac1, frac2) {
|
|
102
|
+
const frac = frac1 || frac2;
|
|
88
103
|
const node = new _Scalar.default(parseFloat(str));
|
|
89
104
|
if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
|
|
90
105
|
return node;
|
|
91
106
|
},
|
|
92
107
|
|
|
93
108
|
stringify: _stringify.stringifyNumber
|
|
94
|
-
}
|
|
109
|
+
};
|
|
110
|
+
exports.floatObj = floatObj;
|
|
111
|
+
|
|
112
|
+
var _default = _failsafe.default.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
|
|
95
113
|
|
|
96
114
|
exports.default = _default;
|
|
@@ -12,7 +12,7 @@ var _parseMap = _interopRequireDefault(require("../../schema/parseMap"));
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
14
|
function createMap(schema, obj, ctx) {
|
|
15
|
-
const map = new _Map.default();
|
|
15
|
+
const map = new _Map.default(schema);
|
|
16
16
|
|
|
17
17
|
if (obj instanceof Map) {
|
|
18
18
|
for (const [key, value] of obj) map.items.push(schema.createPair(key, value, ctx));
|
|
@@ -20,6 +20,10 @@ function createMap(schema, obj, ctx) {
|
|
|
20
20
|
for (const key of Object.keys(obj)) map.items.push(schema.createPair(key, obj[key], ctx));
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
if (typeof schema.sortMapEntries === 'function') {
|
|
24
|
+
map.items.sort(schema.sortMapEntries);
|
|
25
|
+
}
|
|
26
|
+
|
|
23
27
|
return map;
|
|
24
28
|
}
|
|
25
29
|
|
|
@@ -12,7 +12,7 @@ var _Seq = _interopRequireDefault(require("../../schema/Seq"));
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
14
|
function createSeq(schema, obj, ctx) {
|
|
15
|
-
const seq = new _Seq.default();
|
|
15
|
+
const seq = new _Seq.default(schema);
|
|
16
16
|
|
|
17
17
|
if (obj && obj[Symbol.iterator]) {
|
|
18
18
|
for (const it of obj) {
|
package/dist/tags/index.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.tags = exports.schemas = void 0;
|
|
7
7
|
|
|
8
|
-
var _core =
|
|
8
|
+
var _core = _interopRequireWildcard(require("./core"));
|
|
9
9
|
|
|
10
10
|
var _failsafe = _interopRequireDefault(require("./failsafe"));
|
|
11
11
|
|
|
@@ -29,6 +29,10 @@ var _timestamp = require("./yaml-1.1/timestamp");
|
|
|
29
29
|
|
|
30
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
31
|
|
|
32
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
33
|
+
|
|
34
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
35
|
+
|
|
32
36
|
const schemas = {
|
|
33
37
|
core: _core.default,
|
|
34
38
|
failsafe: _failsafe.default,
|
|
@@ -38,9 +42,17 @@ const schemas = {
|
|
|
38
42
|
exports.schemas = schemas;
|
|
39
43
|
const tags = {
|
|
40
44
|
binary: _binary.default,
|
|
45
|
+
bool: _core.boolObj,
|
|
46
|
+
float: _core.floatObj,
|
|
47
|
+
floatExp: _core.expObj,
|
|
48
|
+
floatNaN: _core.nanObj,
|
|
41
49
|
floatTime: _timestamp.floatTime,
|
|
50
|
+
int: _core.intObj,
|
|
51
|
+
intHex: _core.hexObj,
|
|
52
|
+
intOct: _core.octObj,
|
|
42
53
|
intTime: _timestamp.intTime,
|
|
43
54
|
map: _map.default,
|
|
55
|
+
null: _core.nullObj,
|
|
44
56
|
omap: _omap.default,
|
|
45
57
|
pairs: _pairs.default,
|
|
46
58
|
seq: _seq.default,
|
package/dist/tags/json.js
CHANGED
|
@@ -33,15 +33,8 @@ const schema = [_map.default, _seq.default, {
|
|
|
33
33
|
identify: value => typeof value === 'boolean',
|
|
34
34
|
default: true,
|
|
35
35
|
tag: 'tag:yaml.org,2002:bool',
|
|
36
|
-
test: /^true$/,
|
|
37
|
-
resolve:
|
|
38
|
-
stringify: value => JSON.stringify(value)
|
|
39
|
-
}, {
|
|
40
|
-
identify: value => typeof value === 'boolean',
|
|
41
|
-
default: true,
|
|
42
|
-
tag: 'tag:yaml.org,2002:bool',
|
|
43
|
-
test: /^false$/,
|
|
44
|
-
resolve: () => false,
|
|
36
|
+
test: /^true|false$/,
|
|
37
|
+
resolve: str => str === 'true',
|
|
45
38
|
stringify: value => JSON.stringify(value)
|
|
46
39
|
}, {
|
|
47
40
|
identify: value => typeof value === 'number',
|
|
@@ -31,18 +31,21 @@ var _default = {
|
|
|
31
31
|
* document.querySelector('#photo').src = URL.createObjectURL(blob)
|
|
32
32
|
*/
|
|
33
33
|
resolve: (doc, node) => {
|
|
34
|
+
const src = (0, _string.resolveString)(doc, node);
|
|
35
|
+
|
|
34
36
|
if (typeof Buffer === 'function') {
|
|
35
|
-
const src = (0, _string.resolveString)(doc, node);
|
|
36
37
|
return Buffer.from(src, 'base64');
|
|
37
38
|
} else if (typeof atob === 'function') {
|
|
38
|
-
|
|
39
|
-
const
|
|
39
|
+
// On IE 11, atob() can't handle newlines
|
|
40
|
+
const str = atob(src.replace(/[\n\r]/g, ''));
|
|
41
|
+
const buffer = new Uint8Array(str.length);
|
|
40
42
|
|
|
41
|
-
for (let i = 0; i <
|
|
43
|
+
for (let i = 0; i < str.length; ++i) buffer[i] = str.charCodeAt(i);
|
|
42
44
|
|
|
43
45
|
return buffer;
|
|
44
46
|
} else {
|
|
45
|
-
|
|
47
|
+
const msg = 'This environment does not support reading binary tags; either Buffer or atob is required';
|
|
48
|
+
doc.errors.push(new _errors.YAMLReferenceError(node, msg));
|
|
46
49
|
return null;
|
|
47
50
|
}
|
|
48
51
|
},
|
|
@@ -25,6 +25,10 @@ var _timestamp = require("./timestamp");
|
|
|
25
25
|
|
|
26
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
27
|
|
|
28
|
+
const boolStringify = ({
|
|
29
|
+
value
|
|
30
|
+
}) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr;
|
|
31
|
+
|
|
28
32
|
var _default = _failsafe.default.concat([{
|
|
29
33
|
identify: value => value == null,
|
|
30
34
|
createNode: (schema, value, ctx) => ctx.wrapScalars ? new _Scalar.default(null) : null,
|
|
@@ -41,9 +45,7 @@ var _default = _failsafe.default.concat([{
|
|
|
41
45
|
test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
|
|
42
46
|
resolve: () => true,
|
|
43
47
|
options: _options.boolOptions,
|
|
44
|
-
stringify:
|
|
45
|
-
value
|
|
46
|
-
}) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr
|
|
48
|
+
stringify: boolStringify
|
|
47
49
|
}, {
|
|
48
50
|
identify: value => typeof value === 'boolean',
|
|
49
51
|
default: true,
|
|
@@ -51,9 +53,7 @@ var _default = _failsafe.default.concat([{
|
|
|
51
53
|
test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
|
|
52
54
|
resolve: () => false,
|
|
53
55
|
options: _options.boolOptions,
|
|
54
|
-
stringify:
|
|
55
|
-
value
|
|
56
|
-
}) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr
|
|
56
|
+
stringify: boolStringify
|
|
57
57
|
}, {
|
|
58
58
|
identify: value => typeof value === 'number',
|
|
59
59
|
default: true,
|
|
@@ -19,7 +19,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
19
19
|
|
|
20
20
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
21
21
|
|
|
22
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {};
|
|
22
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
23
|
|
|
24
24
|
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; }
|
|
25
25
|
|