yaml 2.0.0-2 → 2.0.0-6
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 +46 -26
- package/browser/dist/compose/compose-collection.js +59 -0
- package/browser/dist/compose/compose-doc.js +39 -0
- package/browser/dist/compose/compose-node.js +72 -0
- package/browser/dist/compose/compose-scalar.js +74 -0
- package/browser/dist/compose/composer.js +218 -0
- package/browser/dist/compose/resolve-block-map.js +93 -0
- package/browser/dist/compose/resolve-block-scalar.js +185 -0
- package/browser/dist/compose/resolve-block-seq.js +40 -0
- package/browser/dist/compose/resolve-end.js +37 -0
- package/browser/dist/compose/resolve-flow-collection.js +189 -0
- package/browser/dist/compose/resolve-flow-scalar.js +211 -0
- package/browser/dist/compose/resolve-props.js +126 -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-map-includes.js +17 -0
- package/browser/dist/doc/Document.js +251 -348
- package/browser/dist/doc/anchors.js +72 -0
- package/browser/dist/doc/applyReviver.js +41 -28
- package/browser/dist/doc/createNode.js +71 -55
- package/browser/dist/doc/directives.js +161 -0
- package/browser/dist/errors.js +50 -72
- package/browser/dist/index.js +17 -73
- package/browser/dist/log.js +11 -7
- package/browser/dist/nodes/Alias.js +94 -0
- package/browser/dist/nodes/Collection.js +133 -0
- package/browser/dist/nodes/Node.js +41 -0
- package/browser/dist/nodes/Pair.js +28 -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 +103 -0
- package/browser/dist/nodes/toJS.js +35 -0
- package/browser/dist/options.js +14 -95
- 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/browser/dist/parse/cst.js +98 -0
- package/browser/dist/parse/lexer.js +656 -0
- package/browser/dist/parse/line-counter.js +39 -0
- package/browser/dist/parse/parser.js +876 -0
- package/browser/dist/public-api.js +101 -0
- package/browser/dist/schema/Schema.js +23 -0
- package/browser/dist/schema/common/map.js +42 -0
- package/browser/dist/schema/common/null.js +13 -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 +40 -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 +79 -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 +43 -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 +121 -139
- package/browser/dist/stringify/stringify.js +87 -72
- 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/stringifyNumber.js +20 -23
- package/browser/dist/stringify/stringifyPair.js +111 -0
- package/browser/dist/stringify/stringifyString.js +295 -322
- package/browser/dist/util.js +4 -4
- package/browser/dist/visit.js +146 -0
- package/browser/index.js +4 -1
- 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 +41 -0
- package/dist/compose/compose-node.d.ts +25 -0
- package/dist/compose/compose-node.js +75 -0
- package/dist/compose/compose-scalar.d.ts +5 -0
- package/dist/compose/compose-scalar.js +76 -0
- package/dist/compose/composer.d.ts +62 -0
- package/dist/compose/composer.js +222 -0
- package/dist/compose/resolve-block-map.d.ts +6 -0
- package/dist/compose/resolve-block-map.js +95 -0
- package/dist/compose/resolve-block-scalar.d.ts +10 -0
- package/dist/compose/resolve-block-scalar.js +187 -0
- package/dist/compose/resolve-block-seq.d.ts +5 -0
- package/dist/compose/resolve-block-seq.js +42 -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 +191 -0
- package/dist/compose/resolve-flow-scalar.d.ts +10 -0
- package/dist/compose/resolve-flow-scalar.js +213 -0
- package/dist/compose/resolve-props.d.ts +21 -0
- package/dist/compose/resolve-props.js +128 -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-map-includes.d.ts +4 -0
- package/dist/compose/util-map-includes.js +19 -0
- package/dist/doc/Document.d.ts +130 -0
- package/dist/doc/Document.js +250 -347
- 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 +41 -28
- package/dist/doc/createNode.d.ts +16 -0
- package/dist/doc/createNode.js +71 -55
- package/dist/doc/directives.d.ts +46 -0
- package/dist/doc/directives.js +163 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.js +51 -74
- package/dist/index.d.ts +19 -0
- package/dist/index.js +40 -71
- package/dist/log.d.ts +3 -0
- package/dist/log.js +11 -6
- package/dist/nodes/Alias.d.ts +24 -0
- package/dist/nodes/Alias.js +96 -0
- package/dist/nodes/Collection.d.ts +67 -0
- package/dist/nodes/Collection.js +137 -0
- package/dist/nodes/Node.d.ts +48 -0
- package/dist/nodes/Node.js +59 -0
- package/dist/nodes/Pair.d.ts +16 -0
- package/dist/nodes/Pair.js +31 -0
- package/dist/nodes/Scalar.d.ts +40 -0
- package/dist/nodes/Scalar.js +26 -0
- package/dist/nodes/YAMLMap.d.ts +39 -0
- package/dist/nodes/YAMLMap.js +119 -0
- package/dist/nodes/YAMLSeq.d.ts +53 -0
- package/dist/nodes/YAMLSeq.js +107 -0
- package/dist/nodes/addPairToJSMap.d.ts +3 -0
- package/dist/nodes/addPairToJSMap.js +105 -0
- package/dist/nodes/toJS.d.ts +30 -0
- package/dist/nodes/toJS.js +37 -0
- package/dist/options.d.ts +278 -0
- package/dist/options.js +13 -96
- 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/cst.d.ts +106 -0
- package/dist/parse/cst.js +112 -0
- package/dist/parse/lexer.d.ts +85 -0
- package/dist/parse/lexer.js +658 -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 +880 -0
- package/dist/public-api.d.ts +43 -0
- package/dist/public-api.js +106 -0
- package/dist/schema/Schema.d.ts +16 -0
- package/dist/schema/Schema.js +25 -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 +15 -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 +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/schema/json/schema.js +64 -0
- package/dist/schema/tags.d.ts +41 -0
- package/dist/schema/tags.js +82 -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 +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/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 +121 -139
- package/dist/stringify/stringify.d.ts +18 -0
- package/dist/stringify/stringify.js +87 -71
- 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/stringifyNumber.d.ts +2 -0
- package/dist/stringify/stringifyNumber.js +20 -23
- package/dist/stringify/stringifyPair.d.ts +3 -0
- package/dist/stringify/stringifyPair.js +113 -0
- package/dist/stringify/stringifyString.d.ts +3 -0
- package/dist/stringify/stringifyString.js +295 -322
- package/dist/test-events.d.ts +4 -0
- package/dist/test-events.js +124 -148
- package/dist/util.d.ts +6 -0
- package/dist/util.js +9 -12
- package/dist/visit.d.ts +63 -0
- package/dist/visit.js +148 -0
- package/package.json +31 -39
- package/util.js +2 -14
- package/browser/dist/_virtual/_rollupPluginBabelHelpers.js +0 -16
- package/browser/dist/ast/Alias.js +0 -95
- package/browser/dist/ast/Collection.js +0 -192
- package/browser/dist/ast/Merge.js +0 -71
- package/browser/dist/ast/Node.js +0 -3
- package/browser/dist/ast/Pair.js +0 -200
- package/browser/dist/ast/Scalar.js +0 -21
- package/browser/dist/ast/YAMLMap.js +0 -91
- package/browser/dist/ast/YAMLSeq.js +0 -67
- package/browser/dist/ast/toJS.js +0 -29
- package/browser/dist/ast/visit.js +0 -83
- package/browser/dist/constants.js +0 -40
- package/browser/dist/cst/Alias.js +0 -26
- package/browser/dist/cst/BlankLine.js +0 -34
- package/browser/dist/cst/BlockValue.js +0 -240
- package/browser/dist/cst/Collection.js +0 -259
- package/browser/dist/cst/CollectionItem.js +0 -123
- package/browser/dist/cst/Comment.js +0 -27
- package/browser/dist/cst/Directive.js +0 -53
- package/browser/dist/cst/Document.js +0 -262
- package/browser/dist/cst/FlowCollection.js +0 -201
- package/browser/dist/cst/Node.js +0 -355
- package/browser/dist/cst/ParseContext.js +0 -234
- package/browser/dist/cst/PlainValue.js +0 -171
- package/browser/dist/cst/QuoteDouble.js +0 -224
- package/browser/dist/cst/QuoteSingle.js +0 -100
- package/browser/dist/cst/Range.js +0 -56
- package/browser/dist/cst/parse.js +0 -46
- package/browser/dist/cst/source-utils.js +0 -169
- package/browser/dist/doc/Anchors.js +0 -115
- package/browser/dist/doc/Schema.js +0 -34
- package/browser/dist/doc/getSchemaTags.js +0 -33
- package/browser/dist/doc/listTagNames.js +0 -27
- package/browser/dist/doc/parseContents.js +0 -60
- package/browser/dist/doc/parseDirectives.js +0 -107
- package/browser/dist/resolve/collection-utils.js +0 -86
- package/browser/dist/resolve/resolveMap.js +0 -315
- package/browser/dist/resolve/resolveNode.js +0 -173
- package/browser/dist/resolve/resolveScalar.js +0 -20
- package/browser/dist/resolve/resolveSeq.js +0 -170
- package/browser/dist/resolve/resolveTag.js +0 -107
- package/browser/dist/resolve/resolveTagName.js +0 -87
- package/browser/dist/stringify/addComment.js +0 -10
- package/browser/dist/stringify/stringifyTag.js +0 -28
- package/browser/dist/tags/core.js +0 -128
- package/browser/dist/tags/failsafe/index.js +0 -7
- package/browser/dist/tags/failsafe/map.js +0 -37
- package/browser/dist/tags/failsafe/seq.js +0 -34
- package/browser/dist/tags/failsafe/string.js +0 -20
- package/browser/dist/tags/index.js +0 -39
- package/browser/dist/tags/json.js +0 -62
- package/browser/dist/tags/options.js +0 -31
- package/browser/dist/tags/yaml-1.1/binary.js +0 -83
- package/browser/dist/tags/yaml-1.1/index.js +0 -174
- package/browser/dist/tags/yaml-1.1/omap.js +0 -86
- package/browser/dist/tags/yaml-1.1/pairs.js +0 -62
- package/browser/dist/tags/yaml-1.1/set.js +0 -78
- package/browser/dist/tags/yaml-1.1/timestamp.js +0 -101
- package/browser/dist/types.js +0 -10
- package/cst.d.ts +0 -185
- package/dist/_virtual/_rollupPluginBabelHelpers.js +0 -18
- package/dist/ast/Alias.js +0 -97
- package/dist/ast/Collection.js +0 -196
- package/dist/ast/Merge.js +0 -74
- package/dist/ast/Node.js +0 -5
- package/dist/ast/Pair.js +0 -203
- package/dist/ast/Scalar.js +0 -24
- package/dist/ast/YAMLMap.js +0 -94
- package/dist/ast/YAMLSeq.js +0 -69
- package/dist/ast/toJS.js +0 -31
- package/dist/ast/visit.js +0 -85
- package/dist/constants.js +0 -46
- package/dist/cst/Alias.js +0 -28
- package/dist/cst/BlankLine.js +0 -36
- package/dist/cst/BlockValue.js +0 -243
- package/dist/cst/Collection.js +0 -262
- package/dist/cst/CollectionItem.js +0 -125
- package/dist/cst/Comment.js +0 -29
- package/dist/cst/Directive.js +0 -55
- package/dist/cst/Document.js +0 -264
- package/dist/cst/FlowCollection.js +0 -203
- package/dist/cst/Node.js +0 -357
- package/dist/cst/ParseContext.js +0 -236
- package/dist/cst/PlainValue.js +0 -173
- package/dist/cst/QuoteDouble.js +0 -226
- package/dist/cst/QuoteSingle.js +0 -102
- package/dist/cst/Range.js +0 -58
- package/dist/cst/parse.js +0 -48
- package/dist/cst/source-utils.js +0 -173
- package/dist/doc/Anchors.js +0 -117
- package/dist/doc/Schema.js +0 -36
- package/dist/doc/getSchemaTags.js +0 -35
- package/dist/doc/listTagNames.js +0 -29
- package/dist/doc/parseContents.js +0 -62
- package/dist/doc/parseDirectives.js +0 -109
- package/dist/resolve/collection-utils.js +0 -91
- package/dist/resolve/resolveMap.js +0 -317
- package/dist/resolve/resolveNode.js +0 -175
- package/dist/resolve/resolveScalar.js +0 -22
- package/dist/resolve/resolveSeq.js +0 -172
- package/dist/resolve/resolveTag.js +0 -109
- package/dist/resolve/resolveTagName.js +0 -89
- package/dist/stringify/addComment.js +0 -13
- package/dist/stringify/stringifyTag.js +0 -30
- package/dist/tags/core.js +0 -138
- package/dist/tags/failsafe/index.js +0 -9
- package/dist/tags/failsafe/map.js +0 -39
- package/dist/tags/failsafe/seq.js +0 -36
- package/dist/tags/failsafe/string.js +0 -22
- package/dist/tags/index.js +0 -42
- package/dist/tags/json.js +0 -64
- package/dist/tags/options.js +0 -37
- package/dist/tags/yaml-1.1/binary.js +0 -85
- package/dist/tags/yaml-1.1/index.js +0 -176
- package/dist/tags/yaml-1.1/omap.js +0 -89
- package/dist/tags/yaml-1.1/pairs.js +0 -66
- package/dist/tags/yaml-1.1/set.js +0 -81
- package/dist/tags/yaml-1.1/timestamp.js +0 -105
- package/dist/types.js +0 -29
- package/index.d.ts +0 -519
- package/index.js +0 -1
- package/types.d.ts +0 -379
- package/types.js +0 -17
- package/types.mjs +0 -17
- package/util.d.ts +0 -76
- package/util.mjs +0 -15
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { isScalar, isCollection } from '../nodes/Node.js';
|
|
2
|
+
import { visit } from '../visit.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Verify that the input string is a valid anchor.
|
|
6
|
+
*
|
|
7
|
+
* Will throw on errors.
|
|
8
|
+
*/
|
|
9
|
+
function anchorIsValid(anchor) {
|
|
10
|
+
if (/[\x00-\x19\s,[\]{}]/.test(anchor)) {
|
|
11
|
+
const sa = JSON.stringify(anchor);
|
|
12
|
+
const msg = `Anchor must not contain whitespace or control characters: ${sa}`;
|
|
13
|
+
throw new Error(msg);
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
function anchorNames(root) {
|
|
18
|
+
const anchors = new Set();
|
|
19
|
+
visit(root, {
|
|
20
|
+
Value(_key, node) {
|
|
21
|
+
if (node.anchor)
|
|
22
|
+
anchors.add(node.anchor);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return anchors;
|
|
26
|
+
}
|
|
27
|
+
/** Find a new anchor name with the given `prefix` and a one-indexed suffix. */
|
|
28
|
+
function findNewAnchor(prefix, exclude) {
|
|
29
|
+
for (let i = 1; true; ++i) {
|
|
30
|
+
const name = `${prefix}${i}`;
|
|
31
|
+
if (!exclude.has(name))
|
|
32
|
+
return name;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function createNodeAnchors(doc, prefix) {
|
|
36
|
+
const aliasObjects = [];
|
|
37
|
+
const sourceObjects = new Map();
|
|
38
|
+
let prevAnchors = null;
|
|
39
|
+
return {
|
|
40
|
+
onAnchor(source) {
|
|
41
|
+
aliasObjects.push(source);
|
|
42
|
+
if (!prevAnchors)
|
|
43
|
+
prevAnchors = anchorNames(doc);
|
|
44
|
+
const anchor = findNewAnchor(prefix, prevAnchors);
|
|
45
|
+
prevAnchors.add(anchor);
|
|
46
|
+
return anchor;
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* With circular references, the source node is only resolved after all
|
|
50
|
+
* of its child nodes are. This is why anchors are set only after all of
|
|
51
|
+
* the nodes have been created.
|
|
52
|
+
*/
|
|
53
|
+
setAnchors() {
|
|
54
|
+
for (const source of aliasObjects) {
|
|
55
|
+
const ref = sourceObjects.get(source);
|
|
56
|
+
if (typeof ref === 'object' &&
|
|
57
|
+
ref.anchor &&
|
|
58
|
+
(isScalar(ref.node) || isCollection(ref.node))) {
|
|
59
|
+
ref.node.anchor = ref.anchor;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const error = new Error('Failed to resolve repeated object (this should not happen)');
|
|
63
|
+
error.source = source;
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
sourceObjects
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { anchorIsValid, anchorNames, createNodeAnchors, findNewAnchor };
|
|
@@ -6,36 +6,49 @@
|
|
|
6
6
|
* Includes extensions for handling Map and Set objects.
|
|
7
7
|
*/
|
|
8
8
|
function applyReviver(reviver, obj, key, val) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
if (val && typeof val === 'object') {
|
|
10
|
+
if (Array.isArray(val)) {
|
|
11
|
+
for (let i = 0, len = val.length; i < len; ++i) {
|
|
12
|
+
const v0 = val[i];
|
|
13
|
+
const v1 = applyReviver(reviver, val, String(i), v0);
|
|
14
|
+
if (v1 === undefined)
|
|
15
|
+
delete val[i];
|
|
16
|
+
else if (v1 !== v0)
|
|
17
|
+
val[i] = v1;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else if (val instanceof Map) {
|
|
21
|
+
for (const k of Array.from(val.keys())) {
|
|
22
|
+
const v0 = val.get(k);
|
|
23
|
+
const v1 = applyReviver(reviver, val, k, v0);
|
|
24
|
+
if (v1 === undefined)
|
|
25
|
+
val.delete(k);
|
|
26
|
+
else if (v1 !== v0)
|
|
27
|
+
val.set(k, v1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else if (val instanceof Set) {
|
|
31
|
+
for (const v0 of Array.from(val)) {
|
|
32
|
+
const v1 = applyReviver(reviver, val, v0, v0);
|
|
33
|
+
if (v1 === undefined)
|
|
34
|
+
val.delete(v0);
|
|
35
|
+
else if (v1 !== v0) {
|
|
36
|
+
val.delete(v0);
|
|
37
|
+
val.add(v1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
for (const [k, v0] of Object.entries(val)) {
|
|
43
|
+
const v1 = applyReviver(reviver, val, k, v0);
|
|
44
|
+
if (v1 === undefined)
|
|
45
|
+
delete val[k];
|
|
46
|
+
else if (v1 !== v0)
|
|
47
|
+
val[k] = v1;
|
|
48
|
+
}
|
|
28
49
|
}
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
for (const [k, v0] of Object.entries(val)) {
|
|
32
|
-
const v1 = applyReviver(reviver, val, k, v0);
|
|
33
|
-
if (v1 === undefined) delete val[k];else if (v1 !== v0) val[k] = v1;
|
|
34
|
-
}
|
|
35
50
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return reviver.call(obj, key, val);
|
|
51
|
+
return reviver.call(obj, key, val);
|
|
39
52
|
}
|
|
40
53
|
|
|
41
54
|
export { applyReviver };
|
|
@@ -1,62 +1,78 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Alias } from '../nodes/Alias.js';
|
|
2
|
+
import { isNode, isPair, MAP, SEQ } from '../nodes/Node.js';
|
|
3
|
+
import { Scalar } from '../nodes/Scalar.js';
|
|
4
4
|
|
|
5
|
+
const defaultTagPrefix = 'tag:yaml.org,2002:';
|
|
5
6
|
function findTagObject(value, tagName, tags) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
if (tagName) {
|
|
8
|
+
const match = tags.filter(t => t.tag === tagName);
|
|
9
|
+
const tagObj = match.find(t => !t.format) || match[0];
|
|
10
|
+
if (!tagObj)
|
|
11
|
+
throw new Error(`Tag ${tagName} not found`);
|
|
12
|
+
return tagObj;
|
|
13
|
+
}
|
|
14
|
+
return tags.find(t => t.identify && t.identify(value) && !t.format);
|
|
14
15
|
}
|
|
15
|
-
|
|
16
16
|
function createNode(value, tagName, ctx) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
17
|
+
var _a, _b;
|
|
18
|
+
if (isNode(value))
|
|
19
|
+
return value;
|
|
20
|
+
if (isPair(value)) {
|
|
21
|
+
const map = (_b = (_a = ctx.schema[MAP]).createNode) === null || _b === void 0 ? void 0 : _b.call(_a, ctx.schema, null, ctx);
|
|
22
|
+
map.items.push(value);
|
|
23
|
+
return map;
|
|
24
|
+
}
|
|
25
|
+
if (value instanceof String ||
|
|
26
|
+
value instanceof Number ||
|
|
27
|
+
value instanceof Boolean ||
|
|
28
|
+
(typeof BigInt === 'function' && value instanceof BigInt) // not supported everywhere
|
|
29
|
+
) {
|
|
30
|
+
// https://tc39.es/ecma262/#sec-serializejsonproperty
|
|
31
|
+
value = value.valueOf();
|
|
32
|
+
}
|
|
33
|
+
const { onAnchor, onTagObj, schema, sourceObjects } = ctx;
|
|
34
|
+
// Detect duplicate references to the same object & use Alias nodes for all
|
|
35
|
+
// after first. The `ref` wrapper allows for circular references to resolve.
|
|
36
|
+
let ref = undefined;
|
|
37
|
+
if (value && typeof value === 'object') {
|
|
38
|
+
ref = sourceObjects.get(value);
|
|
39
|
+
if (ref) {
|
|
40
|
+
if (!ref.anchor)
|
|
41
|
+
ref.anchor = onAnchor(value);
|
|
42
|
+
return new Alias(ref.anchor);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
ref = { anchor: null, node: null };
|
|
46
|
+
sourceObjects.set(value, ref);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (tagName && tagName.startsWith('!!'))
|
|
50
|
+
tagName = defaultTagPrefix + tagName.slice(2);
|
|
51
|
+
let tagObj = findTagObject(value, tagName, schema.tags);
|
|
52
|
+
if (!tagObj) {
|
|
53
|
+
if (value && typeof value.toJSON === 'function')
|
|
54
|
+
value = value.toJSON();
|
|
55
|
+
if (!value || typeof value !== 'object')
|
|
56
|
+
return new Scalar(value);
|
|
57
|
+
tagObj =
|
|
58
|
+
value instanceof Map
|
|
59
|
+
? schema[MAP]
|
|
60
|
+
: Symbol.iterator in Object(value)
|
|
61
|
+
? schema[SEQ]
|
|
62
|
+
: schema[MAP];
|
|
63
|
+
}
|
|
64
|
+
if (onTagObj) {
|
|
65
|
+
onTagObj(tagObj);
|
|
66
|
+
delete ctx.onTagObj;
|
|
67
|
+
}
|
|
68
|
+
const node = (tagObj === null || tagObj === void 0 ? void 0 : tagObj.createNode)
|
|
69
|
+
? tagObj.createNode(ctx.schema, value, ctx)
|
|
70
|
+
: new Scalar(value);
|
|
71
|
+
if (tagName)
|
|
72
|
+
node.tag = tagName;
|
|
73
|
+
if (ref)
|
|
74
|
+
ref.node = node;
|
|
75
|
+
return node;
|
|
60
76
|
}
|
|
61
77
|
|
|
62
78
|
export { createNode };
|
|
@@ -0,0 +1,161 @@
|
|
|
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.marker = null;
|
|
20
|
+
this.yaml = Object.assign({}, Directives.defaultYaml, yaml);
|
|
21
|
+
this.tags = Object.assign({}, Directives.defaultTags, tags);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* During parsing, get a Directives instance for the current document and
|
|
25
|
+
* update the stream state according to the current version's spec.
|
|
26
|
+
*/
|
|
27
|
+
atDocument() {
|
|
28
|
+
const res = new Directives(this.yaml, this.tags);
|
|
29
|
+
switch (this.yaml.version) {
|
|
30
|
+
case '1.1':
|
|
31
|
+
this.atNextDocument = true;
|
|
32
|
+
break;
|
|
33
|
+
case '1.2':
|
|
34
|
+
this.atNextDocument = false;
|
|
35
|
+
this.yaml = {
|
|
36
|
+
explicit: Directives.defaultYaml.explicit,
|
|
37
|
+
version: '1.2'
|
|
38
|
+
};
|
|
39
|
+
this.tags = Object.assign({}, Directives.defaultTags);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
return res;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @param onError - May be called even if the action was successful
|
|
46
|
+
* @returns `true` on success
|
|
47
|
+
*/
|
|
48
|
+
add(line, onError) {
|
|
49
|
+
if (this.atNextDocument) {
|
|
50
|
+
this.yaml = { explicit: Directives.defaultYaml.explicit, version: '1.1' };
|
|
51
|
+
this.tags = Object.assign({}, Directives.defaultTags);
|
|
52
|
+
this.atNextDocument = false;
|
|
53
|
+
}
|
|
54
|
+
const parts = line.trim().split(/[ \t]+/);
|
|
55
|
+
const name = parts.shift();
|
|
56
|
+
switch (name) {
|
|
57
|
+
case '%TAG': {
|
|
58
|
+
if (parts.length !== 2) {
|
|
59
|
+
onError(0, '%TAG directive should contain exactly two parts');
|
|
60
|
+
if (parts.length < 2)
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const [handle, prefix] = parts;
|
|
64
|
+
this.tags[handle] = prefix;
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
case '%YAML': {
|
|
68
|
+
this.yaml.explicit = true;
|
|
69
|
+
if (parts.length < 1) {
|
|
70
|
+
onError(0, '%YAML directive should contain exactly one part');
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const [version] = parts;
|
|
74
|
+
if (version === '1.1' || version === '1.2') {
|
|
75
|
+
this.yaml.version = version;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
onError(6, `Unsupported YAML version ${version}`, true);
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
default:
|
|
84
|
+
onError(0, `Unknown directive ${name}`, true);
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Resolves a tag, matching handles to those defined in %TAG directives.
|
|
90
|
+
*
|
|
91
|
+
* @returns Resolved tag, which may also be the non-specific tag `'!'` or a
|
|
92
|
+
* `'!local'` tag, or `null` if unresolvable.
|
|
93
|
+
*/
|
|
94
|
+
tagName(source, onError) {
|
|
95
|
+
if (source === '!')
|
|
96
|
+
return '!'; // non-specific tag
|
|
97
|
+
if (source[0] !== '!') {
|
|
98
|
+
onError(`Not a valid tag: ${source}`);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
if (source[1] === '<') {
|
|
102
|
+
const verbatim = source.slice(2, -1);
|
|
103
|
+
if (verbatim === '!' || verbatim === '!!') {
|
|
104
|
+
onError(`Verbatim tags aren't resolved, so ${source} is invalid.`);
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
if (source[source.length - 1] !== '>')
|
|
108
|
+
onError('Verbatim tags must end with a >');
|
|
109
|
+
return verbatim;
|
|
110
|
+
}
|
|
111
|
+
const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/);
|
|
112
|
+
if (!suffix)
|
|
113
|
+
onError(`The ${source} tag has no suffix`);
|
|
114
|
+
const prefix = this.tags[handle];
|
|
115
|
+
if (prefix)
|
|
116
|
+
return prefix + decodeURIComponent(suffix);
|
|
117
|
+
if (handle === '!')
|
|
118
|
+
return source; // local tag
|
|
119
|
+
onError(`Could not resolve tag: ${source}`);
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Given a fully resolved tag, returns its printable string form,
|
|
124
|
+
* taking into account current tag prefixes and defaults.
|
|
125
|
+
*/
|
|
126
|
+
tagString(tag) {
|
|
127
|
+
for (const [handle, prefix] of Object.entries(this.tags)) {
|
|
128
|
+
if (tag.startsWith(prefix))
|
|
129
|
+
return handle + escapeTagName(tag.substring(prefix.length));
|
|
130
|
+
}
|
|
131
|
+
return tag[0] === '!' ? tag : `!<${tag}>`;
|
|
132
|
+
}
|
|
133
|
+
toString(doc) {
|
|
134
|
+
const lines = this.yaml.explicit
|
|
135
|
+
? [`%YAML ${this.yaml.version || '1.2'}`]
|
|
136
|
+
: [];
|
|
137
|
+
const tagEntries = Object.entries(this.tags);
|
|
138
|
+
let tagNames;
|
|
139
|
+
if (doc && tagEntries.length > 0 && isNode(doc.contents)) {
|
|
140
|
+
const tags = {};
|
|
141
|
+
visit(doc.contents, (_key, node) => {
|
|
142
|
+
if (isNode(node) && node.tag)
|
|
143
|
+
tags[node.tag] = true;
|
|
144
|
+
});
|
|
145
|
+
tagNames = Object.keys(tags);
|
|
146
|
+
}
|
|
147
|
+
else
|
|
148
|
+
tagNames = [];
|
|
149
|
+
for (const [handle, prefix] of tagEntries) {
|
|
150
|
+
if (handle === '!!' && prefix === 'tag:yaml.org,2002:')
|
|
151
|
+
continue;
|
|
152
|
+
if (!doc || tagNames.some(tn => tn.startsWith(prefix)))
|
|
153
|
+
lines.push(`%TAG ${handle} ${prefix}`);
|
|
154
|
+
}
|
|
155
|
+
return lines.join('\n');
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
Directives.defaultYaml = { explicit: false, version: '1.2' };
|
|
159
|
+
Directives.defaultTags = { '!!': 'tag:yaml.org,2002:' };
|
|
160
|
+
|
|
161
|
+
export { Directives };
|
package/browser/dist/errors.js
CHANGED
|
@@ -1,79 +1,57 @@
|
|
|
1
|
-
import { Node } from './cst/Node.js';
|
|
2
|
-
import { getLinePos, getPrettyContext } from './cst/source-utils.js';
|
|
3
|
-
import { Range } from './cst/Range.js';
|
|
4
|
-
|
|
5
1
|
class YAMLError extends Error {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
makePretty() {
|
|
15
|
-
if (!this.source) return;
|
|
16
|
-
this.nodeType = this.source.type;
|
|
17
|
-
const cst = this.source.context && this.source.context.root;
|
|
18
|
-
|
|
19
|
-
if (typeof this.offset === 'number') {
|
|
20
|
-
this.range = new Range(this.offset, this.offset + 1);
|
|
21
|
-
const start = cst && getLinePos(this.offset, cst);
|
|
22
|
-
|
|
23
|
-
if (start) {
|
|
24
|
-
const end = {
|
|
25
|
-
line: start.line,
|
|
26
|
-
col: start.col + 1
|
|
27
|
-
};
|
|
28
|
-
this.linePos = {
|
|
29
|
-
start,
|
|
30
|
-
end
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
delete this.offset;
|
|
35
|
-
} else {
|
|
36
|
-
this.range = this.source.range;
|
|
37
|
-
this.linePos = this.source.rangeAsLinePos;
|
|
2
|
+
constructor(name, pos, code, message) {
|
|
3
|
+
super();
|
|
4
|
+
this.name = name;
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.message = message;
|
|
7
|
+
this.pos = pos;
|
|
38
8
|
}
|
|
39
|
-
|
|
40
|
-
if (this.linePos) {
|
|
41
|
-
const {
|
|
42
|
-
line,
|
|
43
|
-
col
|
|
44
|
-
} = this.linePos.start;
|
|
45
|
-
this.message += " at line ".concat(line, ", column ").concat(col);
|
|
46
|
-
const ctx = cst && getPrettyContext(this.linePos, cst);
|
|
47
|
-
if (ctx) this.message += ":\n\n".concat(ctx, "\n");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
delete this.source;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
class YAMLReferenceError extends YAMLError {
|
|
55
|
-
constructor(source, message) {
|
|
56
|
-
super('YAMLReferenceError', source, message);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
class YAMLSemanticError extends YAMLError {
|
|
61
|
-
constructor(source, message) {
|
|
62
|
-
super('YAMLSemanticError', source, message);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
9
|
}
|
|
66
|
-
class
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
10
|
+
class YAMLParseError extends YAMLError {
|
|
11
|
+
constructor(pos, code, message) {
|
|
12
|
+
super('YAMLParseError', pos, code, message);
|
|
13
|
+
}
|
|
71
14
|
}
|
|
72
15
|
class YAMLWarning extends YAMLError {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
16
|
+
constructor(pos, code, message) {
|
|
17
|
+
super('YAMLWarning', pos, code, message);
|
|
18
|
+
}
|
|
77
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
|
+
};
|
|
78
56
|
|
|
79
|
-
export { YAMLError,
|
|
57
|
+
export { YAMLError, YAMLParseError, YAMLWarning, prettifyError };
|
package/browser/dist/index.js
CHANGED
|
@@ -1,74 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
import { parse as parse$1 } from './cst/parse.js';
|
|
3
|
-
export { parse as parseCST } from './cst/parse.js';
|
|
4
|
-
import { Document } from './doc/Document.js';
|
|
1
|
+
export { Composer } from './compose/composer.js';
|
|
5
2
|
export { Document } from './doc/Document.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return stream;
|
|
23
|
-
}
|
|
24
|
-
function parseDocument(src, options) {
|
|
25
|
-
const cst = parse$1(src);
|
|
26
|
-
const doc = new Document(cst[0], null, options);
|
|
27
|
-
|
|
28
|
-
if (cst.length > 1 && LogLevel.indexOf(doc.options.logLevel) >= LogLevel.ERROR) {
|
|
29
|
-
const errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()';
|
|
30
|
-
doc.errors.unshift(new YAMLSemanticError(cst[1], errMsg));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return doc;
|
|
34
|
-
}
|
|
35
|
-
function parse(src, reviver, options) {
|
|
36
|
-
if (options === undefined && reviver && typeof reviver === 'object') {
|
|
37
|
-
options = reviver;
|
|
38
|
-
reviver = undefined;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const doc = parseDocument(src, options);
|
|
42
|
-
doc.warnings.forEach(warning => warn(doc.options.logLevel, warning));
|
|
43
|
-
|
|
44
|
-
if (doc.errors.length > 0) {
|
|
45
|
-
if (LogLevel.indexOf(doc.options.logLevel) >= LogLevel.ERROR) throw doc.errors[0];else doc.errors = [];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return doc.toJS({
|
|
49
|
-
reviver
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function stringify(value, replacer, options) {
|
|
53
|
-
if (typeof options === 'string') options = options.length;
|
|
54
|
-
|
|
55
|
-
if (typeof options === 'number') {
|
|
56
|
-
const indent = Math.round(options);
|
|
57
|
-
options = indent < 1 ? undefined : indent > 8 ? {
|
|
58
|
-
indent: 8
|
|
59
|
-
} : {
|
|
60
|
-
indent
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (value === undefined) {
|
|
65
|
-
const {
|
|
66
|
-
keepUndefined
|
|
67
|
-
} = options || replacer || {};
|
|
68
|
-
if (!keepUndefined) return undefined;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return new Document(value, replacer, options).toString();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export { parse, parseAllDocuments, parseDocument, stringify };
|
|
3
|
+
export { Schema } from './schema/Schema.js';
|
|
4
|
+
export { YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
|
|
5
|
+
export { Alias } from './nodes/Alias.js';
|
|
6
|
+
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/Node.js';
|
|
7
|
+
export { Pair } from './nodes/Pair.js';
|
|
8
|
+
export { Scalar } from './nodes/Scalar.js';
|
|
9
|
+
export { YAMLMap } from './nodes/YAMLMap.js';
|
|
10
|
+
export { YAMLSeq } from './nodes/YAMLSeq.js';
|
|
11
|
+
export { defaultOptions } from './options.js';
|
|
12
|
+
import * as cst from './parse/cst.js';
|
|
13
|
+
export { cst as CST };
|
|
14
|
+
export { Lexer } from './parse/lexer.js';
|
|
15
|
+
export { LineCounter } from './parse/line-counter.js';
|
|
16
|
+
export { Parser } from './parse/parser.js';
|
|
17
|
+
export { parse, parseAllDocuments, parseDocument, stringify } from './public-api.js';
|
|
18
|
+
export { visit } from './visit.js';
|