yaml 2.8.4 → 3.0.0-1
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 +65 -85
- package/{bin.mjs → bin.js} +1 -1
- package/dist/chunk-pbuEa-1d.js +13 -0
- package/dist/cli.d.ts +10 -7
- package/dist/cli.js +180 -0
- package/dist/directives-CiM56lHW.js +2963 -0
- package/dist/directives-DlYEVlkC.d.ts +1396 -0
- package/dist/index.d.ts +320 -25
- package/dist/index.js +4 -50
- package/dist/line-counter-bmCJ4fGy.js +3086 -0
- package/dist/public-api-BTMehGT6.js +77 -0
- package/dist/test-events.d.ts +6 -3
- package/dist/test-events.js +105 -126
- package/dist/util.d.ts +2 -16
- package/dist/util.js +2 -28
- package/package.json +20 -44
- package/browser/dist/compose/compose-collection.js +0 -88
- package/browser/dist/compose/compose-doc.js +0 -43
- package/browser/dist/compose/compose-node.js +0 -109
- package/browser/dist/compose/compose-scalar.js +0 -86
- package/browser/dist/compose/composer.js +0 -217
- package/browser/dist/compose/resolve-block-map.js +0 -115
- package/browser/dist/compose/resolve-block-scalar.js +0 -198
- package/browser/dist/compose/resolve-block-seq.js +0 -49
- package/browser/dist/compose/resolve-end.js +0 -37
- package/browser/dist/compose/resolve-flow-collection.js +0 -207
- package/browser/dist/compose/resolve-flow-scalar.js +0 -225
- package/browser/dist/compose/resolve-props.js +0 -146
- package/browser/dist/compose/util-contains-newline.js +0 -34
- package/browser/dist/compose/util-empty-scalar-position.js +0 -26
- package/browser/dist/compose/util-flow-indent-check.js +0 -15
- package/browser/dist/compose/util-map-includes.js +0 -13
- package/browser/dist/doc/Document.js +0 -335
- package/browser/dist/doc/anchors.js +0 -71
- package/browser/dist/doc/applyReviver.js +0 -55
- package/browser/dist/doc/createNode.js +0 -88
- package/browser/dist/doc/directives.js +0 -176
- package/browser/dist/errors.js +0 -57
- package/browser/dist/index.js +0 -17
- package/browser/dist/log.js +0 -11
- package/browser/dist/nodes/Alias.js +0 -116
- package/browser/dist/nodes/Collection.js +0 -147
- package/browser/dist/nodes/Node.js +0 -38
- package/browser/dist/nodes/Pair.js +0 -36
- package/browser/dist/nodes/Scalar.js +0 -24
- package/browser/dist/nodes/YAMLMap.js +0 -144
- package/browser/dist/nodes/YAMLSeq.js +0 -113
- package/browser/dist/nodes/addPairToJSMap.js +0 -63
- package/browser/dist/nodes/identity.js +0 -36
- package/browser/dist/nodes/toJS.js +0 -37
- package/browser/dist/parse/cst-scalar.js +0 -214
- package/browser/dist/parse/cst-stringify.js +0 -61
- package/browser/dist/parse/cst-visit.js +0 -97
- package/browser/dist/parse/cst.js +0 -98
- package/browser/dist/parse/lexer.js +0 -717
- package/browser/dist/parse/line-counter.js +0 -39
- package/browser/dist/parse/parser.js +0 -967
- package/browser/dist/public-api.js +0 -102
- package/browser/dist/schema/Schema.js +0 -37
- package/browser/dist/schema/common/map.js +0 -17
- package/browser/dist/schema/common/null.js +0 -15
- package/browser/dist/schema/common/seq.js +0 -17
- package/browser/dist/schema/common/string.js +0 -14
- package/browser/dist/schema/core/bool.js +0 -19
- package/browser/dist/schema/core/float.js +0 -43
- package/browser/dist/schema/core/int.js +0 -38
- package/browser/dist/schema/core/schema.js +0 -23
- package/browser/dist/schema/json/schema.js +0 -62
- package/browser/dist/schema/tags.js +0 -96
- package/browser/dist/schema/yaml-1.1/binary.js +0 -58
- package/browser/dist/schema/yaml-1.1/bool.js +0 -26
- package/browser/dist/schema/yaml-1.1/float.js +0 -46
- package/browser/dist/schema/yaml-1.1/int.js +0 -71
- package/browser/dist/schema/yaml-1.1/merge.js +0 -67
- package/browser/dist/schema/yaml-1.1/omap.js +0 -74
- package/browser/dist/schema/yaml-1.1/pairs.js +0 -78
- package/browser/dist/schema/yaml-1.1/schema.js +0 -39
- package/browser/dist/schema/yaml-1.1/set.js +0 -93
- package/browser/dist/schema/yaml-1.1/timestamp.js +0 -101
- package/browser/dist/stringify/foldFlowLines.js +0 -146
- package/browser/dist/stringify/stringify.js +0 -129
- package/browser/dist/stringify/stringifyCollection.js +0 -153
- package/browser/dist/stringify/stringifyComment.js +0 -20
- package/browser/dist/stringify/stringifyDocument.js +0 -85
- package/browser/dist/stringify/stringifyNumber.js +0 -25
- package/browser/dist/stringify/stringifyPair.js +0 -150
- package/browser/dist/stringify/stringifyString.js +0 -336
- package/browser/dist/util.js +0 -11
- package/browser/dist/visit.js +0 -233
- package/browser/index.js +0 -5
- package/browser/package.json +0 -3
- package/dist/cli.mjs +0 -201
- package/dist/compose/compose-collection.d.ts +0 -11
- package/dist/compose/compose-collection.js +0 -90
- package/dist/compose/compose-doc.d.ts +0 -7
- package/dist/compose/compose-doc.js +0 -45
- package/dist/compose/compose-node.d.ts +0 -29
- package/dist/compose/compose-node.js +0 -112
- package/dist/compose/compose-scalar.d.ts +0 -5
- package/dist/compose/compose-scalar.js +0 -88
- package/dist/compose/composer.d.ts +0 -63
- package/dist/compose/composer.js +0 -222
- package/dist/compose/resolve-block-map.d.ts +0 -6
- package/dist/compose/resolve-block-map.js +0 -117
- package/dist/compose/resolve-block-scalar.d.ts +0 -11
- package/dist/compose/resolve-block-scalar.js +0 -200
- package/dist/compose/resolve-block-seq.d.ts +0 -6
- package/dist/compose/resolve-block-seq.js +0 -51
- package/dist/compose/resolve-end.d.ts +0 -6
- package/dist/compose/resolve-end.js +0 -39
- package/dist/compose/resolve-flow-collection.d.ts +0 -7
- package/dist/compose/resolve-flow-collection.js +0 -209
- package/dist/compose/resolve-flow-scalar.d.ts +0 -10
- package/dist/compose/resolve-flow-scalar.js +0 -227
- package/dist/compose/resolve-props.d.ts +0 -23
- package/dist/compose/resolve-props.js +0 -148
- package/dist/compose/util-contains-newline.d.ts +0 -2
- package/dist/compose/util-contains-newline.js +0 -36
- package/dist/compose/util-empty-scalar-position.d.ts +0 -2
- package/dist/compose/util-empty-scalar-position.js +0 -28
- package/dist/compose/util-flow-indent-check.d.ts +0 -3
- package/dist/compose/util-flow-indent-check.js +0 -17
- package/dist/compose/util-map-includes.d.ts +0 -4
- package/dist/compose/util-map-includes.js +0 -15
- package/dist/doc/Document.d.ts +0 -141
- package/dist/doc/Document.js +0 -337
- package/dist/doc/anchors.d.ts +0 -24
- package/dist/doc/anchors.js +0 -76
- package/dist/doc/applyReviver.d.ts +0 -9
- package/dist/doc/applyReviver.js +0 -57
- package/dist/doc/createNode.d.ts +0 -17
- package/dist/doc/createNode.js +0 -90
- package/dist/doc/directives.d.ts +0 -49
- package/dist/doc/directives.js +0 -178
- package/dist/errors.d.ts +0 -21
- package/dist/errors.js +0 -62
- package/dist/log.d.ts +0 -3
- package/dist/log.js +0 -19
- package/dist/nodes/Alias.d.ts +0 -29
- package/dist/nodes/Alias.js +0 -118
- package/dist/nodes/Collection.d.ts +0 -73
- package/dist/nodes/Collection.js +0 -151
- package/dist/nodes/Node.d.ts +0 -53
- package/dist/nodes/Node.js +0 -40
- package/dist/nodes/Pair.d.ts +0 -22
- package/dist/nodes/Pair.js +0 -39
- package/dist/nodes/Scalar.d.ts +0 -47
- package/dist/nodes/Scalar.js +0 -27
- package/dist/nodes/YAMLMap.d.ts +0 -53
- package/dist/nodes/YAMLMap.js +0 -147
- package/dist/nodes/YAMLSeq.d.ts +0 -60
- package/dist/nodes/YAMLSeq.js +0 -115
- package/dist/nodes/addPairToJSMap.d.ts +0 -4
- package/dist/nodes/addPairToJSMap.js +0 -65
- package/dist/nodes/identity.d.ts +0 -23
- package/dist/nodes/identity.js +0 -53
- package/dist/nodes/toJS.d.ts +0 -29
- package/dist/nodes/toJS.js +0 -39
- package/dist/options.d.ts +0 -350
- package/dist/parse/cst-scalar.d.ts +0 -64
- package/dist/parse/cst-scalar.js +0 -218
- package/dist/parse/cst-stringify.d.ts +0 -8
- package/dist/parse/cst-stringify.js +0 -63
- package/dist/parse/cst-visit.d.ts +0 -39
- package/dist/parse/cst-visit.js +0 -99
- package/dist/parse/cst.d.ts +0 -109
- package/dist/parse/cst.js +0 -112
- package/dist/parse/lexer.d.ts +0 -87
- package/dist/parse/lexer.js +0 -719
- package/dist/parse/line-counter.d.ts +0 -22
- package/dist/parse/line-counter.js +0 -41
- package/dist/parse/parser.d.ts +0 -84
- package/dist/parse/parser.js +0 -972
- package/dist/public-api.d.ts +0 -44
- package/dist/public-api.js +0 -107
- package/dist/schema/Schema.d.ts +0 -17
- package/dist/schema/Schema.js +0 -39
- package/dist/schema/common/map.d.ts +0 -2
- package/dist/schema/common/map.js +0 -19
- package/dist/schema/common/null.d.ts +0 -4
- package/dist/schema/common/null.js +0 -17
- package/dist/schema/common/seq.d.ts +0 -2
- package/dist/schema/common/seq.js +0 -19
- package/dist/schema/common/string.d.ts +0 -2
- package/dist/schema/common/string.js +0 -16
- package/dist/schema/core/bool.d.ts +0 -4
- package/dist/schema/core/bool.js +0 -21
- package/dist/schema/core/float.d.ts +0 -4
- package/dist/schema/core/float.js +0 -47
- package/dist/schema/core/int.d.ts +0 -4
- package/dist/schema/core/int.js +0 -42
- package/dist/schema/core/schema.d.ts +0 -1
- package/dist/schema/core/schema.js +0 -25
- package/dist/schema/json/schema.d.ts +0 -2
- package/dist/schema/json/schema.js +0 -64
- package/dist/schema/json-schema.d.ts +0 -69
- package/dist/schema/tags.d.ts +0 -48
- package/dist/schema/tags.js +0 -99
- package/dist/schema/types.d.ts +0 -92
- package/dist/schema/yaml-1.1/binary.d.ts +0 -2
- package/dist/schema/yaml-1.1/binary.js +0 -70
- package/dist/schema/yaml-1.1/bool.d.ts +0 -7
- package/dist/schema/yaml-1.1/bool.js +0 -29
- package/dist/schema/yaml-1.1/float.d.ts +0 -4
- package/dist/schema/yaml-1.1/float.js +0 -50
- package/dist/schema/yaml-1.1/int.d.ts +0 -5
- package/dist/schema/yaml-1.1/int.js +0 -76
- package/dist/schema/yaml-1.1/merge.d.ts +0 -9
- package/dist/schema/yaml-1.1/merge.js +0 -71
- package/dist/schema/yaml-1.1/omap.d.ts +0 -22
- package/dist/schema/yaml-1.1/omap.js +0 -77
- package/dist/schema/yaml-1.1/pairs.d.ts +0 -10
- package/dist/schema/yaml-1.1/pairs.js +0 -82
- package/dist/schema/yaml-1.1/schema.d.ts +0 -1
- package/dist/schema/yaml-1.1/schema.js +0 -41
- package/dist/schema/yaml-1.1/set.d.ts +0 -28
- package/dist/schema/yaml-1.1/set.js +0 -96
- package/dist/schema/yaml-1.1/timestamp.d.ts +0 -6
- package/dist/schema/yaml-1.1/timestamp.js +0 -105
- package/dist/stringify/foldFlowLines.d.ts +0 -34
- package/dist/stringify/foldFlowLines.js +0 -151
- package/dist/stringify/stringify.d.ts +0 -21
- package/dist/stringify/stringify.js +0 -132
- package/dist/stringify/stringifyCollection.d.ts +0 -17
- package/dist/stringify/stringifyCollection.js +0 -155
- package/dist/stringify/stringifyComment.d.ts +0 -10
- package/dist/stringify/stringifyComment.js +0 -24
- package/dist/stringify/stringifyDocument.d.ts +0 -4
- package/dist/stringify/stringifyDocument.js +0 -87
- package/dist/stringify/stringifyNumber.d.ts +0 -2
- package/dist/stringify/stringifyNumber.js +0 -27
- package/dist/stringify/stringifyPair.d.ts +0 -3
- package/dist/stringify/stringifyPair.js +0 -152
- package/dist/stringify/stringifyString.d.ts +0 -9
- package/dist/stringify/stringifyString.js +0 -338
- package/dist/visit.d.ts +0 -102
- package/dist/visit.js +0 -236
- package/util.js +0 -2
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { i as Document, y as warn } from "./directives-CiM56lHW.js";
|
|
2
|
+
import { c as YAMLParseError, n as Composer, r as Parser, t as LineCounter, u as prettifyError } from "./line-counter-bmCJ4fGy.js";
|
|
3
|
+
//#region src/public-api.ts
|
|
4
|
+
function parseOptions(options) {
|
|
5
|
+
const prettyErrors = options.prettyErrors !== false;
|
|
6
|
+
return {
|
|
7
|
+
lineCounter: options.lineCounter || prettyErrors && new LineCounter() || null,
|
|
8
|
+
prettyErrors
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse the input as a stream of YAML documents.
|
|
13
|
+
*
|
|
14
|
+
* Documents should be separated from each other by `...` or `---` marker lines.
|
|
15
|
+
*
|
|
16
|
+
* @returns If an empty `docs` array is returned, it will be of type
|
|
17
|
+
* EmptyStream and contain additional stream information. In
|
|
18
|
+
* TypeScript, you should use `'empty' in docs` as a type guard for it.
|
|
19
|
+
*/
|
|
20
|
+
function parseAllDocuments(source, options = {}) {
|
|
21
|
+
const { lineCounter, prettyErrors } = parseOptions(options);
|
|
22
|
+
const parser = new Parser(lineCounter?.addNewLine);
|
|
23
|
+
const composer = new Composer(options);
|
|
24
|
+
const docs = Array.from(composer.compose(parser.parse(source)));
|
|
25
|
+
if (prettyErrors && lineCounter) for (const doc of docs) {
|
|
26
|
+
doc.errors.forEach(prettifyError(source, lineCounter));
|
|
27
|
+
doc.warnings.forEach(prettifyError(source, lineCounter));
|
|
28
|
+
}
|
|
29
|
+
if (docs.length > 0) return docs;
|
|
30
|
+
return Object.assign([], { empty: true }, composer.streamInfo());
|
|
31
|
+
}
|
|
32
|
+
/** Parse an input string into a single YAML.Document */
|
|
33
|
+
function parseDocument(source, options = {}) {
|
|
34
|
+
const { lineCounter, prettyErrors } = parseOptions(options);
|
|
35
|
+
const parser = new Parser(lineCounter?.addNewLine);
|
|
36
|
+
const composer = new Composer(options);
|
|
37
|
+
let doc = null;
|
|
38
|
+
for (const _doc of composer.compose(parser.parse(source), true, source.length)) if (!doc) doc = _doc;
|
|
39
|
+
else if (doc.options.logLevel !== "silent") {
|
|
40
|
+
doc.errors.push(new YAMLParseError(_doc.range.slice(0, 2), "MULTIPLE_DOCS", "Source contains multiple documents; please use YAML.parseAllDocuments()"));
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
if (prettyErrors && lineCounter) {
|
|
44
|
+
doc.errors.forEach(prettifyError(source, lineCounter));
|
|
45
|
+
doc.warnings.forEach(prettifyError(source, lineCounter));
|
|
46
|
+
}
|
|
47
|
+
return doc;
|
|
48
|
+
}
|
|
49
|
+
function parse(src, reviver, options) {
|
|
50
|
+
let _reviver = void 0;
|
|
51
|
+
if (typeof reviver === "function") _reviver = reviver;
|
|
52
|
+
else if (options === void 0 && reviver && typeof reviver === "object") options = reviver;
|
|
53
|
+
const doc = parseDocument(src, options);
|
|
54
|
+
if (!doc) return null;
|
|
55
|
+
doc.warnings.forEach((warning) => warn(doc.options.logLevel, warning));
|
|
56
|
+
if (doc.errors.length > 0) if (doc.options.logLevel !== "silent") throw doc.errors[0];
|
|
57
|
+
else doc.errors = [];
|
|
58
|
+
return doc.toJS(Object.assign({ reviver: _reviver }, options));
|
|
59
|
+
}
|
|
60
|
+
function stringify(value, replacer, options) {
|
|
61
|
+
let _replacer = null;
|
|
62
|
+
if (typeof replacer === "function" || Array.isArray(replacer)) _replacer = replacer;
|
|
63
|
+
else if (options === void 0 && replacer) options = replacer;
|
|
64
|
+
if (typeof options === "string") options = options.length;
|
|
65
|
+
if (typeof options === "number") {
|
|
66
|
+
const indent = Math.round(options);
|
|
67
|
+
options = indent < 1 ? void 0 : indent > 8 ? { indent: 8 } : { indent };
|
|
68
|
+
}
|
|
69
|
+
if (value === void 0) {
|
|
70
|
+
const { keepUndefined } = options ?? replacer ?? {};
|
|
71
|
+
if (!keepUndefined) return void 0;
|
|
72
|
+
}
|
|
73
|
+
if (value instanceof Document && !_replacer) return value.toString(options);
|
|
74
|
+
return new Document(value, _replacer, options).toString(options);
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { stringify as i, parseAllDocuments as n, parseDocument as r, parse as t };
|
package/dist/test-events.d.ts
CHANGED
package/dist/test-events.js
CHANGED
|
@@ -1,134 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var publicApi = require('./public-api.js');
|
|
5
|
-
var visit = require('./visit.js');
|
|
6
|
-
|
|
1
|
+
import { S as Scalar, d as Pair, g as YAMLMap, h as YAMLSeq, m as YAMLSet, n as visit, p as isNode, u as Alias } from "./directives-CiM56lHW.js";
|
|
2
|
+
import { n as parseAllDocuments } from "./public-api-BTMehGT6.js";
|
|
3
|
+
//#region src/test-events.ts
|
|
7
4
|
const scalarChar = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
BLOCK_FOLDED: ">",
|
|
6
|
+
BLOCK_LITERAL: "|",
|
|
7
|
+
PLAIN: ":",
|
|
8
|
+
QUOTE_DOUBLE: "\"",
|
|
9
|
+
QUOTE_SINGLE: "'"
|
|
13
10
|
};
|
|
14
11
|
function anchorExists(doc, anchor) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
return found;
|
|
12
|
+
let found = false;
|
|
13
|
+
visit(doc, { Value(_key, node) {
|
|
14
|
+
if (node.anchor === anchor) {
|
|
15
|
+
found = true;
|
|
16
|
+
return visit.BREAK;
|
|
17
|
+
}
|
|
18
|
+
} });
|
|
19
|
+
return found;
|
|
25
20
|
}
|
|
26
|
-
// test harness for yaml-test-suite event tests
|
|
27
21
|
function testEvents(src) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return { events, error: error ?? e };
|
|
60
|
-
}
|
|
61
|
-
events.push('-STR');
|
|
62
|
-
return { events, error };
|
|
22
|
+
const docs = parseAllDocuments(src);
|
|
23
|
+
const errDoc = docs.find((doc) => doc.errors.length > 0);
|
|
24
|
+
const error = errDoc ? errDoc.errors[0].message : null;
|
|
25
|
+
const events = ["+STR"];
|
|
26
|
+
try {
|
|
27
|
+
for (let i = 0; i < docs.length; ++i) {
|
|
28
|
+
const doc = docs[i];
|
|
29
|
+
const root = doc.value;
|
|
30
|
+
const [rootStart] = doc.range || [0];
|
|
31
|
+
const error = doc.errors[0];
|
|
32
|
+
if (error && (!error.pos || error.pos[0] < rootStart)) throw new Error();
|
|
33
|
+
let docStart = "+DOC";
|
|
34
|
+
if (doc.directives.docStart) docStart += " ---";
|
|
35
|
+
else if (root.range[2] === root.range[0] && !root.anchor && !root.tag) continue;
|
|
36
|
+
events.push(docStart);
|
|
37
|
+
addEvents(events, doc, error?.pos[0] ?? -1, root);
|
|
38
|
+
let docEnd = "-DOC";
|
|
39
|
+
if (doc.directives.docEnd) docEnd += " ...";
|
|
40
|
+
events.push(docEnd);
|
|
41
|
+
}
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return {
|
|
44
|
+
events,
|
|
45
|
+
error: error ?? e
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
events.push("-STR");
|
|
49
|
+
return {
|
|
50
|
+
events,
|
|
51
|
+
error
|
|
52
|
+
};
|
|
63
53
|
}
|
|
64
54
|
function addEvents(events, doc, errPos, node) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
.replace(/\0/g, '\\0')
|
|
122
|
-
.replace(/\x07/g, '\\a')
|
|
123
|
-
.replace(/\x08/g, '\\b')
|
|
124
|
-
.replace(/\t/g, '\\t')
|
|
125
|
-
.replace(/\n/g, '\\n')
|
|
126
|
-
.replace(/\v/g, '\\v')
|
|
127
|
-
.replace(/\f/g, '\\f')
|
|
128
|
-
.replace(/\r/g, '\\r')
|
|
129
|
-
.replace(/\x1b/g, '\\e');
|
|
130
|
-
events.push(`=VAL${props} ${scalar}${value}`);
|
|
131
|
-
}
|
|
55
|
+
if (!node) {
|
|
56
|
+
events.push("=VAL :");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (errPos !== -1 && isNode(node) && node.range[0] >= errPos) throw new Error();
|
|
60
|
+
let props = "";
|
|
61
|
+
let anchor = isNode(node) ? node.anchor : void 0;
|
|
62
|
+
if (anchor) {
|
|
63
|
+
if (/\d$/.test(anchor)) {
|
|
64
|
+
const alt = anchor.replace(/\d$/, "");
|
|
65
|
+
if (anchorExists(doc, alt)) anchor = alt;
|
|
66
|
+
}
|
|
67
|
+
props = ` &${anchor}`;
|
|
68
|
+
}
|
|
69
|
+
if (isNode(node) && node.tag) props += ` <${node.tag}>`;
|
|
70
|
+
if (node instanceof YAMLMap) {
|
|
71
|
+
const ev = node.flow ? "+MAP {}" : "+MAP";
|
|
72
|
+
events.push(`${ev}${props}`);
|
|
73
|
+
for (const { key, value } of node.values.values()) {
|
|
74
|
+
addEvents(events, doc, errPos, key);
|
|
75
|
+
addEvents(events, doc, errPos, value);
|
|
76
|
+
}
|
|
77
|
+
events.push("-MAP");
|
|
78
|
+
} else if (node instanceof YAMLSeq) {
|
|
79
|
+
const ev = node.flow ? "+SEQ []" : "+SEQ";
|
|
80
|
+
events.push(`${ev}${props}`);
|
|
81
|
+
node.forEach((item) => {
|
|
82
|
+
addEvents(events, doc, errPos, item);
|
|
83
|
+
});
|
|
84
|
+
events.push("-SEQ");
|
|
85
|
+
} else if (node instanceof YAMLSet) {
|
|
86
|
+
const ev = node.flow ? "+MAP {}" : "+MAP";
|
|
87
|
+
events.push(`${ev}${props}`);
|
|
88
|
+
for (const value of node.values.values()) {
|
|
89
|
+
addEvents(events, doc, errPos, value);
|
|
90
|
+
events.push("=VAL :");
|
|
91
|
+
}
|
|
92
|
+
events.push("-MAP");
|
|
93
|
+
} else if (node instanceof Pair) {
|
|
94
|
+
events.push(`+MAP${props}`);
|
|
95
|
+
addEvents(events, doc, errPos, node.key);
|
|
96
|
+
addEvents(events, doc, errPos, node.value);
|
|
97
|
+
events.push("-MAP");
|
|
98
|
+
} else if (node instanceof Alias) {
|
|
99
|
+
let alias = node.source;
|
|
100
|
+
if (alias && /\d$/.test(alias)) {
|
|
101
|
+
const alt = alias.replace(/\d$/, "");
|
|
102
|
+
if (anchorExists(doc, alt)) alias = alt;
|
|
103
|
+
}
|
|
104
|
+
events.push(`=ALI${props} *${alias}`);
|
|
105
|
+
} else if (node instanceof Scalar) {
|
|
106
|
+
const scalar = scalarChar[String(node.type)];
|
|
107
|
+
if (!scalar) throw new Error(`Unexpected node type ${node.type}`);
|
|
108
|
+
const value = node.source.replace(/\\/g, "\\\\").replace(/\0/g, "\\0").replace(/\x07/g, "\\a").replace(/\x08/g, "\\b").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\v/g, "\\v").replace(/\f/g, "\\f").replace(/\r/g, "\\r").replace(/\x1b/g, "\\e");
|
|
109
|
+
events.push(`=VAL${props} ${scalar}${value}`);
|
|
110
|
+
} else throw new Error(`Unexpected node ${node}`);
|
|
132
111
|
}
|
|
133
|
-
|
|
134
|
-
|
|
112
|
+
//#endregion
|
|
113
|
+
export { testEvents };
|
package/dist/util.d.ts
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export { debug, warn } from './log';
|
|
4
|
-
export type { LogLevelId } from './log';
|
|
5
|
-
export { createPair } from './nodes/Pair';
|
|
6
|
-
export { toJS } from './nodes/toJS';
|
|
7
|
-
export type { ToJSContext } from './nodes/toJS';
|
|
8
|
-
export { findPair } from './nodes/YAMLMap';
|
|
9
|
-
export { map as mapTag } from './schema/common/map';
|
|
10
|
-
export { seq as seqTag } from './schema/common/seq';
|
|
11
|
-
export { string as stringTag } from './schema/common/string';
|
|
12
|
-
export { foldFlowLines } from './stringify/foldFlowLines';
|
|
13
|
-
export type { FoldOptions } from './stringify/foldFlowLines';
|
|
14
|
-
export type { StringifyContext } from './stringify/stringify';
|
|
15
|
-
export { stringifyNumber } from './stringify/stringifyNumber';
|
|
16
|
-
export { stringifyString } from './stringify/stringifyString';
|
|
1
|
+
import { B as debug, I as NodeCreator, L as ToJSContext, R as StringifyContext, V as warn, _ as string, b as map, g as foldFlowLines, h as FoldOptions, m as stringifyNumber, p as stringifyString, v as seq, z as LogLevelId } from "./directives-DlYEVlkC.js";
|
|
2
|
+
export { FoldOptions, LogLevelId, NodeCreator, StringifyContext, ToJSContext, debug, foldFlowLines, map as mapTag, seq as seqTag, string as stringTag, stringifyNumber, stringifyString, warn };
|
package/dist/util.js
CHANGED
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var createNode = require('./doc/createNode.js');
|
|
4
|
-
var log = require('./log.js');
|
|
5
|
-
var Pair = require('./nodes/Pair.js');
|
|
6
|
-
var toJS = require('./nodes/toJS.js');
|
|
7
|
-
var YAMLMap = require('./nodes/YAMLMap.js');
|
|
8
|
-
var map = require('./schema/common/map.js');
|
|
9
|
-
var seq = require('./schema/common/seq.js');
|
|
10
|
-
var string = require('./schema/common/string.js');
|
|
11
|
-
var foldFlowLines = require('./stringify/foldFlowLines.js');
|
|
12
|
-
var stringifyNumber = require('./stringify/stringifyNumber.js');
|
|
13
|
-
var stringifyString = require('./stringify/stringifyString.js');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
exports.createNode = createNode.createNode;
|
|
18
|
-
exports.debug = log.debug;
|
|
19
|
-
exports.warn = log.warn;
|
|
20
|
-
exports.createPair = Pair.createPair;
|
|
21
|
-
exports.toJS = toJS.toJS;
|
|
22
|
-
exports.findPair = YAMLMap.findPair;
|
|
23
|
-
exports.mapTag = map.map;
|
|
24
|
-
exports.seqTag = seq.seq;
|
|
25
|
-
exports.stringTag = string.string;
|
|
26
|
-
exports.foldFlowLines = foldFlowLines.foldFlowLines;
|
|
27
|
-
exports.stringifyNumber = stringifyNumber.stringifyNumber;
|
|
28
|
-
exports.stringifyString = stringifyString.stringifyString;
|
|
1
|
+
import { _ as ToJSContext, b as stringifyString, c as seq, l as map, o as stringifyNumber, s as string, v as debug, x as foldFlowLines, y as warn } from "./directives-CiM56lHW.js";
|
|
2
|
+
export { ToJSContext, debug, foldFlowLines, map as mapTag, seq as seqTag, string as stringTag, stringifyNumber, stringifyString, warn };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yaml",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-1",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"author": "Eemeli Aro <eemeli@gmail.com>",
|
|
6
6
|
"funding": "https://github.com/sponsors/eemeli",
|
|
@@ -13,55 +13,41 @@
|
|
|
13
13
|
],
|
|
14
14
|
"homepage": "https://eemeli.org/yaml/",
|
|
15
15
|
"files": [
|
|
16
|
-
"
|
|
17
|
-
"dist/",
|
|
18
|
-
"util.js"
|
|
16
|
+
"dist/"
|
|
19
17
|
],
|
|
20
|
-
"type": "
|
|
18
|
+
"type": "module",
|
|
21
19
|
"main": "./dist/index.js",
|
|
22
|
-
"bin": "./bin.
|
|
23
|
-
"browser": {
|
|
24
|
-
"./dist/index.js": "./browser/index.js",
|
|
25
|
-
"./dist/util.js": "./browser/dist/util.js",
|
|
26
|
-
"./util.js": "./browser/dist/util.js"
|
|
27
|
-
},
|
|
20
|
+
"bin": "./bin.js",
|
|
28
21
|
"exports": {
|
|
29
22
|
".": {
|
|
30
23
|
"types": "./dist/index.d.ts",
|
|
31
|
-
"
|
|
32
|
-
"default": "./browser/index.js"
|
|
24
|
+
"default": "./dist/index.js"
|
|
33
25
|
},
|
|
34
26
|
"./package.json": "./package.json",
|
|
35
27
|
"./util": {
|
|
36
28
|
"types": "./dist/util.d.ts",
|
|
37
|
-
"
|
|
38
|
-
"default": "./browser/dist/util.js"
|
|
29
|
+
"default": "./dist/util.js"
|
|
39
30
|
}
|
|
40
31
|
},
|
|
41
32
|
"scripts": {
|
|
42
|
-
"build": "
|
|
43
|
-
"build:browser": "rollup -c config/rollup.browser-config.mjs",
|
|
44
|
-
"build:node": "rollup -c config/rollup.node-config.mjs",
|
|
33
|
+
"build": "rolldown -c",
|
|
45
34
|
"clean": "git clean -fdxe node_modules",
|
|
46
|
-
"lint": "eslint
|
|
35
|
+
"lint": "eslint src/",
|
|
47
36
|
"prettier": "prettier --write .",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"test": "jest --config config/jest.config.js",
|
|
37
|
+
"start": "node -i -e 'YAML=require(\"./src/index.ts\");const{parse,parseDocument,parseAllDocuments,stringify}=YAML'",
|
|
38
|
+
"test": "vitest run",
|
|
51
39
|
"test:all": "npm test && npm run test:types && npm run test:dist && npm run test:dist:types",
|
|
52
|
-
"test:
|
|
53
|
-
"test:dist": "
|
|
54
|
-
"test:dist:types": "tsc --allowJs --moduleResolution node --noEmit --target es5 dist/index.js",
|
|
40
|
+
"test:dist": "npm run build && vitest run",
|
|
41
|
+
"test:dist:types": "tsc --allowJs --moduleResolution node --noEmit --target es5 dist/cli.js dist/index.js dist/test-events.js dist/util.js",
|
|
55
42
|
"test:types": "tsc --noEmit && tsc --noEmit -p tests/tsconfig.json",
|
|
56
43
|
"docs:install": "cd docs-slate && bundle install",
|
|
57
|
-
"predocs:deploy": "node docs/prepare-docs.
|
|
44
|
+
"predocs:deploy": "node docs/prepare-docs.js",
|
|
58
45
|
"docs:deploy": "cd docs-slate && ./deploy.sh",
|
|
59
|
-
"predocs": "node docs/prepare-docs.
|
|
46
|
+
"predocs": "node docs/prepare-docs.js",
|
|
60
47
|
"docs": "cd docs-slate && bundle exec middleman server",
|
|
61
48
|
"preversion": "npm test && npm run build",
|
|
62
49
|
"prepublishOnly": "npm run clean && npm test && npm run build"
|
|
63
50
|
},
|
|
64
|
-
"browserslist": "defaults, not ie 11",
|
|
65
51
|
"prettier": {
|
|
66
52
|
"arrowParens": "avoid",
|
|
67
53
|
"semi": false,
|
|
@@ -69,29 +55,19 @@
|
|
|
69
55
|
"trailingComma": "none"
|
|
70
56
|
},
|
|
71
57
|
"devDependencies": {
|
|
72
|
-
"@babel/core": "^7.12.10",
|
|
73
|
-
"@babel/plugin-transform-typescript": "^7.12.17",
|
|
74
|
-
"@babel/preset-env": "^7.12.11",
|
|
75
58
|
"@eslint/js": "^9.9.1",
|
|
76
|
-
"@rollup/plugin-babel": "^6.0.3",
|
|
77
|
-
"@rollup/plugin-replace": "^6.0.3",
|
|
78
|
-
"@rollup/plugin-typescript": "^12.1.1",
|
|
79
|
-
"@types/jest": "^29.2.4",
|
|
80
59
|
"@types/node": "^20.11.20",
|
|
81
|
-
"babel-jest": "^29.0.1",
|
|
82
60
|
"eslint": "^9.9.1",
|
|
83
61
|
"eslint-config-prettier": "^10.1.8",
|
|
84
62
|
"fast-check": "^2.12.0",
|
|
85
|
-
"jest": "^29.0.1",
|
|
86
|
-
"jest-resolve": "^29.7.0",
|
|
87
|
-
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
88
63
|
"prettier": "^3.0.2",
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"typescript": "^5.
|
|
92
|
-
"typescript-eslint": "^8.4.0"
|
|
64
|
+
"rolldown": "^1.0.0-beta.54",
|
|
65
|
+
"rolldown-plugin-dts": "^0.22.1",
|
|
66
|
+
"typescript": "^5.9.3",
|
|
67
|
+
"typescript-eslint": "^8.4.0",
|
|
68
|
+
"vitest": "^4.0.15"
|
|
93
69
|
},
|
|
94
70
|
"engines": {
|
|
95
|
-
"node": "
|
|
71
|
+
"node": "^20.19 || ^22.12 || >=24"
|
|
96
72
|
}
|
|
97
73
|
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { isNode } from '../nodes/identity.js';
|
|
2
|
-
import { Scalar } from '../nodes/Scalar.js';
|
|
3
|
-
import { YAMLMap } from '../nodes/YAMLMap.js';
|
|
4
|
-
import { YAMLSeq } from '../nodes/YAMLSeq.js';
|
|
5
|
-
import { resolveBlockMap } from './resolve-block-map.js';
|
|
6
|
-
import { resolveBlockSeq } from './resolve-block-seq.js';
|
|
7
|
-
import { resolveFlowCollection } from './resolve-flow-collection.js';
|
|
8
|
-
|
|
9
|
-
function resolveCollection(CN, ctx, token, onError, tagName, tag) {
|
|
10
|
-
const coll = token.type === 'block-map'
|
|
11
|
-
? resolveBlockMap(CN, ctx, token, onError, tag)
|
|
12
|
-
: token.type === 'block-seq'
|
|
13
|
-
? resolveBlockSeq(CN, ctx, token, onError, tag)
|
|
14
|
-
: resolveFlowCollection(CN, ctx, token, onError, tag);
|
|
15
|
-
const Coll = coll.constructor;
|
|
16
|
-
// If we got a tagName matching the class, or the tag name is '!',
|
|
17
|
-
// then use the tagName from the node class used to create it.
|
|
18
|
-
if (tagName === '!' || tagName === Coll.tagName) {
|
|
19
|
-
coll.tag = Coll.tagName;
|
|
20
|
-
return coll;
|
|
21
|
-
}
|
|
22
|
-
if (tagName)
|
|
23
|
-
coll.tag = tagName;
|
|
24
|
-
return coll;
|
|
25
|
-
}
|
|
26
|
-
function composeCollection(CN, ctx, token, props, onError) {
|
|
27
|
-
const tagToken = props.tag;
|
|
28
|
-
const tagName = !tagToken
|
|
29
|
-
? null
|
|
30
|
-
: ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg));
|
|
31
|
-
if (token.type === 'block-seq') {
|
|
32
|
-
const { anchor, newlineAfterProp: nl } = props;
|
|
33
|
-
const lastProp = anchor && tagToken
|
|
34
|
-
? anchor.offset > tagToken.offset
|
|
35
|
-
? anchor
|
|
36
|
-
: tagToken
|
|
37
|
-
: (anchor ?? tagToken);
|
|
38
|
-
if (lastProp && (!nl || nl.offset < lastProp.offset)) {
|
|
39
|
-
const message = 'Missing newline after block sequence props';
|
|
40
|
-
onError(lastProp, 'MISSING_CHAR', message);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
const expType = token.type === 'block-map'
|
|
44
|
-
? 'map'
|
|
45
|
-
: token.type === 'block-seq'
|
|
46
|
-
? 'seq'
|
|
47
|
-
: token.start.source === '{'
|
|
48
|
-
? 'map'
|
|
49
|
-
: 'seq';
|
|
50
|
-
// shortcut: check if it's a generic YAMLMap or YAMLSeq
|
|
51
|
-
// before jumping into the custom tag logic.
|
|
52
|
-
if (!tagToken ||
|
|
53
|
-
!tagName ||
|
|
54
|
-
tagName === '!' ||
|
|
55
|
-
(tagName === YAMLMap.tagName && expType === 'map') ||
|
|
56
|
-
(tagName === YAMLSeq.tagName && expType === 'seq')) {
|
|
57
|
-
return resolveCollection(CN, ctx, token, onError, tagName);
|
|
58
|
-
}
|
|
59
|
-
let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType);
|
|
60
|
-
if (!tag) {
|
|
61
|
-
const kt = ctx.schema.knownTags[tagName];
|
|
62
|
-
if (kt?.collection === expType) {
|
|
63
|
-
ctx.schema.tags.push(Object.assign({}, kt, { default: false }));
|
|
64
|
-
tag = kt;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
if (kt) {
|
|
68
|
-
onError(tagToken, 'BAD_COLLECTION_TYPE', `${kt.tag} used for ${expType} collection, but expects ${kt.collection ?? 'scalar'}`, true);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, true);
|
|
72
|
-
}
|
|
73
|
-
return resolveCollection(CN, ctx, token, onError, tagName);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const coll = resolveCollection(CN, ctx, token, onError, tagName, tag);
|
|
77
|
-
const res = tag.resolve?.(coll, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg), ctx.options) ?? coll;
|
|
78
|
-
const node = isNode(res)
|
|
79
|
-
? res
|
|
80
|
-
: new Scalar(res);
|
|
81
|
-
node.range = coll.range;
|
|
82
|
-
node.tag = tagName;
|
|
83
|
-
if (tag?.format)
|
|
84
|
-
node.format = tag.format;
|
|
85
|
-
return node;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export { composeCollection };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Document } from '../doc/Document.js';
|
|
2
|
-
import { composeNode, composeEmptyNode } from './compose-node.js';
|
|
3
|
-
import { resolveEnd } from './resolve-end.js';
|
|
4
|
-
import { resolveProps } from './resolve-props.js';
|
|
5
|
-
|
|
6
|
-
function composeDoc(options, directives, { offset, start, value, end }, onError) {
|
|
7
|
-
const opts = Object.assign({ _directives: directives }, options);
|
|
8
|
-
const doc = new Document(undefined, opts);
|
|
9
|
-
const ctx = {
|
|
10
|
-
atKey: false,
|
|
11
|
-
atRoot: true,
|
|
12
|
-
directives: doc.directives,
|
|
13
|
-
options: doc.options,
|
|
14
|
-
schema: doc.schema
|
|
15
|
-
};
|
|
16
|
-
const props = resolveProps(start, {
|
|
17
|
-
indicator: 'doc-start',
|
|
18
|
-
next: value ?? end?.[0],
|
|
19
|
-
offset,
|
|
20
|
-
onError,
|
|
21
|
-
parentIndent: 0,
|
|
22
|
-
startOnNewline: true
|
|
23
|
-
});
|
|
24
|
-
if (props.found) {
|
|
25
|
-
doc.directives.docStart = true;
|
|
26
|
-
if (value &&
|
|
27
|
-
(value.type === 'block-map' || value.type === 'block-seq') &&
|
|
28
|
-
!props.hasNewline)
|
|
29
|
-
onError(props.end, 'MISSING_CHAR', 'Block collection cannot start on same line with directives-end marker');
|
|
30
|
-
}
|
|
31
|
-
// @ts-expect-error If Contents is set, let's trust the user
|
|
32
|
-
doc.contents = value
|
|
33
|
-
? composeNode(ctx, value, props, onError)
|
|
34
|
-
: composeEmptyNode(ctx, props.end, start, null, props, onError);
|
|
35
|
-
const contentEnd = doc.contents.range[2];
|
|
36
|
-
const re = resolveEnd(end, contentEnd, false, onError);
|
|
37
|
-
if (re.comment)
|
|
38
|
-
doc.comment = re.comment;
|
|
39
|
-
doc.range = [offset, contentEnd, re.offset];
|
|
40
|
-
return doc;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { composeDoc };
|