yaml 2.0.0-4 → 2.0.0-8
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 +5 -5
- package/browser/dist/compose/compose-collection.js +12 -9
- package/browser/dist/compose/compose-doc.js +23 -6
- package/browser/dist/compose/compose-node.js +27 -17
- package/browser/dist/compose/compose-scalar.js +21 -23
- package/browser/dist/compose/composer.js +108 -78
- package/browser/dist/compose/resolve-block-map.js +41 -29
- package/browser/dist/compose/resolve-block-scalar.js +14 -17
- package/browser/dist/compose/resolve-block-seq.js +21 -17
- package/browser/dist/compose/resolve-end.js +7 -8
- package/browser/dist/compose/resolve-flow-collection.js +158 -199
- package/browser/dist/compose/resolve-flow-scalar.js +62 -26
- package/browser/dist/compose/resolve-props.js +72 -37
- package/browser/dist/compose/util-contains-newline.js +15 -12
- package/browser/dist/compose/util-map-includes.js +17 -0
- package/browser/dist/doc/Document.js +74 -99
- package/browser/dist/doc/anchors.js +72 -0
- package/browser/dist/doc/createNode.js +35 -19
- package/browser/dist/doc/directives.js +5 -0
- package/browser/dist/errors.js +16 -12
- package/browser/dist/index.js +3 -3
- package/browser/dist/nodes/Alias.js +51 -28
- package/browser/dist/nodes/Collection.js +23 -92
- package/browser/dist/nodes/Node.js +9 -1
- package/browser/dist/nodes/Pair.js +16 -231
- package/browser/dist/nodes/YAMLMap.js +8 -4
- package/browser/dist/nodes/YAMLSeq.js +7 -4
- package/browser/dist/nodes/addPairToJSMap.js +103 -0
- package/browser/dist/nodes/toJS.js +12 -10
- package/browser/dist/options.js +1 -2
- package/browser/dist/parse/cst-scalar.js +219 -0
- package/browser/dist/parse/cst-stringify.js +61 -0
- package/browser/dist/parse/cst-visit.js +97 -0
- package/{dist/parse/tokens.js → browser/dist/parse/cst.js} +12 -7
- package/browser/dist/parse/lexer.js +149 -125
- package/browser/dist/parse/parser.js +272 -196
- package/browser/dist/public-api.js +11 -14
- package/browser/dist/schema/Schema.js +28 -0
- package/browser/dist/{tags/failsafe → schema/common}/map.js +0 -0
- package/browser/dist/schema/common/null.js +13 -0
- package/browser/dist/{tags/failsafe → schema/common}/seq.js +1 -1
- package/browser/dist/{tags/failsafe → schema/common}/string.js +0 -0
- package/browser/dist/schema/core/bool.js +19 -0
- package/browser/dist/schema/core/float.js +40 -0
- package/browser/dist/schema/core/int.js +38 -0
- package/browser/dist/schema/core/schema.js +23 -0
- package/browser/dist/{tags/json.js → schema/json/schema.js} +5 -6
- package/browser/dist/schema/tags.js +79 -0
- package/browser/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
- package/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/browser/dist/schema/yaml-1.1/float.js +43 -0
- package/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/browser/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
- package/browser/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
- package/browser/dist/schema/yaml-1.1/schema.js +37 -0
- package/browser/dist/{tags → schema}/yaml-1.1/set.js +0 -0
- package/browser/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
- package/browser/dist/stringify/stringify.js +8 -6
- package/browser/dist/stringify/stringifyCollection.js +122 -0
- package/browser/dist/stringify/stringifyComment.js +14 -0
- package/browser/dist/stringify/stringifyDocument.js +64 -0
- package/browser/dist/stringify/stringifyPair.js +111 -0
- package/browser/dist/stringify/stringifyString.js +53 -52
- package/browser/dist/visit.js +20 -1
- package/dist/compose/compose-collection.d.ts +4 -4
- package/dist/compose/compose-collection.js +12 -9
- package/dist/compose/compose-doc.d.ts +4 -3
- package/dist/compose/compose-doc.js +23 -6
- package/dist/compose/compose-node.d.ts +15 -7
- package/dist/compose/compose-node.js +27 -17
- package/dist/compose/compose-scalar.d.ts +4 -3
- package/dist/compose/compose-scalar.js +20 -22
- package/dist/compose/composer.d.ts +28 -23
- package/dist/compose/composer.js +109 -79
- package/dist/compose/resolve-block-map.d.ts +5 -4
- package/dist/compose/resolve-block-map.js +41 -29
- package/dist/compose/resolve-block-scalar.d.ts +5 -3
- package/dist/compose/resolve-block-scalar.js +14 -17
- package/dist/compose/resolve-block-seq.d.ts +4 -4
- package/dist/compose/resolve-block-seq.js +21 -17
- package/dist/compose/resolve-end.d.ts +3 -2
- package/dist/compose/resolve-end.js +7 -8
- package/dist/compose/resolve-flow-collection.d.ts +4 -5
- package/dist/compose/resolve-flow-collection.js +157 -198
- package/dist/compose/resolve-flow-scalar.d.ts +5 -3
- package/dist/compose/resolve-flow-scalar.js +62 -26
- package/dist/compose/resolve-props.d.ts +16 -10
- package/dist/compose/resolve-props.js +72 -37
- package/dist/compose/util-contains-newline.d.ts +1 -1
- package/dist/compose/util-contains-newline.js +15 -12
- package/dist/compose/util-empty-scalar-position.d.ts +1 -1
- package/dist/compose/util-map-includes.d.ts +4 -0
- package/dist/compose/util-map-includes.js +19 -0
- package/dist/doc/Document.d.ts +35 -15
- package/dist/doc/Document.js +72 -97
- package/dist/doc/anchors.d.ts +24 -0
- package/dist/doc/anchors.js +77 -0
- package/dist/doc/createNode.d.ts +10 -11
- package/dist/doc/createNode.js +34 -18
- package/dist/doc/directives.d.ts +1 -0
- package/dist/doc/directives.js +5 -0
- package/dist/errors.d.ts +11 -8
- package/dist/errors.js +16 -12
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -3
- package/dist/nodes/Alias.d.ts +19 -9
- package/dist/nodes/Alias.js +51 -28
- package/dist/nodes/Collection.d.ts +9 -17
- package/dist/nodes/Collection.js +22 -91
- package/dist/nodes/Node.d.ts +10 -4
- package/dist/nodes/Node.js +9 -0
- package/dist/nodes/Pair.d.ts +10 -13
- package/dist/nodes/Pair.js +15 -230
- package/dist/nodes/Scalar.d.ts +6 -3
- package/dist/nodes/YAMLMap.d.ts +3 -3
- package/dist/nodes/YAMLMap.js +8 -4
- package/dist/nodes/YAMLSeq.d.ts +3 -3
- package/dist/nodes/YAMLSeq.js +7 -4
- package/dist/nodes/addPairToJSMap.d.ts +3 -0
- package/dist/nodes/addPairToJSMap.js +105 -0
- package/dist/nodes/toJS.d.ts +4 -5
- package/dist/nodes/toJS.js +12 -10
- package/dist/options.d.ts +41 -25
- package/dist/options.js +1 -2
- package/dist/parse/cst-scalar.d.ts +58 -0
- package/dist/parse/cst-scalar.js +223 -0
- package/dist/parse/cst-stringify.d.ts +8 -0
- package/dist/parse/cst-stringify.js +63 -0
- package/dist/parse/cst-visit.d.ts +39 -0
- package/dist/parse/cst-visit.js +99 -0
- package/dist/parse/{tokens.d.ts → cst.d.ts} +23 -7
- package/{browser/dist/parse/tokens.js → dist/parse/cst.js} +27 -1
- package/dist/parse/lexer.d.ts +7 -14
- package/dist/parse/lexer.js +150 -126
- package/dist/parse/parser.d.ts +31 -24
- package/dist/parse/parser.js +274 -198
- package/dist/public-api.d.ts +7 -7
- package/dist/public-api.js +11 -14
- package/dist/{doc → schema}/Schema.d.ts +6 -3
- package/dist/schema/Schema.js +30 -0
- package/dist/{tags/failsafe → schema/common}/map.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/map.js +0 -0
- package/dist/schema/common/null.d.ts +4 -0
- package/dist/schema/common/null.js +15 -0
- package/dist/{tags/failsafe → schema/common}/seq.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/seq.js +1 -1
- package/dist/{tags/failsafe → schema/common}/string.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/string.js +0 -0
- package/dist/schema/core/bool.d.ts +4 -0
- package/dist/schema/core/bool.js +21 -0
- package/dist/schema/core/float.d.ts +4 -0
- package/dist/schema/core/float.js +44 -0
- package/dist/schema/core/int.d.ts +4 -0
- package/dist/schema/core/int.js +42 -0
- package/dist/schema/core/schema.d.ts +1 -0
- package/dist/schema/core/schema.js +25 -0
- package/dist/schema/json/schema.d.ts +2 -0
- package/dist/{tags/json.js → schema/json/schema.js} +5 -6
- package/dist/schema/tags.d.ts +41 -0
- package/dist/schema/tags.js +82 -0
- package/dist/{tags → schema}/types.d.ts +3 -7
- package/dist/{tags → schema}/yaml-1.1/binary.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
- package/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/dist/schema/yaml-1.1/bool.js +29 -0
- package/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/dist/schema/yaml-1.1/float.js +47 -0
- package/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/dist/schema/yaml-1.1/int.js +76 -0
- package/dist/{tags → schema}/yaml-1.1/omap.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
- package/dist/{tags → schema}/yaml-1.1/pairs.d.ts +3 -2
- package/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
- package/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/dist/schema/yaml-1.1/schema.js +39 -0
- package/dist/{tags → schema}/yaml-1.1/set.d.ts +1 -1
- package/dist/{tags → schema}/yaml-1.1/set.js +0 -0
- package/dist/{tags → schema}/yaml-1.1/timestamp.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
- package/dist/stringify/stringify.d.ts +1 -2
- package/dist/stringify/stringify.js +8 -6
- package/dist/stringify/stringifyCollection.d.ts +21 -0
- package/dist/stringify/stringifyCollection.js +124 -0
- package/dist/stringify/stringifyComment.d.ts +2 -0
- package/dist/stringify/stringifyComment.js +17 -0
- package/dist/stringify/stringifyDocument.d.ts +3 -0
- package/dist/stringify/stringifyDocument.js +66 -0
- package/dist/stringify/stringifyPair.d.ts +3 -0
- package/dist/stringify/stringifyPair.js +113 -0
- package/dist/stringify/stringifyString.js +53 -52
- package/dist/test-events.d.ts +1 -2
- package/dist/test-events.js +25 -12
- package/dist/util.d.ts +1 -1
- package/dist/visit.d.ts +10 -1
- package/dist/visit.js +20 -1
- package/package.json +9 -8
- package/browser/dist/doc/Anchors.js +0 -102
- package/browser/dist/doc/Schema.js +0 -27
- package/browser/dist/doc/getSchemaTags.js +0 -30
- package/browser/dist/stringify/addComment.js +0 -17
- package/browser/dist/tags/core.js +0 -109
- package/browser/dist/tags/failsafe/index.js +0 -7
- package/browser/dist/tags/index.js +0 -34
- package/browser/dist/tags/yaml-1.1/index.js +0 -152
- package/dist/doc/Anchors.d.ts +0 -36
- package/dist/doc/Anchors.js +0 -104
- package/dist/doc/Schema.js +0 -29
- package/dist/doc/getSchemaTags.d.ts +0 -3
- package/dist/doc/getSchemaTags.js +0 -32
- package/dist/stringify/addComment.d.ts +0 -2
- package/dist/stringify/addComment.js +0 -20
- package/dist/tags/core.d.ts +0 -14
- package/dist/tags/core.js +0 -119
- package/dist/tags/failsafe/index.d.ts +0 -1
- package/dist/tags/failsafe/index.js +0 -9
- package/dist/tags/index.d.ts +0 -31
- package/dist/tags/index.js +0 -37
- package/dist/tags/json.d.ts +0 -2
- package/dist/tags/yaml-1.1/index.d.ts +0 -2
- package/dist/tags/yaml-1.1/index.js +0 -154
package/dist/nodes/Pair.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var createNode = require('../doc/createNode.js');
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var stringify = require('../stringify/stringify.js');
|
|
7
|
-
var Scalar = require('./Scalar.js');
|
|
8
|
-
var toJS = require('./toJS.js');
|
|
4
|
+
var stringifyPair = require('../stringify/stringifyPair.js');
|
|
5
|
+
var addPairToJSMap = require('./addPairToJSMap.js');
|
|
9
6
|
var Node = require('./Node.js');
|
|
10
7
|
|
|
11
8
|
function createPair(key, value, ctx) {
|
|
@@ -13,241 +10,29 @@ function createPair(key, value, ctx) {
|
|
|
13
10
|
const v = createNode.createNode(value, undefined, ctx);
|
|
14
11
|
return new Pair(k, v);
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
(Node.isScalar(key) &&
|
|
18
|
-
key.value === Pair.MERGE_KEY &&
|
|
19
|
-
(!key.type || key.type === Scalar.Scalar.PLAIN));
|
|
20
|
-
// If the value associated with a merge key is a single mapping node, each of
|
|
21
|
-
// its key/value pairs is inserted into the current mapping, unless the key
|
|
22
|
-
// already exists in it. If the value associated with the merge key is a
|
|
23
|
-
// sequence, then this sequence is expected to contain mapping nodes and each
|
|
24
|
-
// of these nodes is merged in turn according to its order in the sequence.
|
|
25
|
-
// Keys in mapping nodes earlier in the sequence override keys specified in
|
|
26
|
-
// later mapping nodes. -- http://yaml.org/type/merge.html
|
|
27
|
-
function mergeToJSMap(ctx, map, value) {
|
|
28
|
-
if (!Node.isAlias(value) || !Node.isMap(value.source))
|
|
29
|
-
throw new Error('Merge sources must be map aliases');
|
|
30
|
-
const srcMap = value.source.toJSON(null, ctx, Map);
|
|
31
|
-
for (const [key, value] of srcMap) {
|
|
32
|
-
if (map instanceof Map) {
|
|
33
|
-
if (!map.has(key))
|
|
34
|
-
map.set(key, value);
|
|
35
|
-
}
|
|
36
|
-
else if (map instanceof Set) {
|
|
37
|
-
map.add(key);
|
|
38
|
-
}
|
|
39
|
-
else if (!Object.prototype.hasOwnProperty.call(map, key)) {
|
|
40
|
-
Object.defineProperty(map, key, {
|
|
41
|
-
value,
|
|
42
|
-
writable: true,
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return map;
|
|
49
|
-
}
|
|
50
|
-
class Pair extends Node.NodeBase {
|
|
13
|
+
class Pair {
|
|
51
14
|
constructor(key, value = null) {
|
|
52
|
-
|
|
15
|
+
Object.defineProperty(this, Node.NODE_TYPE, { value: Node.PAIR });
|
|
53
16
|
this.key = key;
|
|
54
17
|
this.value = value;
|
|
55
18
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (Node.isNode(this.key))
|
|
64
|
-
this.key.commentBefore = cb;
|
|
65
|
-
else {
|
|
66
|
-
const msg = 'Pair.commentBefore is an alias for Pair.key.commentBefore. To set it, the key must be a Node.';
|
|
67
|
-
throw new Error(msg);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// @ts-ignore This is fine.
|
|
71
|
-
get spaceBefore() {
|
|
72
|
-
return Node.isNode(this.key) ? this.key.spaceBefore : undefined;
|
|
73
|
-
}
|
|
74
|
-
set spaceBefore(sb) {
|
|
75
|
-
if (this.key == null)
|
|
76
|
-
this.key = new Scalar.Scalar(null); // FIXME
|
|
77
|
-
if (Node.isNode(this.key))
|
|
78
|
-
this.key.spaceBefore = sb;
|
|
79
|
-
else {
|
|
80
|
-
const msg = 'Pair.spaceBefore is an alias for Pair.key.spaceBefore. To set it, the key must be a Node.';
|
|
81
|
-
throw new Error(msg);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
addToJSMap(ctx, map) {
|
|
85
|
-
if (ctx && ctx.doc.schema.merge && isMergeKey(this.key)) {
|
|
86
|
-
if (Node.isSeq(this.value))
|
|
87
|
-
for (const it of this.value.items)
|
|
88
|
-
mergeToJSMap(ctx, map, it);
|
|
89
|
-
else if (Array.isArray(this.value))
|
|
90
|
-
for (const it of this.value)
|
|
91
|
-
mergeToJSMap(ctx, map, it);
|
|
92
|
-
else
|
|
93
|
-
mergeToJSMap(ctx, map, this.value);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
const key = toJS.toJS(this.key, '', ctx);
|
|
97
|
-
if (map instanceof Map) {
|
|
98
|
-
const value = toJS.toJS(this.value, key, ctx);
|
|
99
|
-
map.set(key, value);
|
|
100
|
-
}
|
|
101
|
-
else if (map instanceof Set) {
|
|
102
|
-
map.add(key);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
const stringKey = stringifyKey(this.key, key, ctx);
|
|
106
|
-
const value = toJS.toJS(this.value, stringKey, ctx);
|
|
107
|
-
if (stringKey in map)
|
|
108
|
-
Object.defineProperty(map, stringKey, {
|
|
109
|
-
value,
|
|
110
|
-
writable: true,
|
|
111
|
-
enumerable: true,
|
|
112
|
-
configurable: true
|
|
113
|
-
});
|
|
114
|
-
else
|
|
115
|
-
map[stringKey] = value;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return map;
|
|
19
|
+
clone(schema) {
|
|
20
|
+
let { key, value } = this;
|
|
21
|
+
if (Node.isNode(key))
|
|
22
|
+
key = key.clone(schema);
|
|
23
|
+
if (Node.isNode(value))
|
|
24
|
+
value = value.clone(schema);
|
|
25
|
+
return new Pair(key, value);
|
|
119
26
|
}
|
|
120
27
|
toJSON(_, ctx) {
|
|
121
28
|
const pair = ctx && ctx.mapAsMap ? new Map() : {};
|
|
122
|
-
return
|
|
29
|
+
return addPairToJSMap.addPairToJSMap(ctx, pair, this);
|
|
123
30
|
}
|
|
124
31
|
toString(ctx, onComment, onChompKeep) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
let { key, value } = this;
|
|
129
|
-
let keyComment = (Node.isNode(key) && key.comment) || null;
|
|
130
|
-
if (simpleKeys) {
|
|
131
|
-
if (keyComment) {
|
|
132
|
-
throw new Error('With simple keys, key nodes cannot have comments');
|
|
133
|
-
}
|
|
134
|
-
if (Node.isCollection(key)) {
|
|
135
|
-
const msg = 'With simple keys, collection cannot be used as a key value';
|
|
136
|
-
throw new Error(msg);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
let explicitKey = !simpleKeys &&
|
|
140
|
-
(!key ||
|
|
141
|
-
(keyComment && value == null) ||
|
|
142
|
-
Node.isCollection(key) ||
|
|
143
|
-
(Node.isScalar(key)
|
|
144
|
-
? key.type === Scalar.Scalar.BLOCK_FOLDED || key.type === Scalar.Scalar.BLOCK_LITERAL
|
|
145
|
-
: typeof key === 'object'));
|
|
146
|
-
ctx = Object.assign({}, ctx, {
|
|
147
|
-
allNullValues: false,
|
|
148
|
-
implicitKey: !explicitKey && (simpleKeys || !allNullValues),
|
|
149
|
-
indent: indent + indentStep
|
|
150
|
-
});
|
|
151
|
-
let chompKeep = false;
|
|
152
|
-
let str = stringify.stringify(key, ctx, () => (keyComment = null), () => (chompKeep = true));
|
|
153
|
-
if (!explicitKey && !ctx.inFlow && str.length > 1024) {
|
|
154
|
-
if (simpleKeys)
|
|
155
|
-
throw new Error('With simple keys, single line scalar must not span more than 1024 characters');
|
|
156
|
-
explicitKey = true;
|
|
157
|
-
}
|
|
158
|
-
if ((allNullValues && (!simpleKeys || ctx.inFlow)) ||
|
|
159
|
-
(value == null && (explicitKey || ctx.inFlow))) {
|
|
160
|
-
str = addComment.addComment(str, ctx.indent, keyComment);
|
|
161
|
-
if (this.comment) {
|
|
162
|
-
if (keyComment && !this.comment.includes('\n'))
|
|
163
|
-
str += `\n${ctx.indent || ''}#${this.comment}`;
|
|
164
|
-
else
|
|
165
|
-
str = addComment.addComment(str, ctx.indent, this.comment);
|
|
166
|
-
if (onComment)
|
|
167
|
-
onComment();
|
|
168
|
-
}
|
|
169
|
-
else if (chompKeep && !keyComment && onChompKeep)
|
|
170
|
-
onChompKeep();
|
|
171
|
-
return ctx.inFlow && !explicitKey ? str : `? ${str}`;
|
|
172
|
-
}
|
|
173
|
-
str = explicitKey
|
|
174
|
-
? `? ${addComment.addComment(str, ctx.indent, keyComment)}\n${indent}:`
|
|
175
|
-
: addComment.addComment(`${str}:`, ctx.indent, keyComment);
|
|
176
|
-
if (this.comment) {
|
|
177
|
-
if (keyComment && !explicitKey && !this.comment.includes('\n'))
|
|
178
|
-
str += `\n${ctx.indent || ''}#${this.comment}`;
|
|
179
|
-
else
|
|
180
|
-
str = addComment.addComment(str, ctx.indent, this.comment);
|
|
181
|
-
if (onComment)
|
|
182
|
-
onComment();
|
|
183
|
-
}
|
|
184
|
-
let vcb = '';
|
|
185
|
-
let valueComment = null;
|
|
186
|
-
if (Node.isNode(value)) {
|
|
187
|
-
if (value.spaceBefore)
|
|
188
|
-
vcb = '\n';
|
|
189
|
-
if (value.commentBefore) {
|
|
190
|
-
const cs = value.commentBefore.replace(/^/gm, `${ctx.indent}#`);
|
|
191
|
-
vcb += `\n${cs}`;
|
|
192
|
-
}
|
|
193
|
-
valueComment = value.comment;
|
|
194
|
-
}
|
|
195
|
-
else if (value && typeof value === 'object') {
|
|
196
|
-
value = doc.createNode(value);
|
|
197
|
-
}
|
|
198
|
-
ctx.implicitKey = false;
|
|
199
|
-
if (!explicitKey && !keyComment && !this.comment && Node.isScalar(value))
|
|
200
|
-
ctx.indentAtStart = str.length + 1;
|
|
201
|
-
chompKeep = false;
|
|
202
|
-
if (!indentSeq &&
|
|
203
|
-
indentStep.length >= 2 &&
|
|
204
|
-
!ctx.inFlow &&
|
|
205
|
-
!explicitKey &&
|
|
206
|
-
Node.isSeq(value) &&
|
|
207
|
-
!value.flow &&
|
|
208
|
-
!value.tag &&
|
|
209
|
-
!doc.anchors.getName(value)) {
|
|
210
|
-
// If indentSeq === false, consider '- ' as part of indentation where possible
|
|
211
|
-
ctx.indent = ctx.indent.substr(2);
|
|
212
|
-
}
|
|
213
|
-
const valueStr = stringify.stringify(value, ctx, () => (valueComment = null), () => (chompKeep = true));
|
|
214
|
-
let ws = ' ';
|
|
215
|
-
if (vcb || keyComment || this.comment) {
|
|
216
|
-
ws = `${vcb}\n${ctx.indent}`;
|
|
217
|
-
}
|
|
218
|
-
else if (!explicitKey && Node.isCollection(value)) {
|
|
219
|
-
const flow = valueStr[0] === '[' || valueStr[0] === '{';
|
|
220
|
-
if (!flow || valueStr.includes('\n'))
|
|
221
|
-
ws = `\n${ctx.indent}`;
|
|
222
|
-
}
|
|
223
|
-
else if (valueStr[0] === '\n')
|
|
224
|
-
ws = '';
|
|
225
|
-
if (chompKeep && !valueComment && onChompKeep)
|
|
226
|
-
onChompKeep();
|
|
227
|
-
return addComment.addComment(str + ws + valueStr, ctx.indent, valueComment);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
Pair.MERGE_KEY = '<<';
|
|
231
|
-
function stringifyKey(key, jsKey, ctx) {
|
|
232
|
-
if (jsKey === null)
|
|
233
|
-
return '';
|
|
234
|
-
if (typeof jsKey !== 'object')
|
|
235
|
-
return String(jsKey);
|
|
236
|
-
if (Node.isNode(key) && ctx && ctx.doc) {
|
|
237
|
-
const strCtx = stringify.createStringifyContext(ctx.doc, {});
|
|
238
|
-
strCtx.inFlow = true;
|
|
239
|
-
strCtx.inStringifyKey = true;
|
|
240
|
-
const strKey = key.toString(strCtx);
|
|
241
|
-
if (!ctx.mapKeyWarned) {
|
|
242
|
-
let jsonStr = JSON.stringify(strKey);
|
|
243
|
-
if (jsonStr.length > 40)
|
|
244
|
-
jsonStr = jsonStr.substring(0, 36) + '..."';
|
|
245
|
-
log.warn(ctx.doc.options.logLevel, `Keys with collection values will be stringified due to JS Object restrictions: ${jsonStr}. Set mapAsMap: true to use object keys.`);
|
|
246
|
-
ctx.mapKeyWarned = true;
|
|
247
|
-
}
|
|
248
|
-
return strKey;
|
|
32
|
+
return ctx && ctx.doc
|
|
33
|
+
? stringifyPair.stringifyPair(this, ctx, onComment, onChompKeep)
|
|
34
|
+
: JSON.stringify(this);
|
|
249
35
|
}
|
|
250
|
-
return JSON.stringify(jsKey);
|
|
251
36
|
}
|
|
252
37
|
|
|
253
38
|
exports.Pair = Pair;
|
package/dist/nodes/Scalar.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { NodeBase } from './Node.js';
|
|
1
|
+
import { NodeBase, Range } from './Node.js';
|
|
2
2
|
import { ToJSContext } from './toJS.js';
|
|
3
3
|
export declare const isScalarValue: (value: unknown) => boolean;
|
|
4
4
|
export declare namespace Scalar {
|
|
5
5
|
interface Parsed extends Scalar {
|
|
6
|
-
range:
|
|
6
|
+
range: Range;
|
|
7
7
|
source: string;
|
|
8
8
|
}
|
|
9
9
|
type BLOCK_FOLDED = 'BLOCK_FOLDED';
|
|
@@ -20,7 +20,8 @@ export declare class Scalar<T = unknown> extends NodeBase {
|
|
|
20
20
|
static readonly QUOTE_DOUBLE = "QUOTE_DOUBLE";
|
|
21
21
|
static readonly QUOTE_SINGLE = "QUOTE_SINGLE";
|
|
22
22
|
value: T;
|
|
23
|
-
|
|
23
|
+
/** An optional anchor on this node. Used by alias nodes. */
|
|
24
|
+
anchor?: string;
|
|
24
25
|
/**
|
|
25
26
|
* By default (undefined), numbers use decimal notation.
|
|
26
27
|
* The YAML 1.2 core schema only supports 'HEX' and 'OCT'.
|
|
@@ -31,6 +32,8 @@ export declare class Scalar<T = unknown> extends NodeBase {
|
|
|
31
32
|
minFractionDigits?: number;
|
|
32
33
|
/** Set during parsing to the source string value */
|
|
33
34
|
source?: string;
|
|
35
|
+
/** The scalar style used for the node's string representation */
|
|
36
|
+
type?: Scalar.Type;
|
|
34
37
|
constructor(value: T);
|
|
35
38
|
toJSON(arg?: any, ctx?: ToJSContext): any;
|
|
36
39
|
toString(): string;
|
package/dist/nodes/YAMLMap.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { Schema } from '../
|
|
1
|
+
import type { Schema } from '../schema/Schema.js';
|
|
2
2
|
import type { StringifyContext } from '../stringify/stringify.js';
|
|
3
3
|
import { Collection } from './Collection.js';
|
|
4
|
-
import { ParsedNode } from './Node.js';
|
|
4
|
+
import { ParsedNode, Range } from './Node.js';
|
|
5
5
|
import { Pair } from './Pair.js';
|
|
6
6
|
import type { ToJSContext } from './toJS.js';
|
|
7
7
|
export declare function findPair<K = unknown, V = unknown>(items: Iterable<Pair<K, V>>, key: unknown): Pair<K, V> | undefined;
|
|
8
8
|
export declare namespace YAMLMap {
|
|
9
9
|
interface Parsed<K extends ParsedNode = ParsedNode, V extends ParsedNode | null = ParsedNode | null> extends YAMLMap<K, V> {
|
|
10
10
|
items: Pair<K, V>[];
|
|
11
|
-
range:
|
|
11
|
+
range: Range;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
export declare class YAMLMap<K = unknown, V = unknown> extends Collection {
|
package/dist/nodes/YAMLMap.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var stringifyCollection = require('../stringify/stringifyCollection.js');
|
|
4
|
+
var addPairToJSMap = require('./addPairToJSMap.js');
|
|
3
5
|
var Collection = require('./Collection.js');
|
|
4
6
|
var Node = require('./Node.js');
|
|
5
7
|
var Pair = require('./Pair.js');
|
|
@@ -91,7 +93,7 @@ class YAMLMap extends Collection.Collection {
|
|
|
91
93
|
if (ctx && ctx.onCreate)
|
|
92
94
|
ctx.onCreate(map);
|
|
93
95
|
for (const item of this.items)
|
|
94
|
-
|
|
96
|
+
addPairToJSMap.addPairToJSMap(ctx, map, item);
|
|
95
97
|
return map;
|
|
96
98
|
}
|
|
97
99
|
toString(ctx, onComment, onChompKeep) {
|
|
@@ -103,11 +105,13 @@ class YAMLMap extends Collection.Collection {
|
|
|
103
105
|
}
|
|
104
106
|
if (!ctx.allNullValues && this.hasAllNullValues(false))
|
|
105
107
|
ctx = Object.assign({}, ctx, { allNullValues: true });
|
|
106
|
-
return
|
|
108
|
+
return stringifyCollection.stringifyCollection(this, ctx, {
|
|
107
109
|
blockItem: n => n.str,
|
|
108
110
|
flowChars: { start: '{', end: '}' },
|
|
109
|
-
itemIndent: ctx.indent || ''
|
|
110
|
-
|
|
111
|
+
itemIndent: ctx.indent || '',
|
|
112
|
+
onChompKeep,
|
|
113
|
+
onComment
|
|
114
|
+
});
|
|
111
115
|
}
|
|
112
116
|
}
|
|
113
117
|
|
package/dist/nodes/YAMLSeq.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { Schema } from '../
|
|
1
|
+
import type { Schema } from '../schema/Schema.js';
|
|
2
2
|
import type { StringifyContext } from '../stringify/stringify.js';
|
|
3
3
|
import { Collection } from './Collection.js';
|
|
4
|
-
import { ParsedNode } from './Node.js';
|
|
4
|
+
import { ParsedNode, Range } from './Node.js';
|
|
5
5
|
import type { Pair } from './Pair.js';
|
|
6
6
|
import { ToJSContext } from './toJS.js';
|
|
7
7
|
export declare namespace YAMLSeq {
|
|
8
8
|
interface Parsed<T extends ParsedNode | Pair<ParsedNode, ParsedNode | null> = ParsedNode> extends YAMLSeq<T> {
|
|
9
9
|
items: T[];
|
|
10
|
-
range:
|
|
10
|
+
range: Range;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
export declare class YAMLSeq<T = unknown> extends Collection {
|
package/dist/nodes/YAMLSeq.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var stringifyCollection = require('../stringify/stringifyCollection.js');
|
|
3
4
|
var Collection = require('./Collection.js');
|
|
4
5
|
var Node = require('./Node.js');
|
|
5
6
|
var Scalar = require('./Scalar.js');
|
|
@@ -85,11 +86,13 @@ class YAMLSeq extends Collection.Collection {
|
|
|
85
86
|
toString(ctx, onComment, onChompKeep) {
|
|
86
87
|
if (!ctx)
|
|
87
88
|
return JSON.stringify(this);
|
|
88
|
-
return
|
|
89
|
-
blockItem: n => (n.
|
|
89
|
+
return stringifyCollection.stringifyCollection(this, ctx, {
|
|
90
|
+
blockItem: n => (n.comment ? n.str : `- ${n.str}`),
|
|
90
91
|
flowChars: { start: '[', end: ']' },
|
|
91
|
-
itemIndent: (ctx.indent || '') + ' '
|
|
92
|
-
|
|
92
|
+
itemIndent: (ctx.indent || '') + ' ',
|
|
93
|
+
onChompKeep,
|
|
94
|
+
onComment
|
|
95
|
+
});
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
function asItemIndex(key) {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Pair } from './Pair.js';
|
|
2
|
+
import { ToJSContext } from './toJS.js';
|
|
3
|
+
export declare function addPairToJSMap(ctx: ToJSContext | undefined, map: Map<unknown, unknown> | Set<unknown> | Record<string | number | symbol, unknown>, { key, value }: Pair): Map<unknown, unknown> | Set<unknown> | Record<string | number | symbol, unknown>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var log = require('../log.js');
|
|
4
|
+
var stringify = require('../stringify/stringify.js');
|
|
5
|
+
var Node = require('./Node.js');
|
|
6
|
+
var Scalar = require('./Scalar.js');
|
|
7
|
+
var toJS = require('./toJS.js');
|
|
8
|
+
|
|
9
|
+
const MERGE_KEY = '<<';
|
|
10
|
+
function addPairToJSMap(ctx, map, { key, value }) {
|
|
11
|
+
if (ctx && ctx.doc.schema.merge && isMergeKey(key)) {
|
|
12
|
+
if (Node.isSeq(value))
|
|
13
|
+
for (const it of value.items)
|
|
14
|
+
mergeToJSMap(ctx, map, it);
|
|
15
|
+
else if (Array.isArray(value))
|
|
16
|
+
for (const it of value)
|
|
17
|
+
mergeToJSMap(ctx, map, it);
|
|
18
|
+
else
|
|
19
|
+
mergeToJSMap(ctx, map, value);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const jsKey = toJS.toJS(key, '', ctx);
|
|
23
|
+
if (map instanceof Map) {
|
|
24
|
+
map.set(jsKey, toJS.toJS(value, jsKey, ctx));
|
|
25
|
+
}
|
|
26
|
+
else if (map instanceof Set) {
|
|
27
|
+
map.add(jsKey);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const stringKey = stringifyKey(key, jsKey, ctx);
|
|
31
|
+
const jsValue = toJS.toJS(value, stringKey, ctx);
|
|
32
|
+
if (stringKey in map)
|
|
33
|
+
Object.defineProperty(map, stringKey, {
|
|
34
|
+
value: jsValue,
|
|
35
|
+
writable: true,
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true
|
|
38
|
+
});
|
|
39
|
+
else
|
|
40
|
+
map[stringKey] = jsValue;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return map;
|
|
44
|
+
}
|
|
45
|
+
const isMergeKey = (key) => key === MERGE_KEY ||
|
|
46
|
+
(Node.isScalar(key) &&
|
|
47
|
+
key.value === MERGE_KEY &&
|
|
48
|
+
(!key.type || key.type === Scalar.Scalar.PLAIN));
|
|
49
|
+
// If the value associated with a merge key is a single mapping node, each of
|
|
50
|
+
// its key/value pairs is inserted into the current mapping, unless the key
|
|
51
|
+
// already exists in it. If the value associated with the merge key is a
|
|
52
|
+
// sequence, then this sequence is expected to contain mapping nodes and each
|
|
53
|
+
// of these nodes is merged in turn according to its order in the sequence.
|
|
54
|
+
// Keys in mapping nodes earlier in the sequence override keys specified in
|
|
55
|
+
// later mapping nodes. -- http://yaml.org/type/merge.html
|
|
56
|
+
function mergeToJSMap(ctx, map, value) {
|
|
57
|
+
const source = ctx && Node.isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
58
|
+
if (!Node.isMap(source))
|
|
59
|
+
throw new Error('Merge sources must be maps or map aliases');
|
|
60
|
+
const srcMap = source.toJSON(null, ctx, Map);
|
|
61
|
+
for (const [key, value] of srcMap) {
|
|
62
|
+
if (map instanceof Map) {
|
|
63
|
+
if (!map.has(key))
|
|
64
|
+
map.set(key, value);
|
|
65
|
+
}
|
|
66
|
+
else if (map instanceof Set) {
|
|
67
|
+
map.add(key);
|
|
68
|
+
}
|
|
69
|
+
else if (!Object.prototype.hasOwnProperty.call(map, key)) {
|
|
70
|
+
Object.defineProperty(map, key, {
|
|
71
|
+
value,
|
|
72
|
+
writable: true,
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return map;
|
|
79
|
+
}
|
|
80
|
+
function stringifyKey(key, jsKey, ctx) {
|
|
81
|
+
if (jsKey === null)
|
|
82
|
+
return '';
|
|
83
|
+
if (typeof jsKey !== 'object')
|
|
84
|
+
return String(jsKey);
|
|
85
|
+
if (Node.isNode(key) && ctx && ctx.doc) {
|
|
86
|
+
const strCtx = stringify.createStringifyContext(ctx.doc, {});
|
|
87
|
+
strCtx.anchors = new Set();
|
|
88
|
+
for (const node of ctx.anchors.keys())
|
|
89
|
+
strCtx.anchors.add(node.anchor);
|
|
90
|
+
strCtx.inFlow = true;
|
|
91
|
+
strCtx.inStringifyKey = true;
|
|
92
|
+
const strKey = key.toString(strCtx);
|
|
93
|
+
if (!ctx.mapKeyWarned) {
|
|
94
|
+
let jsonStr = JSON.stringify(strKey);
|
|
95
|
+
if (jsonStr.length > 40)
|
|
96
|
+
jsonStr = jsonStr.substring(0, 36) + '..."';
|
|
97
|
+
log.warn(ctx.doc.options.logLevel, `Keys with collection values will be stringified due to JS Object restrictions: ${jsonStr}. Set mapAsMap: true to use object keys.`);
|
|
98
|
+
ctx.mapKeyWarned = true;
|
|
99
|
+
}
|
|
100
|
+
return strKey;
|
|
101
|
+
}
|
|
102
|
+
return JSON.stringify(jsKey);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
exports.addPairToJSMap = addPairToJSMap;
|
package/dist/nodes/toJS.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type { Document } from '../doc/Document.js';
|
|
2
2
|
import type { stringify } from '../stringify/stringify.js';
|
|
3
|
-
import
|
|
4
|
-
export interface
|
|
5
|
-
alias: string[];
|
|
3
|
+
import { Node } from './Node.js';
|
|
4
|
+
export interface AnchorData {
|
|
6
5
|
aliasCount: number;
|
|
7
6
|
count: number;
|
|
8
|
-
res
|
|
7
|
+
res: unknown;
|
|
9
8
|
}
|
|
10
9
|
export interface ToJSContext {
|
|
11
|
-
anchors: Map<Node,
|
|
10
|
+
anchors: Map<Node, AnchorData>;
|
|
12
11
|
doc: Document;
|
|
13
12
|
keep: boolean;
|
|
14
13
|
mapAsMap: boolean;
|
package/dist/nodes/toJS.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var Node = require('./Node.js');
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Recursively convert any node or its contents to native JavaScript
|
|
5
7
|
*
|
|
@@ -14,20 +16,20 @@ function toJS(value, arg, ctx) {
|
|
|
14
16
|
if (Array.isArray(value))
|
|
15
17
|
return value.map((v, i) => toJS(v, String(i), ctx));
|
|
16
18
|
if (value && typeof value.toJSON === 'function') {
|
|
17
|
-
if (!ctx)
|
|
18
|
-
return value.toJSON(arg);
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
if (!ctx || !Node.hasAnchor(value))
|
|
20
|
+
return value.toJSON(arg, ctx);
|
|
21
|
+
const data = { aliasCount: 0, count: 1, res: undefined };
|
|
22
|
+
ctx.anchors.set(value, data);
|
|
23
|
+
ctx.onCreate = res => {
|
|
24
|
+
data.res = res;
|
|
25
|
+
delete ctx.onCreate;
|
|
26
|
+
};
|
|
25
27
|
const res = value.toJSON(arg, ctx);
|
|
26
|
-
if (
|
|
28
|
+
if (ctx.onCreate)
|
|
27
29
|
ctx.onCreate(res);
|
|
28
30
|
return res;
|
|
29
31
|
}
|
|
30
|
-
if (!(ctx && ctx.keep)
|
|
32
|
+
if (typeof value === 'bigint' && !(ctx && ctx.keep))
|
|
31
33
|
return Number(value);
|
|
32
34
|
return value;
|
|
33
35
|
}
|