yaml 1.6.0 → 1.8.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/browser/dist/Anchors.js +24 -39
- package/browser/dist/Document.js +99 -111
- 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 +57 -58
- 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 +30 -47
- package/browser/dist/cst/ParseContext.js +100 -140
- package/browser/dist/cst/PlainValue.js +22 -39
- 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 +168 -0
- package/browser/dist/errors.js +71 -74
- package/browser/dist/foldFlowLines.js +4 -15
- package/browser/dist/index.js +26 -45
- package/browser/dist/listTagNames.js +10 -24
- package/browser/dist/schema/Alias.js +33 -50
- package/browser/dist/schema/Collection.js +54 -65
- package/browser/dist/schema/Map.js +39 -49
- package/browser/dist/schema/Merge.js +33 -53
- package/browser/dist/schema/Node.js +3 -12
- package/browser/dist/schema/Pair.js +53 -56
- package/browser/dist/schema/Scalar.js +18 -33
- package/browser/dist/schema/Seq.js +23 -40
- package/browser/dist/schema/index.js +67 -81
- package/browser/dist/schema/parseMap.js +63 -70
- package/browser/dist/schema/parseSeq.js +45 -44
- package/browser/dist/schema/parseUtils.js +47 -11
- package/browser/dist/stringify.js +43 -48
- package/browser/dist/tags/core.js +30 -37
- package/browser/dist/tags/failsafe/index.js +4 -17
- package/browser/dist/tags/failsafe/map.js +17 -26
- 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 +16 -29
- 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 +28 -0
- package/browser/map.js +1 -1
- package/browser/pair.js +1 -1
- package/browser/scalar.js +1 -1
- package/browser/schema.js +1 -1
- package/browser/seq.js +1 -1
- package/browser/types/binary.js +1 -1
- package/browser/types/omap.js +1 -1
- package/browser/types/pairs.js +1 -1
- package/browser/types/set.js +1 -1
- package/browser/types/timestamp.js +1 -1
- package/dist/Document.js +21 -9
- package/dist/cst/BlankLine.js +4 -0
- package/dist/cst/BlockValue.js +1 -1
- package/dist/cst/CollectionItem.js +27 -6
- package/dist/cst/Directive.js +0 -16
- package/dist/cst/Node.js +7 -9
- package/dist/cst/ParseContext.js +41 -55
- package/dist/cst/PlainValue.js +1 -1
- package/dist/cst/source-utils.js +178 -0
- package/dist/errors.js +37 -3
- package/dist/index.js +5 -4
- package/dist/schema/Alias.js +2 -1
- package/dist/schema/Collection.js +22 -5
- package/dist/schema/Map.js +12 -5
- package/dist/schema/Merge.js +4 -5
- package/dist/schema/Pair.js +20 -2
- package/dist/schema/index.js +14 -8
- package/dist/schema/parseMap.js +20 -5
- package/dist/schema/parseSeq.js +19 -6
- package/dist/schema/parseUtils.js +54 -6
- package/dist/stringify.js +21 -11
- package/dist/tags/core.js +27 -10
- 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/index.js +6 -6
- package/dist/tags/yaml-1.1/omap.js +3 -5
- package/dist/tags/yaml-1.1/pairs.js +1 -1
- package/dist/tags/yaml-1.1/set.js +3 -1
- package/dist/{deprecation.js → warnings.js} +12 -7
- package/map.js +1 -1
- package/package.json +35 -17
- package/pair.js +1 -1
- package/scalar.js +1 -1
- package/schema.js +1 -1
- package/seq.js +1 -1
- package/types/binary.js +1 -1
- package/types/omap.js +1 -1
- package/types/pairs.js +1 -1
- package/types/set.js +1 -1
- package/types/timestamp.js +1 -1
- package/types.mjs +20 -0
- package/util.mjs +24 -0
- package/browser/dist/cst/getLinePos.js +0 -79
- package/browser/dist/deprecation.js +0 -34
- package/dist/cst/getLinePos.js +0 -79
|
@@ -1,36 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _constants = require("../constants");
|
|
11
|
-
|
|
12
|
-
var _errors = require("../errors");
|
|
13
|
-
|
|
14
|
-
var _Pair = _interopRequireDefault(require("./Pair"));
|
|
15
|
-
|
|
16
|
-
var _parseUtils = require("./parseUtils");
|
|
17
|
-
|
|
18
|
-
var _Seq = _interopRequireDefault(require("./Seq"));
|
|
19
|
-
|
|
20
|
-
function parseSeq(doc, cst) {
|
|
21
|
-
if (cst.type !== _constants.Type.SEQ && cst.type !== _constants.Type.FLOW_SEQ) {
|
|
1
|
+
import { Type } from '../constants';
|
|
2
|
+
import { YAMLSemanticError, YAMLSyntaxError, YAMLWarning } from '../errors';
|
|
3
|
+
import Pair from './Pair';
|
|
4
|
+
import { checkFlowCollectionEnd, checkKeyLength, resolveComments } from './parseUtils';
|
|
5
|
+
import Seq from './Seq';
|
|
6
|
+
import Collection from './Collection';
|
|
7
|
+
export default function parseSeq(doc, cst) {
|
|
8
|
+
if (cst.type !== Type.SEQ && cst.type !== Type.FLOW_SEQ) {
|
|
22
9
|
var msg = "A ".concat(cst.type, " node cannot be resolved as a sequence");
|
|
23
|
-
doc.errors.push(new
|
|
10
|
+
doc.errors.push(new YAMLSyntaxError(cst, msg));
|
|
24
11
|
return null;
|
|
25
12
|
}
|
|
26
13
|
|
|
27
|
-
var _ref = cst.type ===
|
|
14
|
+
var _ref = cst.type === Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst),
|
|
28
15
|
comments = _ref.comments,
|
|
29
16
|
items = _ref.items;
|
|
30
17
|
|
|
31
|
-
var seq = new
|
|
18
|
+
var seq = new Seq();
|
|
32
19
|
seq.items = items;
|
|
33
|
-
|
|
20
|
+
resolveComments(seq, comments);
|
|
21
|
+
|
|
22
|
+
if (!doc.options.mapAsMap && items.some(function (it) {
|
|
23
|
+
return it instanceof Pair && it.key instanceof Collection;
|
|
24
|
+
})) {
|
|
25
|
+
var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
|
|
26
|
+
doc.warnings.push(new YAMLWarning(cst, warn));
|
|
27
|
+
}
|
|
28
|
+
|
|
34
29
|
cst.resolved = seq;
|
|
35
30
|
return seq;
|
|
36
31
|
}
|
|
@@ -43,33 +38,33 @@ function resolveBlockSeqItems(doc, cst) {
|
|
|
43
38
|
var item = cst.items[i];
|
|
44
39
|
|
|
45
40
|
switch (item.type) {
|
|
46
|
-
case
|
|
41
|
+
case Type.BLANK_LINE:
|
|
47
42
|
comments.push({
|
|
48
43
|
before: items.length
|
|
49
44
|
});
|
|
50
45
|
break;
|
|
51
46
|
|
|
52
|
-
case
|
|
47
|
+
case Type.COMMENT:
|
|
53
48
|
comments.push({
|
|
54
49
|
comment: item.comment,
|
|
55
50
|
before: items.length
|
|
56
51
|
});
|
|
57
52
|
break;
|
|
58
53
|
|
|
59
|
-
case
|
|
54
|
+
case Type.SEQ_ITEM:
|
|
60
55
|
if (item.error) doc.errors.push(item.error);
|
|
61
56
|
items.push(doc.resolveNode(item.node));
|
|
62
57
|
|
|
63
58
|
if (item.hasProps) {
|
|
64
59
|
var msg = 'Sequence items cannot have tags or anchors before the - indicator';
|
|
65
|
-
doc.errors.push(new
|
|
60
|
+
doc.errors.push(new YAMLSemanticError(item, msg));
|
|
66
61
|
}
|
|
67
62
|
|
|
68
63
|
break;
|
|
69
64
|
|
|
70
65
|
default:
|
|
71
66
|
if (item.error) doc.errors.push(item.error);
|
|
72
|
-
doc.errors.push(new
|
|
67
|
+
doc.errors.push(new YAMLSyntaxError(item, "Unexpected ".concat(item.type, " node in sequence")));
|
|
73
68
|
}
|
|
74
69
|
}
|
|
75
70
|
|
|
@@ -91,11 +86,12 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
91
86
|
var item = cst.items[i];
|
|
92
87
|
|
|
93
88
|
if (typeof item.char === 'string') {
|
|
94
|
-
var char = item.char
|
|
89
|
+
var char = item.char,
|
|
90
|
+
offset = item.offset;
|
|
95
91
|
|
|
96
92
|
if (char !== ':' && (explicitKey || key !== undefined)) {
|
|
97
93
|
if (explicitKey && key === undefined) key = next ? items.pop() : null;
|
|
98
|
-
items.push(new
|
|
94
|
+
items.push(new Pair(key));
|
|
99
95
|
explicitKey = false;
|
|
100
96
|
key = undefined;
|
|
101
97
|
keyStart = null;
|
|
@@ -109,12 +105,14 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
109
105
|
if (next === ',') {
|
|
110
106
|
key = items.pop();
|
|
111
107
|
|
|
112
|
-
if (key instanceof
|
|
113
|
-
var msg = 'Chaining flow sequence pairs is invalid
|
|
114
|
-
|
|
108
|
+
if (key instanceof Pair) {
|
|
109
|
+
var msg = 'Chaining flow sequence pairs is invalid';
|
|
110
|
+
var err = new YAMLSemanticError(cst, msg);
|
|
111
|
+
err.offset = offset;
|
|
112
|
+
doc.errors.push(err);
|
|
115
113
|
}
|
|
116
114
|
|
|
117
|
-
if (!explicitKey)
|
|
115
|
+
if (!explicitKey) checkKeyLength(doc.errors, cst, i, key, keyStart);
|
|
118
116
|
} else {
|
|
119
117
|
key = null;
|
|
120
118
|
}
|
|
@@ -126,22 +124,25 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
126
124
|
} else if (next === '[' || char !== ']' || i < cst.items.length - 1) {
|
|
127
125
|
var _msg = "Flow sequence contains an unexpected ".concat(char);
|
|
128
126
|
|
|
129
|
-
|
|
127
|
+
var _err = new YAMLSyntaxError(cst, _msg);
|
|
128
|
+
|
|
129
|
+
_err.offset = offset;
|
|
130
|
+
doc.errors.push(_err);
|
|
130
131
|
}
|
|
131
|
-
} else if (item.type ===
|
|
132
|
+
} else if (item.type === Type.BLANK_LINE) {
|
|
132
133
|
comments.push({
|
|
133
134
|
before: items.length
|
|
134
135
|
});
|
|
135
|
-
} else if (item.type ===
|
|
136
|
+
} else if (item.type === Type.COMMENT) {
|
|
136
137
|
comments.push({
|
|
137
138
|
comment: item.comment,
|
|
138
139
|
before: items.length
|
|
139
140
|
});
|
|
140
141
|
} else {
|
|
141
142
|
if (next) {
|
|
142
|
-
var _msg2 = "Expected a ".concat(next, "
|
|
143
|
+
var _msg2 = "Expected a ".concat(next, " in flow sequence");
|
|
143
144
|
|
|
144
|
-
doc.errors.push(new
|
|
145
|
+
doc.errors.push(new YAMLSemanticError(item, _msg2));
|
|
145
146
|
}
|
|
146
147
|
|
|
147
148
|
var value = doc.resolveNode(item);
|
|
@@ -149,7 +150,7 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
149
150
|
if (key === undefined) {
|
|
150
151
|
items.push(value);
|
|
151
152
|
} else {
|
|
152
|
-
items.push(new
|
|
153
|
+
items.push(new Pair(key, value));
|
|
153
154
|
key = undefined;
|
|
154
155
|
}
|
|
155
156
|
|
|
@@ -158,8 +159,8 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
|
|
162
|
-
if (key !== undefined) items.push(new
|
|
162
|
+
checkFlowCollectionEnd(doc.errors, cst);
|
|
163
|
+
if (key !== undefined) items.push(new Pair(key));
|
|
163
164
|
return {
|
|
164
165
|
comments: comments,
|
|
165
166
|
items: items
|
|
@@ -1,14 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
import { YAMLSemanticError } from '../errors';
|
|
2
|
+
import { Type } from '../constants';
|
|
3
|
+
export function checkFlowCollectionEnd(errors, cst) {
|
|
4
|
+
var char, name;
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
switch (cst.type) {
|
|
7
|
+
case Type.FLOW_MAP:
|
|
8
|
+
char = '}';
|
|
9
|
+
name = 'flow map';
|
|
10
|
+
break;
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
case Type.FLOW_SEQ:
|
|
13
|
+
char = ']';
|
|
14
|
+
name = 'flow sequence';
|
|
15
|
+
break;
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
default:
|
|
18
|
+
errors.push(new YAMLSemanticError(cst, 'Not a flow collection!?'));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var lastItem;
|
|
23
|
+
|
|
24
|
+
for (var i = cst.items.length - 1; i >= 0; --i) {
|
|
25
|
+
var item = cst.items[i];
|
|
26
|
+
|
|
27
|
+
if (!item || item.type !== Type.COMMENT) {
|
|
28
|
+
lastItem = item;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (lastItem && lastItem.char !== char) {
|
|
34
|
+
var msg = "Expected ".concat(name, " to end with ").concat(char);
|
|
35
|
+
var err;
|
|
36
|
+
|
|
37
|
+
if (typeof lastItem.offset === 'number') {
|
|
38
|
+
err = new YAMLSemanticError(cst, msg);
|
|
39
|
+
err.offset = lastItem.offset + 1;
|
|
40
|
+
} else {
|
|
41
|
+
err = new YAMLSemanticError(lastItem, msg);
|
|
42
|
+
if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
errors.push(err);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function checkKeyLength(errors, node, itemIdx, key, keyStart) {
|
|
12
49
|
if (!key || typeof keyStart !== 'number') return;
|
|
13
50
|
var item = node.items[itemIdx];
|
|
14
51
|
var keyEnd = item && item.range && item.range.start;
|
|
@@ -26,11 +63,10 @@ function checkKeyLength(errors, node, itemIdx, key, keyStart) {
|
|
|
26
63
|
|
|
27
64
|
if (keyEnd > keyStart + 1024) {
|
|
28
65
|
var k = String(key).substr(0, 8) + '...' + String(key).substr(-8);
|
|
29
|
-
errors.push(new
|
|
66
|
+
errors.push(new YAMLSemanticError(node, "The \"".concat(k, "\" key is too long")));
|
|
30
67
|
}
|
|
31
68
|
}
|
|
32
|
-
|
|
33
|
-
function resolveComments(collection, comments) {
|
|
69
|
+
export function resolveComments(collection, comments) {
|
|
34
70
|
var _iteratorNormalCompletion = true;
|
|
35
71
|
var _didIteratorError = false;
|
|
36
72
|
var _iteratorError = undefined;
|
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function stringifyNumber(_ref) {
|
|
20
|
-
var format = _ref.format,
|
|
21
|
-
minFractionDigits = _ref.minFractionDigits,
|
|
22
|
-
tag = _ref.tag,
|
|
23
|
-
value = _ref.value;
|
|
1
|
+
import { addCommentBefore } from './addComment';
|
|
2
|
+
import { Type } from './constants';
|
|
3
|
+
import foldFlowLines, { FOLD_BLOCK, FOLD_FLOW, FOLD_QUOTED } from './foldFlowLines';
|
|
4
|
+
import { strOptions } from './tags/options';
|
|
5
|
+
|
|
6
|
+
var getFoldOptions = function getFoldOptions(_ref) {
|
|
7
|
+
var indentAtStart = _ref.indentAtStart;
|
|
8
|
+
return indentAtStart ? Object.assign({
|
|
9
|
+
indentAtStart: indentAtStart
|
|
10
|
+
}, strOptions.fold) : strOptions.fold;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function stringifyNumber(_ref2) {
|
|
14
|
+
var format = _ref2.format,
|
|
15
|
+
minFractionDigits = _ref2.minFractionDigits,
|
|
16
|
+
tag = _ref2.tag,
|
|
17
|
+
value = _ref2.value;
|
|
24
18
|
if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
|
|
25
19
|
var n = JSON.stringify(value);
|
|
26
20
|
|
|
@@ -57,10 +51,10 @@ function lineLengthOverLimit(str, limit) {
|
|
|
57
51
|
return true;
|
|
58
52
|
}
|
|
59
53
|
|
|
60
|
-
function doubleQuotedString(value,
|
|
61
|
-
var implicitKey =
|
|
62
|
-
indent =
|
|
63
|
-
var _strOptions$doubleQuo =
|
|
54
|
+
function doubleQuotedString(value, ctx) {
|
|
55
|
+
var implicitKey = ctx.implicitKey,
|
|
56
|
+
indent = ctx.indent;
|
|
57
|
+
var _strOptions$doubleQuo = strOptions.doubleQuoted,
|
|
64
58
|
jsonEncoding = _strOptions$doubleQuo.jsonEncoding,
|
|
65
59
|
minMultiLineLength = _strOptions$doubleQuo.minMultiLineLength;
|
|
66
60
|
var json = JSON.stringify(value);
|
|
@@ -152,7 +146,7 @@ function doubleQuotedString(value, _ref2) {
|
|
|
152
146
|
}
|
|
153
147
|
|
|
154
148
|
str = start ? str + json.slice(start) : json;
|
|
155
|
-
return implicitKey ? str : (
|
|
149
|
+
return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
|
|
156
150
|
}
|
|
157
151
|
|
|
158
152
|
function singleQuotedString(value, ctx) {
|
|
@@ -167,7 +161,7 @@ function singleQuotedString(value, ctx) {
|
|
|
167
161
|
}
|
|
168
162
|
|
|
169
163
|
var res = "'" + value.replace(/'/g, "''").replace(/\n+/g, "$&\n".concat(indent)) + "'";
|
|
170
|
-
return implicitKey ? res : (
|
|
164
|
+
return implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
|
|
171
165
|
}
|
|
172
166
|
|
|
173
167
|
function blockString(_ref3, ctx, onComment, onChompKeep) {
|
|
@@ -184,7 +178,7 @@ function blockString(_ref3, ctx, onComment, onChompKeep) {
|
|
|
184
178
|
var indent = ctx.indent || (ctx.forceBlockIndent ? ' ' : '');
|
|
185
179
|
var indentSize = indent ? '2' : '1'; // root is at -1
|
|
186
180
|
|
|
187
|
-
var literal = type ===
|
|
181
|
+
var literal = type === Type.BLOCK_FOLDED ? false : type === Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth - indent.length);
|
|
188
182
|
var header = literal ? '|' : '>';
|
|
189
183
|
if (!value) return header + '\n';
|
|
190
184
|
var wsStart = '';
|
|
@@ -232,7 +226,7 @@ function blockString(_ref3, ctx, onComment, onChompKeep) {
|
|
|
232
226
|
value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
|
|
233
227
|
// ^ ind.line ^ empty ^ capture next empty lines only at end of indent
|
|
234
228
|
.replace(/\n+/g, "$&".concat(indent));
|
|
235
|
-
var body = (
|
|
229
|
+
var body = foldFlowLines("".concat(wsStart).concat(value).concat(wsEnd), indent, FOLD_BLOCK, strOptions.fold);
|
|
236
230
|
return "".concat(header, "\n").concat(indent).concat(body);
|
|
237
231
|
}
|
|
238
232
|
|
|
@@ -260,30 +254,31 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
260
254
|
return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
|
|
261
255
|
}
|
|
262
256
|
|
|
263
|
-
if (!implicitKey && !inFlow && type !==
|
|
257
|
+
if (!implicitKey && !inFlow && type !== Type.PLAIN && value.indexOf('\n') !== -1) {
|
|
264
258
|
// Where allowed & type not set explicitly, prefer block style for multiline strings
|
|
265
259
|
return blockString(item, ctx, onComment, onChompKeep);
|
|
266
260
|
}
|
|
267
261
|
|
|
268
|
-
var str = value.replace(/\n+/g, "$&\n".concat(indent)); //
|
|
269
|
-
//
|
|
262
|
+
var str = value.replace(/\n+/g, "$&\n".concat(indent)); // Verify that output will be parsed as a string, as e.g. plain numbers and
|
|
263
|
+
// booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
|
|
264
|
+
// and others in v1.1.
|
|
270
265
|
|
|
271
|
-
if (actualString &&
|
|
266
|
+
if (actualString && typeof tags.resolveScalar(str).value !== 'string') {
|
|
272
267
|
return doubleQuotedString(value, ctx);
|
|
273
268
|
}
|
|
274
269
|
|
|
275
|
-
var body = implicitKey ? str : (
|
|
270
|
+
var body = implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx));
|
|
276
271
|
|
|
277
272
|
if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
|
|
278
273
|
if (onComment) onComment();
|
|
279
|
-
return
|
|
274
|
+
return addCommentBefore(body, indent, comment);
|
|
280
275
|
}
|
|
281
276
|
|
|
282
277
|
return body;
|
|
283
278
|
}
|
|
284
279
|
|
|
285
|
-
function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
286
|
-
var defaultType =
|
|
280
|
+
export function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
281
|
+
var defaultType = strOptions.defaultType;
|
|
287
282
|
var implicitKey = ctx.implicitKey,
|
|
288
283
|
inFlow = ctx.inFlow;
|
|
289
284
|
var _item = item,
|
|
@@ -299,17 +294,17 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
|
299
294
|
|
|
300
295
|
var _stringify = function _stringify(_type) {
|
|
301
296
|
switch (_type) {
|
|
302
|
-
case
|
|
303
|
-
case
|
|
297
|
+
case Type.BLOCK_FOLDED:
|
|
298
|
+
case Type.BLOCK_LITERAL:
|
|
304
299
|
return blockString(item, ctx, onComment, onChompKeep);
|
|
305
300
|
|
|
306
|
-
case
|
|
301
|
+
case Type.QUOTE_DOUBLE:
|
|
307
302
|
return doubleQuotedString(value, ctx);
|
|
308
303
|
|
|
309
|
-
case
|
|
304
|
+
case Type.QUOTE_SINGLE:
|
|
310
305
|
return singleQuotedString(value, ctx);
|
|
311
306
|
|
|
312
|
-
case
|
|
307
|
+
case Type.PLAIN:
|
|
313
308
|
return plainString(item, ctx, onComment, onChompKeep);
|
|
314
309
|
|
|
315
310
|
default:
|
|
@@ -317,12 +312,12 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
|
317
312
|
}
|
|
318
313
|
};
|
|
319
314
|
|
|
320
|
-
if (type !==
|
|
315
|
+
if (type !== Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
|
|
321
316
|
// force double quotes on control characters
|
|
322
|
-
type =
|
|
323
|
-
} else if ((implicitKey || inFlow) && (type ===
|
|
317
|
+
type = Type.QUOTE_DOUBLE;
|
|
318
|
+
} else if ((implicitKey || inFlow) && (type === Type.BLOCK_FOLDED || type === Type.BLOCK_LITERAL)) {
|
|
324
319
|
// should not happen; blocks are not valid inside flow containers
|
|
325
|
-
type =
|
|
320
|
+
type = Type.QUOTE_DOUBLE;
|
|
326
321
|
}
|
|
327
322
|
|
|
328
323
|
var res = _stringify(type);
|
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _Scalar = _interopRequireDefault(require("../schema/Scalar"));
|
|
11
|
-
|
|
12
|
-
var _stringify = require("../stringify");
|
|
13
|
-
|
|
14
|
-
var _failsafe = _interopRequireDefault(require("./failsafe"));
|
|
15
|
-
|
|
16
|
-
var _options = require("./options");
|
|
17
|
-
|
|
18
|
-
var _default = _failsafe.default.concat([{
|
|
1
|
+
import Scalar from '../schema/Scalar';
|
|
2
|
+
import { stringifyNumber } from '../stringify';
|
|
3
|
+
import failsafe from './failsafe';
|
|
4
|
+
import { boolOptions, nullOptions } from './options';
|
|
5
|
+
export var nullObj = {
|
|
19
6
|
identify: function identify(value) {
|
|
20
7
|
return value == null;
|
|
21
8
|
},
|
|
22
9
|
createNode: function createNode(schema, value, ctx) {
|
|
23
|
-
return ctx.wrapScalars ? new
|
|
10
|
+
return ctx.wrapScalars ? new Scalar(null) : null;
|
|
24
11
|
},
|
|
25
12
|
default: true,
|
|
26
13
|
tag: 'tag:yaml.org,2002:null',
|
|
@@ -28,11 +15,12 @@ var _default = _failsafe.default.concat([{
|
|
|
28
15
|
resolve: function resolve() {
|
|
29
16
|
return null;
|
|
30
17
|
},
|
|
31
|
-
options:
|
|
18
|
+
options: nullOptions,
|
|
32
19
|
stringify: function stringify() {
|
|
33
|
-
return
|
|
20
|
+
return nullOptions.nullStr;
|
|
34
21
|
}
|
|
35
|
-
}
|
|
22
|
+
};
|
|
23
|
+
export var boolObj = {
|
|
36
24
|
identify: function identify(value) {
|
|
37
25
|
return typeof value === 'boolean';
|
|
38
26
|
},
|
|
@@ -42,12 +30,13 @@ var _default = _failsafe.default.concat([{
|
|
|
42
30
|
resolve: function resolve(str) {
|
|
43
31
|
return str[0] === 't' || str[0] === 'T';
|
|
44
32
|
},
|
|
45
|
-
options:
|
|
33
|
+
options: boolOptions,
|
|
46
34
|
stringify: function stringify(_ref) {
|
|
47
35
|
var value = _ref.value;
|
|
48
|
-
return value ?
|
|
36
|
+
return value ? boolOptions.trueStr : boolOptions.falseStr;
|
|
49
37
|
}
|
|
50
|
-
}
|
|
38
|
+
};
|
|
39
|
+
export var octObj = {
|
|
51
40
|
identify: function identify(value) {
|
|
52
41
|
return typeof value === 'number';
|
|
53
42
|
},
|
|
@@ -62,7 +51,8 @@ var _default = _failsafe.default.concat([{
|
|
|
62
51
|
var value = _ref2.value;
|
|
63
52
|
return '0o' + value.toString(8);
|
|
64
53
|
}
|
|
65
|
-
}
|
|
54
|
+
};
|
|
55
|
+
export var intObj = {
|
|
66
56
|
identify: function identify(value) {
|
|
67
57
|
return typeof value === 'number';
|
|
68
58
|
},
|
|
@@ -72,8 +62,9 @@ var _default = _failsafe.default.concat([{
|
|
|
72
62
|
resolve: function resolve(str) {
|
|
73
63
|
return parseInt(str, 10);
|
|
74
64
|
},
|
|
75
|
-
stringify:
|
|
76
|
-
}
|
|
65
|
+
stringify: stringifyNumber
|
|
66
|
+
};
|
|
67
|
+
export var hexObj = {
|
|
77
68
|
identify: function identify(value) {
|
|
78
69
|
return typeof value === 'number';
|
|
79
70
|
},
|
|
@@ -88,7 +79,8 @@ var _default = _failsafe.default.concat([{
|
|
|
88
79
|
var value = _ref3.value;
|
|
89
80
|
return '0x' + value.toString(16);
|
|
90
81
|
}
|
|
91
|
-
}
|
|
82
|
+
};
|
|
83
|
+
export var nanObj = {
|
|
92
84
|
identify: function identify(value) {
|
|
93
85
|
return typeof value === 'number';
|
|
94
86
|
},
|
|
@@ -98,8 +90,9 @@ var _default = _failsafe.default.concat([{
|
|
|
98
90
|
resolve: function resolve(str, nan) {
|
|
99
91
|
return nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY;
|
|
100
92
|
},
|
|
101
|
-
stringify:
|
|
102
|
-
}
|
|
93
|
+
stringify: stringifyNumber
|
|
94
|
+
};
|
|
95
|
+
export var expObj = {
|
|
103
96
|
identify: function identify(value) {
|
|
104
97
|
return typeof value === 'number';
|
|
105
98
|
},
|
|
@@ -114,7 +107,8 @@ var _default = _failsafe.default.concat([{
|
|
|
114
107
|
var value = _ref4.value;
|
|
115
108
|
return Number(value).toExponential();
|
|
116
109
|
}
|
|
117
|
-
}
|
|
110
|
+
};
|
|
111
|
+
export var floatObj = {
|
|
118
112
|
identify: function identify(value) {
|
|
119
113
|
return typeof value === 'number';
|
|
120
114
|
},
|
|
@@ -122,11 +116,10 @@ var _default = _failsafe.default.concat([{
|
|
|
122
116
|
tag: 'tag:yaml.org,2002:float',
|
|
123
117
|
test: /^[-+]?(?:0|[1-9][0-9]*)\.([0-9]*)$/,
|
|
124
118
|
resolve: function resolve(str, frac) {
|
|
125
|
-
var node = new
|
|
119
|
+
var node = new Scalar(parseFloat(str));
|
|
126
120
|
if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
|
|
127
121
|
return node;
|
|
128
122
|
},
|
|
129
|
-
stringify:
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
exports.default = _default;
|
|
123
|
+
stringify: stringifyNumber
|
|
124
|
+
};
|
|
125
|
+
export default failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _map = _interopRequireDefault(require("./map"));
|
|
11
|
-
|
|
12
|
-
var _seq = _interopRequireDefault(require("./seq"));
|
|
13
|
-
|
|
14
|
-
var _string = _interopRequireDefault(require("./string"));
|
|
15
|
-
|
|
16
|
-
var _default = [_map.default, _seq.default, _string.default];
|
|
17
|
-
exports.default = _default;
|
|
1
|
+
import map from './map';
|
|
2
|
+
import seq from './seq';
|
|
3
|
+
import str from './string';
|
|
4
|
+
export default [map, seq, str];
|
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
-
|
|
12
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
-
|
|
14
|
-
var _Map = _interopRequireDefault(require("../../schema/Map"));
|
|
15
|
-
|
|
16
|
-
var _parseMap = _interopRequireDefault(require("../../schema/parseMap"));
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import YAMLMap from '../../schema/Map';
|
|
4
|
+
import parseMap from '../../schema/parseMap';
|
|
17
5
|
|
|
18
6
|
function createMap(schema, obj, ctx) {
|
|
19
|
-
var map = new
|
|
7
|
+
var map = new YAMLMap(schema);
|
|
20
8
|
|
|
21
9
|
if (obj instanceof Map) {
|
|
22
10
|
var _iteratorNormalCompletion = true;
|
|
@@ -25,7 +13,7 @@ function createMap(schema, obj, ctx) {
|
|
|
25
13
|
|
|
26
14
|
try {
|
|
27
15
|
for (var _iterator = obj[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
28
|
-
var _step$value = (
|
|
16
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
29
17
|
key = _step$value[0],
|
|
30
18
|
value = _step$value[1];
|
|
31
19
|
|
|
@@ -45,21 +33,24 @@ function createMap(schema, obj, ctx) {
|
|
|
45
33
|
}
|
|
46
34
|
}
|
|
47
35
|
}
|
|
48
|
-
} else if (obj && (
|
|
36
|
+
} else if (obj && _typeof(obj) === 'object') {
|
|
49
37
|
for (var _i = 0, _Object$keys = Object.keys(obj); _i < _Object$keys.length; _i++) {
|
|
50
|
-
var
|
|
51
|
-
map.items.push(schema.createPair(
|
|
38
|
+
var _key = _Object$keys[_i];
|
|
39
|
+
map.items.push(schema.createPair(_key, obj[_key], ctx));
|
|
52
40
|
}
|
|
53
41
|
}
|
|
54
42
|
|
|
43
|
+
if (typeof schema.sortMapEntries === 'function') {
|
|
44
|
+
map.items.sort(schema.sortMapEntries);
|
|
45
|
+
}
|
|
46
|
+
|
|
55
47
|
return map;
|
|
56
48
|
}
|
|
57
49
|
|
|
58
|
-
|
|
50
|
+
export default {
|
|
59
51
|
createNode: createMap,
|
|
60
52
|
default: true,
|
|
61
|
-
nodeClass:
|
|
53
|
+
nodeClass: YAMLMap,
|
|
62
54
|
tag: 'tag:yaml.org,2002:map',
|
|
63
|
-
resolve:
|
|
64
|
-
};
|
|
65
|
-
exports.default = _default;
|
|
55
|
+
resolve: parseMap
|
|
56
|
+
};
|