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
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.Collection = exports.isEmptyPath = void 0;
|
|
4
|
-
|
|
5
|
-
var _addComment = require("../addComment");
|
|
6
|
-
|
|
7
|
-
var _constants = require("../constants");
|
|
8
|
-
|
|
9
|
-
var _Node = require("./Node");
|
|
10
|
-
|
|
11
|
-
var _Scalar = require("./Scalar");
|
|
12
|
-
|
|
13
|
-
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; }
|
|
14
|
-
|
|
15
|
-
function collectionFromPath(schema, path, value) {
|
|
16
|
-
let v = value;
|
|
17
|
-
|
|
18
|
-
for (let i = path.length - 1; i >= 0; --i) {
|
|
19
|
-
const k = path[i];
|
|
20
|
-
const o = Number.isInteger(k) && k >= 0 ? [] : {};
|
|
21
|
-
o[k] = v;
|
|
22
|
-
v = o;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return schema.createNode(v, false);
|
|
26
|
-
} // null, undefined, or an empty non-string iterable (e.g. [])
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const isEmptyPath = path => path == null || typeof path === 'object' && path[Symbol.iterator]().next().done;
|
|
30
|
-
|
|
31
|
-
exports.isEmptyPath = isEmptyPath;
|
|
32
|
-
|
|
33
|
-
class Collection extends _Node.Node {
|
|
34
|
-
constructor(schema) {
|
|
35
|
-
super();
|
|
36
|
-
|
|
37
|
-
_defineProperty(this, "items", []);
|
|
38
|
-
|
|
39
|
-
this.schema = schema;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
addIn(path, value) {
|
|
43
|
-
if (isEmptyPath(path)) this.add(value);else {
|
|
44
|
-
const [key, ...rest] = path;
|
|
45
|
-
const node = this.get(key, true);
|
|
46
|
-
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}`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
deleteIn([key, ...rest]) {
|
|
51
|
-
if (rest.length === 0) return this.delete(key);
|
|
52
|
-
const node = this.get(key, true);
|
|
53
|
-
if (node instanceof Collection) return node.deleteIn(rest);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
getIn([key, ...rest], keepScalar) {
|
|
57
|
-
const node = this.get(key, true);
|
|
58
|
-
if (rest.length === 0) return !keepScalar && node instanceof _Scalar.Scalar ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
hasAllNullValues() {
|
|
62
|
-
return this.items.every(node => {
|
|
63
|
-
if (!node || node.type !== 'PAIR') return false;
|
|
64
|
-
const n = node.value;
|
|
65
|
-
return n == null || n instanceof _Scalar.Scalar && n.value == null && !n.commentBefore && !n.comment && !n.tag;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
hasIn([key, ...rest]) {
|
|
70
|
-
if (rest.length === 0) return this.has(key);
|
|
71
|
-
const node = this.get(key, true);
|
|
72
|
-
return node instanceof Collection ? node.hasIn(rest) : false;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
setIn([key, ...rest], value) {
|
|
76
|
-
if (rest.length === 0) {
|
|
77
|
-
this.set(key, value);
|
|
78
|
-
} else {
|
|
79
|
-
const node = this.get(key, true);
|
|
80
|
-
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}`);
|
|
81
|
-
}
|
|
82
|
-
} // overridden in implementations
|
|
83
|
-
|
|
84
|
-
/* istanbul ignore next */
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
toJSON() {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
toString(ctx, {
|
|
92
|
-
blockItem,
|
|
93
|
-
flowChars,
|
|
94
|
-
isMap,
|
|
95
|
-
itemIndent
|
|
96
|
-
}, onComment, onChompKeep) {
|
|
97
|
-
const {
|
|
98
|
-
doc,
|
|
99
|
-
indent,
|
|
100
|
-
indentStep
|
|
101
|
-
} = ctx;
|
|
102
|
-
const inFlow = this.type === _constants.Type.FLOW_MAP || this.type === _constants.Type.FLOW_SEQ || ctx.inFlow;
|
|
103
|
-
if (inFlow) itemIndent += indentStep;
|
|
104
|
-
const allNullValues = isMap && this.hasAllNullValues();
|
|
105
|
-
ctx = Object.assign({}, ctx, {
|
|
106
|
-
allNullValues,
|
|
107
|
-
indent: itemIndent,
|
|
108
|
-
inFlow,
|
|
109
|
-
type: null
|
|
110
|
-
});
|
|
111
|
-
let chompKeep = false;
|
|
112
|
-
let hasItemWithNewLine = false;
|
|
113
|
-
const nodes = this.items.reduce((nodes, item, i) => {
|
|
114
|
-
let comment;
|
|
115
|
-
|
|
116
|
-
if (item) {
|
|
117
|
-
if (!chompKeep && item.spaceBefore) nodes.push({
|
|
118
|
-
type: 'comment',
|
|
119
|
-
str: ''
|
|
120
|
-
});
|
|
121
|
-
if (item.commentBefore) item.commentBefore.match(/^.*$/gm).forEach(line => {
|
|
122
|
-
nodes.push({
|
|
123
|
-
type: 'comment',
|
|
124
|
-
str: `#${line}`
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
if (item.comment) comment = item.comment;
|
|
128
|
-
if (inFlow && (!chompKeep && item.spaceBefore || item.commentBefore || item.comment || item.key && (item.key.commentBefore || item.key.comment) || item.value && (item.value.commentBefore || item.value.comment))) hasItemWithNewLine = true;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
chompKeep = false;
|
|
132
|
-
let str = doc.schema.stringify(item, ctx, () => comment = null, () => chompKeep = true);
|
|
133
|
-
if (inFlow && !hasItemWithNewLine && str.includes('\n')) hasItemWithNewLine = true;
|
|
134
|
-
if (inFlow && i < this.items.length - 1) str += ',';
|
|
135
|
-
str = (0, _addComment.addComment)(str, itemIndent, comment);
|
|
136
|
-
if (chompKeep && (comment || inFlow)) chompKeep = false;
|
|
137
|
-
nodes.push({
|
|
138
|
-
type: 'item',
|
|
139
|
-
str
|
|
140
|
-
});
|
|
141
|
-
return nodes;
|
|
142
|
-
}, []);
|
|
143
|
-
let str;
|
|
144
|
-
|
|
145
|
-
if (nodes.length === 0) {
|
|
146
|
-
str = flowChars.start + flowChars.end;
|
|
147
|
-
} else if (inFlow) {
|
|
148
|
-
const {
|
|
149
|
-
start,
|
|
150
|
-
end
|
|
151
|
-
} = flowChars;
|
|
152
|
-
const strings = nodes.map(n => n.str);
|
|
153
|
-
|
|
154
|
-
if (hasItemWithNewLine || strings.reduce((sum, str) => sum + str.length + 2, 2) > Collection.maxFlowStringSingleLineLength) {
|
|
155
|
-
str = start;
|
|
156
|
-
|
|
157
|
-
for (const s of strings) {
|
|
158
|
-
str += s ? `\n${indentStep}${indent}${s}` : '\n';
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
str += `\n${indent}${end}`;
|
|
162
|
-
} else {
|
|
163
|
-
str = `${start} ${strings.join(' ')} ${end}`;
|
|
164
|
-
}
|
|
165
|
-
} else {
|
|
166
|
-
const strings = nodes.map(blockItem);
|
|
167
|
-
str = strings.shift();
|
|
168
|
-
|
|
169
|
-
for (const s of strings) str += s ? `\n${indent}${s}` : '\n';
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (this.comment) {
|
|
173
|
-
str += '\n' + this.comment.replace(/^/gm, `${indent}#`);
|
|
174
|
-
if (onComment) onComment();
|
|
175
|
-
} else if (chompKeep && onChompKeep) onChompKeep();
|
|
176
|
-
|
|
177
|
-
return str;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
exports.Collection = Collection;
|
|
183
|
-
|
|
184
|
-
_defineProperty(Collection, "maxFlowStringSingleLineLength", 60);
|
package/dist/schema/Map.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.findPair = findPair;
|
|
4
|
-
exports.YAMLMap = void 0;
|
|
5
|
-
|
|
6
|
-
var _Collection = require("./Collection");
|
|
7
|
-
|
|
8
|
-
var _Pair = require("./Pair");
|
|
9
|
-
|
|
10
|
-
var _Scalar = require("./Scalar");
|
|
11
|
-
|
|
12
|
-
function findPair(items, key) {
|
|
13
|
-
const k = key instanceof _Scalar.Scalar ? key.value : key;
|
|
14
|
-
|
|
15
|
-
for (const it of items) {
|
|
16
|
-
if (it instanceof _Pair.Pair) {
|
|
17
|
-
if (it.key === key || it.key === k) return it;
|
|
18
|
-
if (it.key && it.key.value === k) return it;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
class YAMLMap extends _Collection.Collection {
|
|
26
|
-
add(pair, overwrite) {
|
|
27
|
-
if (!pair) pair = new _Pair.Pair(pair);else if (!(pair instanceof _Pair.Pair)) pair = new _Pair.Pair(pair.key || pair, pair.value);
|
|
28
|
-
const prev = findPair(this.items, pair.key);
|
|
29
|
-
const sortEntries = this.schema && this.schema.sortMapEntries;
|
|
30
|
-
|
|
31
|
-
if (prev) {
|
|
32
|
-
if (overwrite) prev.value = pair.value;else throw new Error(`Key ${pair.key} already set`);
|
|
33
|
-
} else if (sortEntries) {
|
|
34
|
-
const i = this.items.findIndex(item => sortEntries(pair, item) < 0);
|
|
35
|
-
if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair);
|
|
36
|
-
} else {
|
|
37
|
-
this.items.push(pair);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
delete(key) {
|
|
42
|
-
const it = findPair(this.items, key);
|
|
43
|
-
if (!it) return false;
|
|
44
|
-
const del = this.items.splice(this.items.indexOf(it), 1);
|
|
45
|
-
return del.length > 0;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get(key, keepScalar) {
|
|
49
|
-
const it = findPair(this.items, key);
|
|
50
|
-
const node = it && it.value;
|
|
51
|
-
return !keepScalar && node instanceof _Scalar.Scalar ? node.value : node;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
has(key) {
|
|
55
|
-
return !!findPair(this.items, key);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
set(key, value) {
|
|
59
|
-
this.add(new _Pair.Pair(key, value), true);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* @param {*} arg ignored
|
|
63
|
-
* @param {*} ctx Conversion context, originally set in Document#toJSON()
|
|
64
|
-
* @param {Class} Type If set, forces the returned collection type
|
|
65
|
-
* @returns {*} Instance of Type, Map, or Object
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
toJSON(_, ctx, Type) {
|
|
70
|
-
const map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
|
|
71
|
-
if (ctx && ctx.onCreate) ctx.onCreate(map);
|
|
72
|
-
|
|
73
|
-
for (const item of this.items) item.addToJSMap(ctx, map);
|
|
74
|
-
|
|
75
|
-
return map;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
toString(ctx, onComment, onChompKeep) {
|
|
79
|
-
if (!ctx) return JSON.stringify(this);
|
|
80
|
-
|
|
81
|
-
for (const item of this.items) {
|
|
82
|
-
if (!(item instanceof _Pair.Pair)) throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return super.toString(ctx, {
|
|
86
|
-
blockItem: n => n.str,
|
|
87
|
-
flowChars: {
|
|
88
|
-
start: '{',
|
|
89
|
-
end: '}'
|
|
90
|
-
},
|
|
91
|
-
isMap: true,
|
|
92
|
-
itemIndent: ctx.indent || ''
|
|
93
|
-
}, onComment, onChompKeep);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
exports.YAMLMap = YAMLMap;
|
package/dist/schema/Merge.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.Merge = exports.MERGE_KEY = void 0;
|
|
4
|
-
|
|
5
|
-
var _Map = require("./Map");
|
|
6
|
-
|
|
7
|
-
var _Pair = require("./Pair");
|
|
8
|
-
|
|
9
|
-
var _Scalar = require("./Scalar");
|
|
10
|
-
|
|
11
|
-
var _Seq = require("./Seq");
|
|
12
|
-
|
|
13
|
-
const MERGE_KEY = '<<';
|
|
14
|
-
exports.MERGE_KEY = MERGE_KEY;
|
|
15
|
-
|
|
16
|
-
class Merge extends _Pair.Pair {
|
|
17
|
-
constructor(pair) {
|
|
18
|
-
if (pair instanceof _Pair.Pair) {
|
|
19
|
-
let seq = pair.value;
|
|
20
|
-
|
|
21
|
-
if (!(seq instanceof _Seq.YAMLSeq)) {
|
|
22
|
-
seq = new _Seq.YAMLSeq();
|
|
23
|
-
seq.items.push(pair.value);
|
|
24
|
-
seq.range = pair.value.range;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
super(pair.key, seq);
|
|
28
|
-
this.range = pair.range;
|
|
29
|
-
} else {
|
|
30
|
-
super(new _Scalar.Scalar(MERGE_KEY), new _Seq.YAMLSeq());
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
this.type = _Pair.Pair.Type.MERGE_PAIR;
|
|
34
|
-
} // If the value associated with a merge key is a single mapping node, each of
|
|
35
|
-
// its key/value pairs is inserted into the current mapping, unless the key
|
|
36
|
-
// already exists in it. If the value associated with the merge key is a
|
|
37
|
-
// sequence, then this sequence is expected to contain mapping nodes and each
|
|
38
|
-
// of these nodes is merged in turn according to its order in the sequence.
|
|
39
|
-
// Keys in mapping nodes earlier in the sequence override keys specified in
|
|
40
|
-
// later mapping nodes. -- http://yaml.org/type/merge.html
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
addToJSMap(ctx, map) {
|
|
44
|
-
for (const {
|
|
45
|
-
source
|
|
46
|
-
} of this.value.items) {
|
|
47
|
-
if (!(source instanceof _Map.YAMLMap)) throw new Error('Merge sources must be maps');
|
|
48
|
-
const srcMap = source.toJSON(null, ctx, Map);
|
|
49
|
-
|
|
50
|
-
for (const [key, value] of srcMap) {
|
|
51
|
-
if (map instanceof Map) {
|
|
52
|
-
if (!map.has(key)) map.set(key, value);
|
|
53
|
-
} else if (map instanceof Set) {
|
|
54
|
-
map.add(key);
|
|
55
|
-
} else {
|
|
56
|
-
if (!Object.prototype.hasOwnProperty.call(map, key)) map[key] = value;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return map;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
toString(ctx, onComment) {
|
|
65
|
-
const seq = this.value;
|
|
66
|
-
if (seq.items.length > 1) return super.toString(ctx, onComment);
|
|
67
|
-
this.value = seq.items[0];
|
|
68
|
-
const str = super.toString(ctx, onComment);
|
|
69
|
-
this.value = seq;
|
|
70
|
-
return str;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
exports.Merge = Merge;
|
package/dist/schema/Node.js
DELETED
package/dist/schema/Pair.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.Pair = void 0;
|
|
4
|
-
|
|
5
|
-
var _addComment = require("../addComment");
|
|
6
|
-
|
|
7
|
-
var _constants = require("../constants");
|
|
8
|
-
|
|
9
|
-
var _toJSON = require("../toJSON");
|
|
10
|
-
|
|
11
|
-
var _Collection = require("./Collection");
|
|
12
|
-
|
|
13
|
-
var _Node = require("./Node");
|
|
14
|
-
|
|
15
|
-
var _Scalar = require("./Scalar");
|
|
16
|
-
|
|
17
|
-
var _Seq = require("./Seq");
|
|
18
|
-
|
|
19
|
-
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; }
|
|
20
|
-
|
|
21
|
-
const stringifyKey = (key, jsKey, ctx) => {
|
|
22
|
-
if (jsKey === null) return '';
|
|
23
|
-
if (typeof jsKey !== 'object') return String(jsKey);
|
|
24
|
-
if (key instanceof _Node.Node && ctx && ctx.doc) return key.toString({
|
|
25
|
-
anchors: {},
|
|
26
|
-
doc: ctx.doc,
|
|
27
|
-
indent: '',
|
|
28
|
-
indentStep: ctx.indentStep,
|
|
29
|
-
inFlow: true,
|
|
30
|
-
inStringifyKey: true
|
|
31
|
-
});
|
|
32
|
-
return JSON.stringify(jsKey);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
class Pair extends _Node.Node {
|
|
36
|
-
constructor(key, value = null) {
|
|
37
|
-
super();
|
|
38
|
-
this.key = key;
|
|
39
|
-
this.value = value;
|
|
40
|
-
this.type = Pair.Type.PAIR;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get commentBefore() {
|
|
44
|
-
return this.key && this.key.commentBefore;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
set commentBefore(cb) {
|
|
48
|
-
if (this.key == null) this.key = new _Scalar.Scalar(null);
|
|
49
|
-
this.key.commentBefore = cb;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
addToJSMap(ctx, map) {
|
|
53
|
-
const key = (0, _toJSON.toJSON)(this.key, '', ctx);
|
|
54
|
-
|
|
55
|
-
if (map instanceof Map) {
|
|
56
|
-
const value = (0, _toJSON.toJSON)(this.value, key, ctx);
|
|
57
|
-
map.set(key, value);
|
|
58
|
-
} else if (map instanceof Set) {
|
|
59
|
-
map.add(key);
|
|
60
|
-
} else {
|
|
61
|
-
const stringKey = stringifyKey(this.key, key, ctx);
|
|
62
|
-
map[stringKey] = (0, _toJSON.toJSON)(this.value, stringKey, ctx);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return map;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
toJSON(_, ctx) {
|
|
69
|
-
const pair = ctx && ctx.mapAsMap ? new Map() : {};
|
|
70
|
-
return this.addToJSMap(ctx, pair);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
toString(ctx, onComment, onChompKeep) {
|
|
74
|
-
if (!ctx || !ctx.doc) return JSON.stringify(this);
|
|
75
|
-
const {
|
|
76
|
-
indent: indentSize,
|
|
77
|
-
indentSeq,
|
|
78
|
-
simpleKeys
|
|
79
|
-
} = ctx.doc.options;
|
|
80
|
-
let {
|
|
81
|
-
key,
|
|
82
|
-
value
|
|
83
|
-
} = this;
|
|
84
|
-
let keyComment = key instanceof _Node.Node && key.comment;
|
|
85
|
-
|
|
86
|
-
if (simpleKeys) {
|
|
87
|
-
if (keyComment) {
|
|
88
|
-
throw new Error('With simple keys, key nodes cannot have comments');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (key instanceof _Collection.Collection) {
|
|
92
|
-
const msg = 'With simple keys, collection cannot be used as a key value';
|
|
93
|
-
throw new Error(msg);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const explicitKey = !simpleKeys && (!key || keyComment || key instanceof _Collection.Collection || key.type === _constants.Type.BLOCK_FOLDED || key.type === _constants.Type.BLOCK_LITERAL);
|
|
98
|
-
const {
|
|
99
|
-
doc,
|
|
100
|
-
indent,
|
|
101
|
-
indentStep
|
|
102
|
-
} = ctx;
|
|
103
|
-
ctx = Object.assign({}, ctx, {
|
|
104
|
-
implicitKey: !explicitKey,
|
|
105
|
-
indent: indent + indentStep
|
|
106
|
-
});
|
|
107
|
-
let chompKeep = false;
|
|
108
|
-
let str = doc.schema.stringify(key, ctx, () => keyComment = null, () => chompKeep = true);
|
|
109
|
-
str = (0, _addComment.addComment)(str, ctx.indent, keyComment);
|
|
110
|
-
|
|
111
|
-
if (ctx.allNullValues && !simpleKeys) {
|
|
112
|
-
if (this.comment) {
|
|
113
|
-
str = (0, _addComment.addComment)(str, ctx.indent, this.comment);
|
|
114
|
-
if (onComment) onComment();
|
|
115
|
-
} else if (chompKeep && !keyComment && onChompKeep) onChompKeep();
|
|
116
|
-
|
|
117
|
-
return ctx.inFlow ? str : `? ${str}`;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
str = explicitKey ? `? ${str}\n${indent}:` : `${str}:`;
|
|
121
|
-
|
|
122
|
-
if (this.comment) {
|
|
123
|
-
// expected (but not strictly required) to be a single-line comment
|
|
124
|
-
str = (0, _addComment.addComment)(str, ctx.indent, this.comment);
|
|
125
|
-
if (onComment) onComment();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
let vcb = '';
|
|
129
|
-
let valueComment = null;
|
|
130
|
-
|
|
131
|
-
if (value instanceof _Node.Node) {
|
|
132
|
-
if (value.spaceBefore) vcb = '\n';
|
|
133
|
-
|
|
134
|
-
if (value.commentBefore) {
|
|
135
|
-
const cs = value.commentBefore.replace(/^/gm, `${ctx.indent}#`);
|
|
136
|
-
vcb += `\n${cs}`;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
valueComment = value.comment;
|
|
140
|
-
} else if (value && typeof value === 'object') {
|
|
141
|
-
value = doc.schema.createNode(value, true);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
ctx.implicitKey = false;
|
|
145
|
-
if (!explicitKey && !this.comment && value instanceof _Scalar.Scalar) ctx.indentAtStart = str.length + 1;
|
|
146
|
-
chompKeep = false;
|
|
147
|
-
|
|
148
|
-
if (!indentSeq && indentSize >= 2 && !ctx.inFlow && !explicitKey && value instanceof _Seq.YAMLSeq && value.type !== _constants.Type.FLOW_SEQ && !value.tag && !doc.anchors.getName(value)) {
|
|
149
|
-
// If indentSeq === false, consider '- ' as part of indentation where possible
|
|
150
|
-
ctx.indent = ctx.indent.substr(2);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const valueStr = doc.schema.stringify(value, ctx, () => valueComment = null, () => chompKeep = true);
|
|
154
|
-
let ws = ' ';
|
|
155
|
-
|
|
156
|
-
if (vcb || this.comment) {
|
|
157
|
-
ws = `${vcb}\n${ctx.indent}`;
|
|
158
|
-
} else if (!explicitKey && value instanceof _Collection.Collection) {
|
|
159
|
-
const flow = valueStr[0] === '[' || valueStr[0] === '{';
|
|
160
|
-
if (!flow || valueStr.includes('\n')) ws = `\n${ctx.indent}`;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (chompKeep && !valueComment && onChompKeep) onChompKeep();
|
|
164
|
-
return (0, _addComment.addComment)(str + ws + valueStr, ctx.indent, valueComment);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
exports.Pair = Pair;
|
|
170
|
-
|
|
171
|
-
_defineProperty(Pair, "Type", {
|
|
172
|
-
PAIR: 'PAIR',
|
|
173
|
-
MERGE_PAIR: 'MERGE_PAIR'
|
|
174
|
-
});
|
package/dist/schema/Scalar.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.Scalar = void 0;
|
|
4
|
-
|
|
5
|
-
var _toJSON = require("../toJSON");
|
|
6
|
-
|
|
7
|
-
var _Node = require("./Node");
|
|
8
|
-
|
|
9
|
-
// Published as 'yaml/scalar'
|
|
10
|
-
class Scalar extends _Node.Node {
|
|
11
|
-
constructor(value) {
|
|
12
|
-
super();
|
|
13
|
-
this.value = value;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
toJSON(arg, ctx) {
|
|
17
|
-
return ctx && ctx.keep ? this.value : (0, _toJSON.toJSON)(this.value, arg, ctx);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
toString() {
|
|
21
|
-
return String(this.value);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
exports.Scalar = Scalar;
|
package/dist/schema/Seq.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.YAMLSeq = void 0;
|
|
4
|
-
|
|
5
|
-
var _toJSON = require("../toJSON");
|
|
6
|
-
|
|
7
|
-
var _Collection = require("./Collection");
|
|
8
|
-
|
|
9
|
-
var _Scalar = require("./Scalar");
|
|
10
|
-
|
|
11
|
-
// Published as 'yaml/seq'
|
|
12
|
-
function asItemIndex(key) {
|
|
13
|
-
let idx = key instanceof _Scalar.Scalar ? key.value : key;
|
|
14
|
-
if (idx && typeof idx === 'string') idx = Number(idx);
|
|
15
|
-
return Number.isInteger(idx) && idx >= 0 ? idx : null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
class YAMLSeq extends _Collection.Collection {
|
|
19
|
-
add(value) {
|
|
20
|
-
this.items.push(value);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
delete(key) {
|
|
24
|
-
const idx = asItemIndex(key);
|
|
25
|
-
if (typeof idx !== 'number') return false;
|
|
26
|
-
const del = this.items.splice(idx, 1);
|
|
27
|
-
return del.length > 0;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get(key, keepScalar) {
|
|
31
|
-
const idx = asItemIndex(key);
|
|
32
|
-
if (typeof idx !== 'number') return undefined;
|
|
33
|
-
const it = this.items[idx];
|
|
34
|
-
return !keepScalar && it instanceof _Scalar.Scalar ? it.value : it;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
has(key) {
|
|
38
|
-
const idx = asItemIndex(key);
|
|
39
|
-
return typeof idx === 'number' && idx < this.items.length;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
set(key, value) {
|
|
43
|
-
const idx = asItemIndex(key);
|
|
44
|
-
if (typeof idx !== 'number') throw new Error(`Expected a valid index, not ${key}.`);
|
|
45
|
-
this.items[idx] = value;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
toJSON(_, ctx) {
|
|
49
|
-
const seq = [];
|
|
50
|
-
if (ctx && ctx.onCreate) ctx.onCreate(seq);
|
|
51
|
-
let i = 0;
|
|
52
|
-
|
|
53
|
-
for (const item of this.items) seq.push((0, _toJSON.toJSON)(item, String(i++), ctx));
|
|
54
|
-
|
|
55
|
-
return seq;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
toString(ctx, onComment, onChompKeep) {
|
|
59
|
-
if (!ctx) return JSON.stringify(this);
|
|
60
|
-
return super.toString(ctx, {
|
|
61
|
-
blockItem: n => n.type === 'comment' ? n.str : `- ${n.str}`,
|
|
62
|
-
flowChars: {
|
|
63
|
-
start: '[',
|
|
64
|
-
end: ']'
|
|
65
|
-
},
|
|
66
|
-
isMap: false,
|
|
67
|
-
itemIndent: (ctx.indent || '') + ' '
|
|
68
|
-
}, onComment, onChompKeep);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
exports.YAMLSeq = YAMLSeq;
|