yaml 2.0.0-0 → 2.0.0-11
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/LICENSE +1 -1
- package/README.md +51 -35
- package/browser/dist/compose/compose-collection.js +59 -0
- package/browser/dist/compose/compose-doc.js +40 -0
- package/browser/dist/compose/compose-node.js +90 -0
- package/browser/dist/compose/compose-scalar.js +81 -0
- package/browser/dist/compose/composer.js +217 -0
- package/browser/dist/compose/resolve-block-map.js +107 -0
- package/browser/dist/compose/resolve-block-scalar.js +192 -0
- package/browser/dist/compose/resolve-block-seq.js +45 -0
- package/browser/dist/compose/resolve-end.js +37 -0
- package/browser/dist/compose/resolve-flow-collection.js +200 -0
- package/browser/dist/compose/resolve-flow-scalar.js +223 -0
- package/browser/dist/compose/resolve-props.js +130 -0
- package/browser/dist/compose/util-contains-newline.js +34 -0
- package/browser/dist/compose/util-empty-scalar-position.js +27 -0
- package/browser/dist/compose/util-flow-indent-check.js +15 -0
- package/browser/dist/compose/util-map-includes.js +17 -0
- package/browser/dist/doc/Document.js +328 -0
- package/browser/dist/doc/anchors.js +72 -0
- package/browser/dist/doc/applyReviver.js +54 -0
- package/browser/dist/doc/createNode.js +84 -0
- package/browser/dist/doc/directives.js +169 -0
- package/browser/dist/errors.js +57 -0
- package/browser/dist/index.js +17 -1045
- package/browser/dist/log.js +14 -0
- package/browser/dist/node_modules/tslib/tslib.es6.js +164 -0
- package/browser/dist/nodes/Alias.js +94 -0
- package/browser/dist/nodes/Collection.js +146 -0
- package/browser/dist/nodes/Node.js +48 -0
- package/browser/dist/nodes/Pair.js +36 -0
- package/browser/dist/nodes/Scalar.js +23 -0
- package/browser/dist/nodes/YAMLMap.js +116 -0
- package/browser/dist/nodes/YAMLSeq.js +105 -0
- package/browser/dist/nodes/addPairToJSMap.js +104 -0
- package/browser/dist/nodes/toJS.js +35 -0
- package/browser/dist/parse/cst-scalar.js +215 -0
- package/browser/dist/parse/cst-stringify.js +61 -0
- package/browser/dist/parse/cst-visit.js +97 -0
- package/browser/dist/parse/cst.js +98 -0
- package/browser/dist/parse/lexer.js +701 -0
- package/browser/dist/parse/line-counter.js +39 -0
- package/browser/dist/parse/parser.js +916 -0
- package/browser/dist/public-api.js +99 -0
- package/browser/dist/schema/Schema.js +34 -0
- package/browser/dist/schema/common/map.js +42 -0
- package/browser/dist/schema/common/null.js +15 -0
- package/browser/dist/schema/common/seq.js +33 -0
- package/browser/dist/schema/common/string.js +14 -0
- package/browser/dist/schema/core/bool.js +19 -0
- package/browser/dist/schema/core/float.js +43 -0
- package/browser/dist/schema/core/int.js +38 -0
- package/browser/dist/schema/core/schema.js +23 -0
- package/browser/dist/schema/json/schema.js +62 -0
- package/browser/dist/schema/tags.js +83 -0
- package/browser/dist/schema/yaml-1.1/binary.js +66 -0
- package/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/browser/dist/schema/yaml-1.1/float.js +46 -0
- package/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/browser/dist/schema/yaml-1.1/omap.js +73 -0
- package/browser/dist/schema/yaml-1.1/pairs.js +77 -0
- package/browser/dist/schema/yaml-1.1/schema.js +37 -0
- package/browser/dist/schema/yaml-1.1/set.js +87 -0
- package/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
- package/browser/dist/stringify/foldFlowLines.js +135 -0
- package/browser/dist/stringify/stringify.js +124 -0
- package/browser/dist/stringify/stringifyCollection.js +152 -0
- package/browser/dist/stringify/stringifyComment.js +18 -0
- package/browser/dist/stringify/stringifyDocument.js +86 -0
- package/browser/dist/stringify/stringifyNumber.js +24 -0
- package/browser/dist/stringify/stringifyPair.js +122 -0
- package/browser/dist/stringify/stringifyString.js +314 -0
- package/browser/dist/util.js +9 -2
- package/browser/dist/visit.js +234 -0
- package/browser/index.js +5 -1
- package/browser/package.json +3 -0
- package/dist/compose/compose-collection.d.ts +5 -0
- package/dist/compose/compose-collection.js +61 -0
- package/dist/compose/compose-doc.d.ts +6 -0
- package/dist/compose/compose-doc.js +42 -0
- package/dist/compose/compose-node.d.ts +26 -0
- package/dist/compose/compose-node.js +93 -0
- package/dist/compose/compose-scalar.d.ts +5 -0
- package/dist/compose/compose-scalar.js +83 -0
- package/dist/compose/composer.d.ts +62 -0
- package/dist/compose/composer.js +221 -0
- package/dist/compose/resolve-block-map.d.ts +6 -0
- package/dist/compose/resolve-block-map.js +109 -0
- package/dist/compose/resolve-block-scalar.d.ts +10 -0
- package/dist/compose/resolve-block-scalar.js +194 -0
- package/dist/compose/resolve-block-seq.d.ts +5 -0
- package/dist/compose/resolve-block-seq.js +47 -0
- package/dist/compose/resolve-end.d.ts +6 -0
- package/dist/compose/resolve-end.js +39 -0
- package/dist/compose/resolve-flow-collection.d.ts +6 -0
- package/dist/compose/resolve-flow-collection.js +202 -0
- package/dist/compose/resolve-flow-scalar.d.ts +10 -0
- package/dist/compose/resolve-flow-scalar.js +225 -0
- package/dist/compose/resolve-props.d.ts +21 -0
- package/dist/compose/resolve-props.js +132 -0
- package/dist/compose/util-contains-newline.d.ts +2 -0
- package/dist/compose/util-contains-newline.js +36 -0
- package/dist/compose/util-empty-scalar-position.d.ts +2 -0
- package/dist/compose/util-empty-scalar-position.js +29 -0
- package/dist/compose/util-flow-indent-check.d.ts +3 -0
- package/dist/compose/util-flow-indent-check.js +17 -0
- 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 +139 -0
- package/dist/doc/Document.js +330 -0
- package/dist/doc/anchors.d.ts +24 -0
- package/dist/doc/anchors.js +77 -0
- package/dist/doc/applyReviver.d.ts +9 -0
- package/dist/doc/applyReviver.js +56 -0
- package/dist/doc/createNode.d.ts +17 -0
- package/dist/doc/createNode.js +86 -0
- package/dist/doc/directives.d.ts +49 -0
- package/dist/doc/directives.js +171 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.js +62 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +48 -81
- package/dist/log.d.ts +3 -0
- package/dist/log.js +17 -0
- package/dist/node_modules/tslib/tslib.es6.js +76 -0
- package/dist/nodes/Alias.d.ts +28 -0
- package/dist/nodes/Alias.js +96 -0
- package/dist/nodes/Collection.d.ts +73 -0
- package/dist/nodes/Collection.js +150 -0
- package/dist/nodes/Node.d.ts +53 -0
- package/dist/nodes/Node.js +66 -0
- package/dist/nodes/Pair.d.ts +21 -0
- package/dist/nodes/Pair.js +39 -0
- package/dist/nodes/Scalar.d.ts +42 -0
- package/dist/nodes/Scalar.js +26 -0
- package/dist/nodes/YAMLMap.d.ts +41 -0
- package/dist/nodes/YAMLMap.js +119 -0
- package/dist/nodes/YAMLSeq.d.ts +55 -0
- package/dist/nodes/YAMLSeq.js +107 -0
- package/dist/nodes/addPairToJSMap.d.ts +3 -0
- package/dist/nodes/addPairToJSMap.js +106 -0
- package/dist/nodes/toJS.d.ts +30 -0
- package/dist/nodes/toJS.js +37 -0
- package/dist/options.d.ts +330 -0
- package/dist/parse/cst-scalar.d.ts +64 -0
- package/dist/parse/cst-scalar.js +219 -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/cst.d.ts +106 -0
- package/dist/parse/cst.js +112 -0
- package/dist/parse/lexer.d.ts +87 -0
- package/dist/parse/lexer.js +703 -0
- package/dist/parse/line-counter.d.ts +22 -0
- package/dist/parse/line-counter.js +41 -0
- package/dist/parse/parser.d.ts +84 -0
- package/dist/parse/parser.js +920 -0
- package/dist/public-api.d.ts +43 -0
- package/dist/public-api.js +104 -0
- package/dist/schema/Schema.d.ts +18 -0
- package/dist/schema/Schema.js +36 -0
- package/dist/schema/common/map.d.ts +2 -0
- package/dist/schema/common/map.js +44 -0
- package/dist/schema/common/null.d.ts +4 -0
- package/dist/schema/common/null.js +17 -0
- package/dist/schema/common/seq.d.ts +2 -0
- package/dist/schema/common/seq.js +35 -0
- package/dist/schema/common/string.d.ts +2 -0
- package/dist/schema/common/string.js +16 -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 +47 -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/schema/json/schema.js +64 -0
- package/dist/schema/tags.d.ts +40 -0
- package/dist/schema/tags.js +86 -0
- package/dist/schema/types.d.ts +82 -0
- package/dist/schema/yaml-1.1/binary.d.ts +2 -0
- package/dist/schema/yaml-1.1/binary.js +68 -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 +50 -0
- package/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/dist/schema/yaml-1.1/int.js +76 -0
- package/dist/schema/yaml-1.1/omap.d.ts +21 -0
- package/dist/schema/yaml-1.1/omap.js +76 -0
- package/dist/schema/yaml-1.1/pairs.d.ts +10 -0
- package/dist/schema/yaml-1.1/pairs.js +81 -0
- package/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/dist/schema/yaml-1.1/schema.js +39 -0
- package/dist/schema/yaml-1.1/set.d.ts +22 -0
- package/dist/schema/yaml-1.1/set.js +90 -0
- package/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
- package/dist/schema/yaml-1.1/timestamp.js +105 -0
- package/dist/stringify/foldFlowLines.d.ts +34 -0
- package/dist/stringify/foldFlowLines.js +140 -0
- package/dist/stringify/stringify.d.ts +20 -0
- package/dist/stringify/stringify.js +127 -0
- package/dist/stringify/stringifyCollection.d.ts +17 -0
- package/dist/stringify/stringifyCollection.js +154 -0
- package/dist/stringify/stringifyComment.d.ts +10 -0
- package/dist/stringify/stringifyComment.js +22 -0
- package/dist/stringify/stringifyDocument.d.ts +3 -0
- package/dist/stringify/stringifyDocument.js +88 -0
- package/dist/stringify/stringifyNumber.d.ts +2 -0
- package/dist/stringify/stringifyNumber.js +26 -0
- package/dist/stringify/stringifyPair.d.ts +3 -0
- package/dist/stringify/stringifyPair.js +124 -0
- package/dist/stringify/stringifyString.d.ts +3 -0
- package/dist/stringify/stringifyString.js +316 -0
- package/dist/test-events.d.ts +4 -0
- package/dist/test-events.js +125 -151
- package/dist/util.d.ts +9 -0
- package/dist/util.js +19 -14
- package/dist/visit.d.ts +102 -0
- package/dist/visit.js +237 -0
- package/package.json +49 -51
- package/util.d.ts +3 -86
- package/util.js +2 -16
- package/browser/dist/PlainValue-6b68dc0e.js +0 -1279
- package/browser/dist/Schema-d14032c2.js +0 -1047
- package/browser/dist/parse-6e806192.js +0 -1904
- package/browser/dist/parse-cst.js +0 -2
- package/browser/dist/resolveSeq-3477c430.js +0 -2478
- package/browser/dist/types.js +0 -3
- package/browser/parse-cst.js +0 -1
- package/browser/types.js +0 -1
- package/browser/util.js +0 -1
- package/dist/Document-59bd9290.js +0 -803
- package/dist/PlainValue-ec8e588e.js +0 -876
- package/dist/Schema-fe1471c4.js +0 -808
- package/dist/parse-ab8de154.js +0 -1748
- package/dist/parse-cst.js +0 -8
- package/dist/resolveSeq-6b2dc4ac.js +0 -2217
- package/dist/types.js +0 -22
- package/index.d.ts +0 -411
- package/index.js +0 -1
- package/parse-cst.d.ts +0 -187
- package/parse-cst.js +0 -1
- package/types.d.ts +0 -379
- package/types.js +0 -17
- package/types.mjs +0 -17
- package/util.mjs +0 -18
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { isNode } from '../nodes/Node.js';
|
|
2
|
+
import { visit } from '../visit.js';
|
|
3
|
+
|
|
4
|
+
const escapeChars = {
|
|
5
|
+
'!': '%21',
|
|
6
|
+
',': '%2C',
|
|
7
|
+
'[': '%5B',
|
|
8
|
+
']': '%5D',
|
|
9
|
+
'{': '%7B',
|
|
10
|
+
'}': '%7D'
|
|
11
|
+
};
|
|
12
|
+
const escapeTagName = (tn) => tn.replace(/[!,[\]{}]/g, ch => escapeChars[ch]);
|
|
13
|
+
class Directives {
|
|
14
|
+
constructor(yaml, tags) {
|
|
15
|
+
/**
|
|
16
|
+
* The directives-end/doc-start marker `---`. If `null`, a marker may still be
|
|
17
|
+
* included in the document's stringified representation.
|
|
18
|
+
*/
|
|
19
|
+
this.docStart = null;
|
|
20
|
+
/** The doc-end marker `...`. */
|
|
21
|
+
this.docEnd = false;
|
|
22
|
+
this.yaml = Object.assign({}, Directives.defaultYaml, yaml);
|
|
23
|
+
this.tags = Object.assign({}, Directives.defaultTags, tags);
|
|
24
|
+
}
|
|
25
|
+
clone() {
|
|
26
|
+
const copy = new Directives(this.yaml, this.tags);
|
|
27
|
+
copy.docStart = this.docStart;
|
|
28
|
+
return copy;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* During parsing, get a Directives instance for the current document and
|
|
32
|
+
* update the stream state according to the current version's spec.
|
|
33
|
+
*/
|
|
34
|
+
atDocument() {
|
|
35
|
+
const res = new Directives(this.yaml, this.tags);
|
|
36
|
+
switch (this.yaml.version) {
|
|
37
|
+
case '1.1':
|
|
38
|
+
this.atNextDocument = true;
|
|
39
|
+
break;
|
|
40
|
+
case '1.2':
|
|
41
|
+
this.atNextDocument = false;
|
|
42
|
+
this.yaml = {
|
|
43
|
+
explicit: Directives.defaultYaml.explicit,
|
|
44
|
+
version: '1.2'
|
|
45
|
+
};
|
|
46
|
+
this.tags = Object.assign({}, Directives.defaultTags);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
return res;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @param onError - May be called even if the action was successful
|
|
53
|
+
* @returns `true` on success
|
|
54
|
+
*/
|
|
55
|
+
add(line, onError) {
|
|
56
|
+
if (this.atNextDocument) {
|
|
57
|
+
this.yaml = { explicit: Directives.defaultYaml.explicit, version: '1.1' };
|
|
58
|
+
this.tags = Object.assign({}, Directives.defaultTags);
|
|
59
|
+
this.atNextDocument = false;
|
|
60
|
+
}
|
|
61
|
+
const parts = line.trim().split(/[ \t]+/);
|
|
62
|
+
const name = parts.shift();
|
|
63
|
+
switch (name) {
|
|
64
|
+
case '%TAG': {
|
|
65
|
+
if (parts.length !== 2) {
|
|
66
|
+
onError(0, '%TAG directive should contain exactly two parts');
|
|
67
|
+
if (parts.length < 2)
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const [handle, prefix] = parts;
|
|
71
|
+
this.tags[handle] = prefix;
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
case '%YAML': {
|
|
75
|
+
this.yaml.explicit = true;
|
|
76
|
+
if (parts.length !== 1) {
|
|
77
|
+
onError(0, '%YAML directive should contain exactly one part');
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const [version] = parts;
|
|
81
|
+
if (version === '1.1' || version === '1.2') {
|
|
82
|
+
this.yaml.version = version;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const isValid = /^\d+\.\d+$/.test(version);
|
|
87
|
+
onError(6, `Unsupported YAML version ${version}`, isValid);
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
default:
|
|
92
|
+
onError(0, `Unknown directive ${name}`, true);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Resolves a tag, matching handles to those defined in %TAG directives.
|
|
98
|
+
*
|
|
99
|
+
* @returns Resolved tag, which may also be the non-specific tag `'!'` or a
|
|
100
|
+
* `'!local'` tag, or `null` if unresolvable.
|
|
101
|
+
*/
|
|
102
|
+
tagName(source, onError) {
|
|
103
|
+
if (source === '!')
|
|
104
|
+
return '!'; // non-specific tag
|
|
105
|
+
if (source[0] !== '!') {
|
|
106
|
+
onError(`Not a valid tag: ${source}`);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
if (source[1] === '<') {
|
|
110
|
+
const verbatim = source.slice(2, -1);
|
|
111
|
+
if (verbatim === '!' || verbatim === '!!') {
|
|
112
|
+
onError(`Verbatim tags aren't resolved, so ${source} is invalid.`);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (source[source.length - 1] !== '>')
|
|
116
|
+
onError('Verbatim tags must end with a >');
|
|
117
|
+
return verbatim;
|
|
118
|
+
}
|
|
119
|
+
const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/);
|
|
120
|
+
if (!suffix)
|
|
121
|
+
onError(`The ${source} tag has no suffix`);
|
|
122
|
+
const prefix = this.tags[handle];
|
|
123
|
+
if (prefix)
|
|
124
|
+
return prefix + decodeURIComponent(suffix);
|
|
125
|
+
if (handle === '!')
|
|
126
|
+
return source; // local tag
|
|
127
|
+
onError(`Could not resolve tag: ${source}`);
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Given a fully resolved tag, returns its printable string form,
|
|
132
|
+
* taking into account current tag prefixes and defaults.
|
|
133
|
+
*/
|
|
134
|
+
tagString(tag) {
|
|
135
|
+
for (const [handle, prefix] of Object.entries(this.tags)) {
|
|
136
|
+
if (tag.startsWith(prefix))
|
|
137
|
+
return handle + escapeTagName(tag.substring(prefix.length));
|
|
138
|
+
}
|
|
139
|
+
return tag[0] === '!' ? tag : `!<${tag}>`;
|
|
140
|
+
}
|
|
141
|
+
toString(doc) {
|
|
142
|
+
const lines = this.yaml.explicit
|
|
143
|
+
? [`%YAML ${this.yaml.version || '1.2'}`]
|
|
144
|
+
: [];
|
|
145
|
+
const tagEntries = Object.entries(this.tags);
|
|
146
|
+
let tagNames;
|
|
147
|
+
if (doc && tagEntries.length > 0 && isNode(doc.contents)) {
|
|
148
|
+
const tags = {};
|
|
149
|
+
visit(doc.contents, (_key, node) => {
|
|
150
|
+
if (isNode(node) && node.tag)
|
|
151
|
+
tags[node.tag] = true;
|
|
152
|
+
});
|
|
153
|
+
tagNames = Object.keys(tags);
|
|
154
|
+
}
|
|
155
|
+
else
|
|
156
|
+
tagNames = [];
|
|
157
|
+
for (const [handle, prefix] of tagEntries) {
|
|
158
|
+
if (handle === '!!' && prefix === 'tag:yaml.org,2002:')
|
|
159
|
+
continue;
|
|
160
|
+
if (!doc || tagNames.some(tn => tn.startsWith(prefix)))
|
|
161
|
+
lines.push(`%TAG ${handle} ${prefix}`);
|
|
162
|
+
}
|
|
163
|
+
return lines.join('\n');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
Directives.defaultYaml = { explicit: false, version: '1.2' };
|
|
167
|
+
Directives.defaultTags = { '!!': 'tag:yaml.org,2002:' };
|
|
168
|
+
|
|
169
|
+
export { Directives };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
class YAMLError extends Error {
|
|
2
|
+
constructor(name, pos, code, message) {
|
|
3
|
+
super();
|
|
4
|
+
this.name = name;
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.message = message;
|
|
7
|
+
this.pos = pos;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
class YAMLParseError extends YAMLError {
|
|
11
|
+
constructor(pos, code, message) {
|
|
12
|
+
super('YAMLParseError', pos, code, message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
class YAMLWarning extends YAMLError {
|
|
16
|
+
constructor(pos, code, message) {
|
|
17
|
+
super('YAMLWarning', pos, code, message);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const prettifyError = (src, lc) => (error) => {
|
|
21
|
+
if (error.pos[0] === -1)
|
|
22
|
+
return;
|
|
23
|
+
error.linePos = error.pos.map(pos => lc.linePos(pos));
|
|
24
|
+
const { line, col } = error.linePos[0];
|
|
25
|
+
error.message += ` at line ${line}, column ${col}`;
|
|
26
|
+
let ci = col - 1;
|
|
27
|
+
let lineStr = src
|
|
28
|
+
.substring(lc.lineStarts[line - 1], lc.lineStarts[line])
|
|
29
|
+
.replace(/[\n\r]+$/, '');
|
|
30
|
+
// Trim to max 80 chars, keeping col position near the middle
|
|
31
|
+
if (ci >= 60 && lineStr.length > 80) {
|
|
32
|
+
const trimStart = Math.min(ci - 39, lineStr.length - 79);
|
|
33
|
+
lineStr = '…' + lineStr.substring(trimStart);
|
|
34
|
+
ci -= trimStart - 1;
|
|
35
|
+
}
|
|
36
|
+
if (lineStr.length > 80)
|
|
37
|
+
lineStr = lineStr.substring(0, 79) + '…';
|
|
38
|
+
// Include previous line in context if pointing at line start
|
|
39
|
+
if (line > 1 && /^ *$/.test(lineStr.substring(0, ci))) {
|
|
40
|
+
// Regexp won't match if start is trimmed
|
|
41
|
+
let prev = src.substring(lc.lineStarts[line - 2], lc.lineStarts[line - 1]);
|
|
42
|
+
if (prev.length > 80)
|
|
43
|
+
prev = prev.substring(0, 79) + '…\n';
|
|
44
|
+
lineStr = prev + lineStr;
|
|
45
|
+
}
|
|
46
|
+
if (/[^ ]/.test(lineStr)) {
|
|
47
|
+
let count = 1;
|
|
48
|
+
const end = error.linePos[1];
|
|
49
|
+
if (end && end.line === line && end.col > col) {
|
|
50
|
+
count = Math.min(end.col - col, 80 - ci);
|
|
51
|
+
}
|
|
52
|
+
const pointer = ' '.repeat(ci) + '^'.repeat(count);
|
|
53
|
+
error.message += `:\n\n${lineStr}\n${pointer}\n`;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export { YAMLError, YAMLParseError, YAMLWarning, prettifyError };
|