yaml 2.0.0-9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/browser/dist/compose/compose-doc.js +3 -2
- package/browser/dist/compose/compose-node.js +13 -4
- package/browser/dist/compose/compose-scalar.js +16 -10
- package/browser/dist/compose/composer.js +6 -7
- package/browser/dist/compose/resolve-block-map.js +9 -2
- package/browser/dist/compose/resolve-block-scalar.js +12 -3
- package/browser/dist/compose/resolve-block-seq.js +5 -0
- package/browser/dist/compose/resolve-flow-collection.js +14 -5
- package/browser/dist/compose/resolve-flow-scalar.js +2 -1
- package/browser/dist/compose/resolve-props.js +4 -0
- package/browser/dist/compose/util-flow-indent-check.js +15 -0
- package/browser/dist/doc/Document.js +49 -16
- package/browser/dist/doc/anchors.js +2 -2
- package/browser/dist/doc/createNode.js +7 -4
- package/browser/dist/doc/directives.js +7 -4
- package/browser/dist/index.js +1 -2
- package/browser/dist/nodes/Pair.js +2 -2
- package/browser/dist/nodes/Scalar.js +1 -1
- package/browser/dist/nodes/YAMLMap.js +6 -5
- package/browser/dist/nodes/YAMLSeq.js +2 -2
- package/browser/dist/nodes/addPairToJSMap.js +1 -1
- package/browser/dist/nodes/toJS.js +3 -1
- package/browser/dist/parse/cst-visit.js +2 -2
- package/browser/dist/parse/lexer.js +21 -8
- package/browser/dist/parse/parser.js +121 -45
- package/browser/dist/public-api.js +4 -5
- package/browser/dist/schema/Schema.js +14 -4
- package/browser/dist/schema/common/null.js +3 -1
- package/browser/dist/schema/core/float.js +4 -1
- package/browser/dist/schema/tags.js +9 -9
- package/browser/dist/schema/yaml-1.1/float.js +4 -1
- package/browser/dist/schema/yaml-1.1/omap.js +1 -1
- package/browser/dist/schema/yaml-1.1/pairs.js +2 -1
- package/browser/dist/stringify/stringify.js +51 -22
- package/browser/dist/stringify/stringifyCollection.js +115 -85
- package/browser/dist/stringify/stringifyComment.js +18 -12
- package/browser/dist/stringify/stringifyDocument.js +37 -15
- package/browser/dist/stringify/stringifyPair.js +34 -20
- package/browser/dist/stringify/stringifyString.js +8 -11
- package/browser/dist/visit.js +150 -62
- package/dist/compose/compose-doc.js +3 -2
- package/dist/compose/compose-node.d.ts +1 -0
- package/dist/compose/compose-node.js +13 -4
- package/dist/compose/compose-scalar.js +15 -9
- package/dist/compose/composer.d.ts +1 -1
- package/dist/compose/composer.js +8 -9
- package/dist/compose/resolve-block-map.js +9 -2
- package/dist/compose/resolve-block-scalar.js +12 -3
- package/dist/compose/resolve-block-seq.js +5 -0
- package/dist/compose/resolve-flow-collection.js +14 -5
- package/dist/compose/resolve-flow-scalar.js +2 -1
- package/dist/compose/resolve-props.d.ts +1 -1
- package/dist/compose/resolve-props.js +4 -0
- package/dist/compose/util-flow-indent-check.d.ts +3 -0
- package/dist/compose/util-flow-indent-check.js +17 -0
- package/dist/doc/Document.d.ts +7 -4
- package/dist/doc/Document.js +56 -23
- package/dist/doc/anchors.d.ts +2 -2
- package/dist/doc/anchors.js +2 -2
- package/dist/doc/createNode.d.ts +1 -1
- package/dist/doc/createNode.js +7 -4
- package/dist/doc/directives.d.ts +4 -2
- package/dist/doc/directives.js +7 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -2
- package/dist/nodes/Pair.js +2 -2
- package/dist/nodes/Scalar.js +1 -1
- package/dist/nodes/YAMLMap.d.ts +3 -1
- package/dist/nodes/YAMLMap.js +6 -5
- package/dist/nodes/YAMLSeq.js +2 -2
- package/dist/nodes/addPairToJSMap.js +1 -1
- package/dist/nodes/toJS.js +3 -1
- package/dist/options.d.ts +42 -12
- package/dist/parse/cst-visit.js +2 -2
- package/dist/parse/lexer.js +21 -8
- package/dist/parse/parser.js +121 -45
- package/dist/public-api.js +4 -5
- package/dist/schema/Schema.d.ts +5 -4
- package/dist/schema/Schema.js +13 -3
- package/dist/schema/common/null.js +3 -1
- package/dist/schema/core/float.js +4 -1
- package/dist/schema/tags.d.ts +1 -2
- package/dist/schema/tags.js +9 -9
- package/dist/schema/yaml-1.1/float.js +4 -1
- package/dist/schema/yaml-1.1/omap.js +1 -1
- package/dist/schema/yaml-1.1/pairs.js +2 -1
- package/dist/stringify/stringify.d.ts +5 -3
- package/dist/stringify/stringify.js +51 -22
- package/dist/stringify/stringifyCollection.d.ts +2 -6
- package/dist/stringify/stringifyCollection.js +114 -84
- package/dist/stringify/stringifyComment.d.ts +10 -2
- package/dist/stringify/stringifyComment.js +19 -12
- package/dist/stringify/stringifyDocument.js +36 -14
- package/dist/stringify/stringifyPair.js +33 -19
- package/dist/stringify/stringifyString.js +8 -11
- package/dist/test-events.js +13 -12
- package/dist/visit.d.ts +49 -10
- package/dist/visit.js +149 -60
- package/package.json +9 -8
- package/browser/dist/options.js +0 -18
- package/dist/options.js +0 -20
|
@@ -61,6 +61,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
61
61
|
case 'anchor':
|
|
62
62
|
if (anchor)
|
|
63
63
|
onError(token, 'MULTIPLE_ANCHORS', 'A node can have at most one anchor');
|
|
64
|
+
if (token.source.endsWith(':'))
|
|
65
|
+
onError(token.offset + token.source.length - 1, 'BAD_ALIAS', 'Anchor ending in : is ambiguous', true);
|
|
64
66
|
anchor = token;
|
|
65
67
|
if (start === null)
|
|
66
68
|
start = token.offset;
|
|
@@ -83,6 +85,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
83
85
|
// Could here handle preceding comments differently
|
|
84
86
|
if (anchor || tag)
|
|
85
87
|
onError(token, 'BAD_PROP_ORDER', `Anchors and tags must be after the ${token.source} indicator`);
|
|
88
|
+
if (found)
|
|
89
|
+
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow !== null && flow !== void 0 ? flow : 'collection'}`);
|
|
86
90
|
found = token;
|
|
87
91
|
atNewline = false;
|
|
88
92
|
hasSpace = false;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utilContainsNewline = require('./util-contains-newline.js');
|
|
4
|
+
|
|
5
|
+
function flowIndentCheck(indent, fc, onError) {
|
|
6
|
+
if ((fc === null || fc === void 0 ? void 0 : fc.type) === 'flow-collection') {
|
|
7
|
+
const end = fc.end[0];
|
|
8
|
+
if (end.indent === indent &&
|
|
9
|
+
(end.source === ']' || end.source === '}') &&
|
|
10
|
+
utilContainsNewline.containsNewline(fc)) {
|
|
11
|
+
const msg = 'Flow end indicator should be more indented than parent';
|
|
12
|
+
onError(end, 'BAD_INDENT', msg, true);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.flowIndentCheck = flowIndentCheck;
|
package/dist/doc/Document.d.ts
CHANGED
|
@@ -5,12 +5,13 @@ import { Pair } from '../nodes/Pair.js';
|
|
|
5
5
|
import type { Scalar } from '../nodes/Scalar.js';
|
|
6
6
|
import type { YAMLMap } from '../nodes/YAMLMap.js';
|
|
7
7
|
import type { YAMLSeq } from '../nodes/YAMLSeq.js';
|
|
8
|
-
import { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from '../options.js';
|
|
8
|
+
import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from '../options.js';
|
|
9
9
|
import { Schema } from '../schema/Schema.js';
|
|
10
10
|
import { Directives } from './directives.js';
|
|
11
11
|
export declare type Replacer = any[] | ((key: any, value: any) => unknown);
|
|
12
12
|
export declare namespace Document {
|
|
13
13
|
interface Parsed<T extends ParsedNode = ParsedNode> extends Document<T> {
|
|
14
|
+
directives: Directives;
|
|
14
15
|
range: Range;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
@@ -22,7 +23,7 @@ export declare class Document<T = unknown> {
|
|
|
22
23
|
comment: string | null;
|
|
23
24
|
/** The document contents. */
|
|
24
25
|
contents: T | null;
|
|
25
|
-
directives
|
|
26
|
+
directives?: Directives;
|
|
26
27
|
/** Errors encountered during parsing. */
|
|
27
28
|
errors: YAMLError[];
|
|
28
29
|
options: Required<Omit<ParseOptions & DocumentOptions, 'lineCounter' | 'directives' | 'version'>>;
|
|
@@ -116,10 +117,12 @@ export declare class Document<T = unknown> {
|
|
|
116
117
|
setIn(path: Iterable<unknown>, value: unknown): void;
|
|
117
118
|
/**
|
|
118
119
|
* Change the YAML version and schema used by the document.
|
|
120
|
+
* A `null` version disables support for directives, explicit tags, anchors, and aliases.
|
|
121
|
+
* It also requires the `schema` option to be given as a `Schema` instance value.
|
|
119
122
|
*
|
|
120
|
-
* Overrides all previously set schema options
|
|
123
|
+
* Overrides all previously set schema options.
|
|
121
124
|
*/
|
|
122
|
-
setSchema(version: '1.1' | '1.2', options?: SchemaOptions): void;
|
|
125
|
+
setSchema(version: '1.1' | '1.2' | 'next' | null, options?: SchemaOptions): void;
|
|
123
126
|
/** A plain JavaScript representation of the document `contents`. */
|
|
124
127
|
toJS(opt?: ToJSOptions & {
|
|
125
128
|
[ignored: string]: unknown;
|
package/dist/doc/Document.js
CHANGED
|
@@ -5,7 +5,6 @@ var Collection = require('../nodes/Collection.js');
|
|
|
5
5
|
var Node = require('../nodes/Node.js');
|
|
6
6
|
var Pair = require('../nodes/Pair.js');
|
|
7
7
|
var toJS = require('../nodes/toJS.js');
|
|
8
|
-
var options = require('../options.js');
|
|
9
8
|
var Schema = require('../schema/Schema.js');
|
|
10
9
|
var stringify = require('../stringify/stringify.js');
|
|
11
10
|
var stringifyDocument = require('../stringify/stringifyDocument.js');
|
|
@@ -15,7 +14,7 @@ var createNode = require('./createNode.js');
|
|
|
15
14
|
var directives = require('./directives.js');
|
|
16
15
|
|
|
17
16
|
class Document {
|
|
18
|
-
constructor(value, replacer, options
|
|
17
|
+
constructor(value, replacer, options) {
|
|
19
18
|
/** A comment before this Document */
|
|
20
19
|
this.commentBefore = null;
|
|
21
20
|
/** A comment immediately after this Document */
|
|
@@ -29,25 +28,33 @@ class Document {
|
|
|
29
28
|
if (typeof replacer === 'function' || Array.isArray(replacer)) {
|
|
30
29
|
_replacer = replacer;
|
|
31
30
|
}
|
|
32
|
-
else if (options
|
|
33
|
-
options
|
|
31
|
+
else if (options === undefined && replacer) {
|
|
32
|
+
options = replacer;
|
|
34
33
|
replacer = undefined;
|
|
35
34
|
}
|
|
36
|
-
const opt = Object.assign({
|
|
35
|
+
const opt = Object.assign({
|
|
36
|
+
intAsBigInt: false,
|
|
37
|
+
keepSourceTokens: false,
|
|
38
|
+
logLevel: 'warn',
|
|
39
|
+
prettyErrors: true,
|
|
40
|
+
strict: true,
|
|
41
|
+
uniqueKeys: true,
|
|
42
|
+
version: '1.2'
|
|
43
|
+
}, options);
|
|
37
44
|
this.options = opt;
|
|
38
45
|
let { version } = opt;
|
|
39
|
-
if (options
|
|
40
|
-
this.directives = options
|
|
46
|
+
if (options === null || options === void 0 ? void 0 : options.directives) {
|
|
47
|
+
this.directives = options.directives.atDocument();
|
|
41
48
|
if (this.directives.yaml.explicit)
|
|
42
49
|
version = this.directives.yaml.version;
|
|
43
50
|
}
|
|
44
51
|
else
|
|
45
52
|
this.directives = new directives.Directives({ version });
|
|
46
|
-
this.setSchema(version, options
|
|
53
|
+
this.setSchema(version, options);
|
|
47
54
|
if (value === undefined)
|
|
48
55
|
this.contents = null;
|
|
49
56
|
else {
|
|
50
|
-
this.contents = this.createNode(value, _replacer, options
|
|
57
|
+
this.contents = this.createNode(value, _replacer, options);
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
60
|
/**
|
|
@@ -64,7 +71,8 @@ class Document {
|
|
|
64
71
|
copy.errors = this.errors.slice();
|
|
65
72
|
copy.warnings = this.warnings.slice();
|
|
66
73
|
copy.options = Object.assign({}, this.options);
|
|
67
|
-
|
|
74
|
+
if (this.directives)
|
|
75
|
+
copy.directives = this.directives.clone();
|
|
68
76
|
copy.schema = this.schema.clone();
|
|
69
77
|
copy.contents = Node.isNode(this.contents)
|
|
70
78
|
? this.contents.clone(copy.schema)
|
|
@@ -96,6 +104,7 @@ class Document {
|
|
|
96
104
|
if (!node.anchor) {
|
|
97
105
|
const prev = anchors.anchorNames(this);
|
|
98
106
|
node.anchor =
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
99
108
|
!name || prev.has(name) ? anchors.findNewAnchor(name || 'a', prev) : name;
|
|
100
109
|
}
|
|
101
110
|
return new Alias.Alias(node.anchor);
|
|
@@ -117,8 +126,10 @@ class Document {
|
|
|
117
126
|
options = replacer;
|
|
118
127
|
replacer = undefined;
|
|
119
128
|
}
|
|
120
|
-
const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options
|
|
121
|
-
const { onAnchor, setAnchors, sourceObjects } = anchors.createNodeAnchors(this,
|
|
129
|
+
const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options !== null && options !== void 0 ? options : {};
|
|
130
|
+
const { onAnchor, setAnchors, sourceObjects } = anchors.createNodeAnchors(this,
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
132
|
+
anchorPrefix || 'a');
|
|
122
133
|
const ctx = {
|
|
123
134
|
aliasDuplicateObjects: aliasDuplicateObjects !== null && aliasDuplicateObjects !== void 0 ? aliasDuplicateObjects : true,
|
|
124
135
|
keepUndefined: keepUndefined !== null && keepUndefined !== void 0 ? keepUndefined : false,
|
|
@@ -231,26 +242,48 @@ class Document {
|
|
|
231
242
|
}
|
|
232
243
|
/**
|
|
233
244
|
* Change the YAML version and schema used by the document.
|
|
245
|
+
* A `null` version disables support for directives, explicit tags, anchors, and aliases.
|
|
246
|
+
* It also requires the `schema` option to be given as a `Schema` instance value.
|
|
234
247
|
*
|
|
235
|
-
* Overrides all previously set schema options
|
|
248
|
+
* Overrides all previously set schema options.
|
|
236
249
|
*/
|
|
237
|
-
setSchema(version, options) {
|
|
238
|
-
|
|
239
|
-
|
|
250
|
+
setSchema(version, options = {}) {
|
|
251
|
+
if (typeof version === 'number')
|
|
252
|
+
version = String(version);
|
|
253
|
+
let opt;
|
|
254
|
+
switch (version) {
|
|
240
255
|
case '1.1':
|
|
241
|
-
this.directives
|
|
242
|
-
|
|
256
|
+
if (this.directives)
|
|
257
|
+
this.directives.yaml.version = '1.1';
|
|
258
|
+
else
|
|
259
|
+
this.directives = new directives.Directives({ version: '1.1' });
|
|
260
|
+
opt = { merge: true, resolveKnownTags: false, schema: 'yaml-1.1' };
|
|
243
261
|
break;
|
|
244
262
|
case '1.2':
|
|
245
|
-
|
|
246
|
-
|
|
263
|
+
case 'next':
|
|
264
|
+
if (this.directives)
|
|
265
|
+
this.directives.yaml.version = version;
|
|
266
|
+
else
|
|
267
|
+
this.directives = new directives.Directives({ version });
|
|
268
|
+
opt = { merge: false, resolveKnownTags: true, schema: 'core' };
|
|
269
|
+
break;
|
|
270
|
+
case null:
|
|
271
|
+
if (this.directives)
|
|
272
|
+
delete this.directives;
|
|
273
|
+
opt = null;
|
|
247
274
|
break;
|
|
248
275
|
default: {
|
|
249
276
|
const sv = JSON.stringify(version);
|
|
250
|
-
throw new Error(`Expected '1.1'
|
|
277
|
+
throw new Error(`Expected '1.1', '1.2' or null as first argument, but found: ${sv}`);
|
|
251
278
|
}
|
|
252
279
|
}
|
|
253
|
-
|
|
280
|
+
// Not using `instanceof Schema` to allow for duck typing
|
|
281
|
+
if (options.schema instanceof Object)
|
|
282
|
+
this.schema = options.schema;
|
|
283
|
+
else if (opt)
|
|
284
|
+
this.schema = new Schema.Schema(Object.assign(opt, options));
|
|
285
|
+
else
|
|
286
|
+
throw new Error(`With a null YAML version, the { schema: Schema } option is required`);
|
|
254
287
|
}
|
|
255
288
|
// json & jsonArg are only used from toJSON()
|
|
256
289
|
toJS({ json, jsonArg, mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
|
|
@@ -263,7 +296,7 @@ class Document {
|
|
|
263
296
|
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100,
|
|
264
297
|
stringify: stringify.stringify
|
|
265
298
|
};
|
|
266
|
-
const res = toJS.toJS(this.contents, jsonArg
|
|
299
|
+
const res = toJS.toJS(this.contents, jsonArg !== null && jsonArg !== void 0 ? jsonArg : '', ctx);
|
|
267
300
|
if (typeof onAnchor === 'function')
|
|
268
301
|
for (const { count, res } of ctx.anchors.values())
|
|
269
302
|
onAnchor(res, count);
|
package/dist/doc/anchors.d.ts
CHANGED
|
@@ -10,13 +10,13 @@ export declare function anchorNames(root: Document | Node): Set<string>;
|
|
|
10
10
|
/** Find a new anchor name with the given `prefix` and a one-indexed suffix. */
|
|
11
11
|
export declare function findNewAnchor(prefix: string, exclude: Set<string>): string;
|
|
12
12
|
export declare function createNodeAnchors(doc: Document, prefix: string): {
|
|
13
|
-
onAnchor(source: unknown)
|
|
13
|
+
onAnchor: (source: unknown) => string;
|
|
14
14
|
/**
|
|
15
15
|
* With circular references, the source node is only resolved after all
|
|
16
16
|
* of its child nodes are. This is why anchors are set only after all of
|
|
17
17
|
* the nodes have been created.
|
|
18
18
|
*/
|
|
19
|
-
setAnchors()
|
|
19
|
+
setAnchors: () => void;
|
|
20
20
|
sourceObjects: Map<unknown, {
|
|
21
21
|
anchor: string | null;
|
|
22
22
|
node: Node | null;
|
package/dist/doc/anchors.js
CHANGED
|
@@ -39,7 +39,7 @@ function createNodeAnchors(doc, prefix) {
|
|
|
39
39
|
const sourceObjects = new Map();
|
|
40
40
|
let prevAnchors = null;
|
|
41
41
|
return {
|
|
42
|
-
onAnchor(source) {
|
|
42
|
+
onAnchor: (source) => {
|
|
43
43
|
aliasObjects.push(source);
|
|
44
44
|
if (!prevAnchors)
|
|
45
45
|
prevAnchors = anchorNames(doc);
|
|
@@ -52,7 +52,7 @@ function createNodeAnchors(doc, prefix) {
|
|
|
52
52
|
* of its child nodes are. This is why anchors are set only after all of
|
|
53
53
|
* the nodes have been created.
|
|
54
54
|
*/
|
|
55
|
-
setAnchors() {
|
|
55
|
+
setAnchors: () => {
|
|
56
56
|
for (const source of aliasObjects) {
|
|
57
57
|
const ref = sourceObjects.get(source);
|
|
58
58
|
if (typeof ref === 'object' &&
|
package/dist/doc/createNode.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Replacer } from './Document.js';
|
|
|
5
5
|
export interface CreateNodeContext {
|
|
6
6
|
aliasDuplicateObjects: boolean;
|
|
7
7
|
keepUndefined: boolean;
|
|
8
|
-
onAnchor(source: unknown)
|
|
8
|
+
onAnchor: (source: unknown) => string;
|
|
9
9
|
onTagObj?: (tagObj: ScalarTag | CollectionTag) => void;
|
|
10
10
|
sourceObjects: Map<unknown, {
|
|
11
11
|
anchor: string | null;
|
package/dist/doc/createNode.js
CHANGED
|
@@ -6,14 +6,15 @@ var Scalar = require('../nodes/Scalar.js');
|
|
|
6
6
|
|
|
7
7
|
const defaultTagPrefix = 'tag:yaml.org,2002:';
|
|
8
8
|
function findTagObject(value, tagName, tags) {
|
|
9
|
+
var _a;
|
|
9
10
|
if (tagName) {
|
|
10
11
|
const match = tags.filter(t => t.tag === tagName);
|
|
11
|
-
const tagObj = match.find(t => !t.format)
|
|
12
|
+
const tagObj = (_a = match.find(t => !t.format)) !== null && _a !== void 0 ? _a : match[0];
|
|
12
13
|
if (!tagObj)
|
|
13
14
|
throw new Error(`Tag ${tagName} not found`);
|
|
14
15
|
return tagObj;
|
|
15
16
|
}
|
|
16
|
-
return tags.find(t => t.identify
|
|
17
|
+
return tags.find(t => { var _a; return ((_a = t.identify) === null || _a === void 0 ? void 0 : _a.call(t, value)) && !t.format; });
|
|
17
18
|
}
|
|
18
19
|
function createNode(value, tagName, ctx) {
|
|
19
20
|
var _a, _b;
|
|
@@ -50,12 +51,14 @@ function createNode(value, tagName, ctx) {
|
|
|
50
51
|
sourceObjects.set(value, ref);
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
|
-
if (tagName
|
|
54
|
+
if (tagName === null || tagName === void 0 ? void 0 : tagName.startsWith('!!'))
|
|
54
55
|
tagName = defaultTagPrefix + tagName.slice(2);
|
|
55
56
|
let tagObj = findTagObject(value, tagName, schema.tags);
|
|
56
57
|
if (!tagObj) {
|
|
57
|
-
if (value && typeof value.toJSON === 'function')
|
|
58
|
+
if (value && typeof value.toJSON === 'function') {
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
58
60
|
value = value.toJSON();
|
|
61
|
+
}
|
|
59
62
|
if (!value || typeof value !== 'object') {
|
|
60
63
|
const node = new Scalar.Scalar(value);
|
|
61
64
|
if (ref)
|
package/dist/doc/directives.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare class Directives {
|
|
|
3
3
|
static defaultYaml: Directives['yaml'];
|
|
4
4
|
static defaultTags: Directives['tags'];
|
|
5
5
|
yaml: {
|
|
6
|
-
version: '1.1' | '1.2';
|
|
6
|
+
version: '1.1' | '1.2' | 'next';
|
|
7
7
|
explicit?: boolean;
|
|
8
8
|
};
|
|
9
9
|
tags: Record<string, string>;
|
|
@@ -11,7 +11,9 @@ export declare class Directives {
|
|
|
11
11
|
* The directives-end/doc-start marker `---`. If `null`, a marker may still be
|
|
12
12
|
* included in the document's stringified representation.
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
docStart: true | null;
|
|
15
|
+
/** The doc-end marker `...`. */
|
|
16
|
+
docEnd: boolean;
|
|
15
17
|
/**
|
|
16
18
|
* Used when parsing YAML 1.1, where:
|
|
17
19
|
* > If the document specifies no directives, it is parsed using the same
|
package/dist/doc/directives.js
CHANGED
|
@@ -18,13 +18,15 @@ class Directives {
|
|
|
18
18
|
* The directives-end/doc-start marker `---`. If `null`, a marker may still be
|
|
19
19
|
* included in the document's stringified representation.
|
|
20
20
|
*/
|
|
21
|
-
this.
|
|
21
|
+
this.docStart = null;
|
|
22
|
+
/** The doc-end marker `...`. */
|
|
23
|
+
this.docEnd = false;
|
|
22
24
|
this.yaml = Object.assign({}, Directives.defaultYaml, yaml);
|
|
23
25
|
this.tags = Object.assign({}, Directives.defaultTags, tags);
|
|
24
26
|
}
|
|
25
27
|
clone() {
|
|
26
28
|
const copy = new Directives(this.yaml, this.tags);
|
|
27
|
-
copy.
|
|
29
|
+
copy.docStart = this.docStart;
|
|
28
30
|
return copy;
|
|
29
31
|
}
|
|
30
32
|
/**
|
|
@@ -73,7 +75,7 @@ class Directives {
|
|
|
73
75
|
}
|
|
74
76
|
case '%YAML': {
|
|
75
77
|
this.yaml.explicit = true;
|
|
76
|
-
if (parts.length
|
|
78
|
+
if (parts.length !== 1) {
|
|
77
79
|
onError(0, '%YAML directive should contain exactly one part');
|
|
78
80
|
return false;
|
|
79
81
|
}
|
|
@@ -83,7 +85,8 @@ class Directives {
|
|
|
83
85
|
return true;
|
|
84
86
|
}
|
|
85
87
|
else {
|
|
86
|
-
|
|
88
|
+
const isValid = /^\d+\.\d+$/.test(version);
|
|
89
|
+
onError(6, `Unsupported YAML version ${version}`, isValid);
|
|
87
90
|
return false;
|
|
88
91
|
}
|
|
89
92
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { Pair } from './nodes/Pair.js';
|
|
|
8
8
|
export { Scalar } from './nodes/Scalar.js';
|
|
9
9
|
export { YAMLMap } from './nodes/YAMLMap.js';
|
|
10
10
|
export { YAMLSeq } from './nodes/YAMLSeq.js';
|
|
11
|
-
export { CreateNodeOptions,
|
|
11
|
+
export type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options.js';
|
|
12
12
|
export * as CST from './parse/cst.js';
|
|
13
13
|
export { Lexer } from './parse/lexer.js';
|
|
14
14
|
export { LineCounter } from './parse/line-counter.js';
|
|
@@ -16,4 +16,4 @@ export { Parser } from './parse/parser.js';
|
|
|
16
16
|
export { EmptyStream, parse, parseAllDocuments, parseDocument, stringify } from './public-api.js';
|
|
17
17
|
export type { TagId, Tags } from './schema/tags';
|
|
18
18
|
export type { CollectionTag, ScalarTag } from './schema/types';
|
|
19
|
-
export { visit, visitor, visitorFn } from './visit.js';
|
|
19
|
+
export { asyncVisitor, asyncVisitorFn, visit, visitAsync, visitor, visitorFn } from './visit.js';
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,6 @@ var Pair = require('./nodes/Pair.js');
|
|
|
10
10
|
var Scalar = require('./nodes/Scalar.js');
|
|
11
11
|
var YAMLMap = require('./nodes/YAMLMap.js');
|
|
12
12
|
var YAMLSeq = require('./nodes/YAMLSeq.js');
|
|
13
|
-
var options = require('./options.js');
|
|
14
13
|
var cst = require('./parse/cst.js');
|
|
15
14
|
var lexer = require('./parse/lexer.js');
|
|
16
15
|
var lineCounter = require('./parse/line-counter.js');
|
|
@@ -39,7 +38,6 @@ exports.Pair = Pair.Pair;
|
|
|
39
38
|
exports.Scalar = Scalar.Scalar;
|
|
40
39
|
exports.YAMLMap = YAMLMap.YAMLMap;
|
|
41
40
|
exports.YAMLSeq = YAMLSeq.YAMLSeq;
|
|
42
|
-
exports.defaultOptions = options.defaultOptions;
|
|
43
41
|
exports.CST = cst;
|
|
44
42
|
exports.Lexer = lexer.Lexer;
|
|
45
43
|
exports.LineCounter = lineCounter.LineCounter;
|
|
@@ -49,3 +47,4 @@ exports.parseAllDocuments = publicApi.parseAllDocuments;
|
|
|
49
47
|
exports.parseDocument = publicApi.parseDocument;
|
|
50
48
|
exports.stringify = publicApi.stringify;
|
|
51
49
|
exports.visit = visit.visit;
|
|
50
|
+
exports.visitAsync = visit.visitAsync;
|
package/dist/nodes/Pair.js
CHANGED
|
@@ -25,11 +25,11 @@ class Pair {
|
|
|
25
25
|
return new Pair(key, value);
|
|
26
26
|
}
|
|
27
27
|
toJSON(_, ctx) {
|
|
28
|
-
const pair = ctx
|
|
28
|
+
const pair = (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
|
|
29
29
|
return addPairToJSMap.addPairToJSMap(ctx, pair, this);
|
|
30
30
|
}
|
|
31
31
|
toString(ctx, onComment, onChompKeep) {
|
|
32
|
-
return ctx
|
|
32
|
+
return (ctx === null || ctx === void 0 ? void 0 : ctx.doc)
|
|
33
33
|
? stringifyPair.stringifyPair(this, ctx, onComment, onChompKeep)
|
|
34
34
|
: JSON.stringify(this);
|
|
35
35
|
}
|
package/dist/nodes/Scalar.js
CHANGED
|
@@ -10,7 +10,7 @@ class Scalar extends Node.NodeBase {
|
|
|
10
10
|
this.value = value;
|
|
11
11
|
}
|
|
12
12
|
toJSON(arg, ctx) {
|
|
13
|
-
return ctx
|
|
13
|
+
return (ctx === null || ctx === void 0 ? void 0 : ctx.keep) ? this.value : toJS.toJS(this.value, arg, ctx);
|
|
14
14
|
}
|
|
15
15
|
toString() {
|
|
16
16
|
return String(this.value);
|
package/dist/nodes/YAMLMap.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export declare class YAMLMap<K = unknown, V = unknown> extends Collection {
|
|
|
36
36
|
* @param {Class} Type - If set, forces the returned collection type
|
|
37
37
|
* @returns Instance of Type, Map, or Object
|
|
38
38
|
*/
|
|
39
|
-
toJSON(_?: unknown, ctx?: ToJSContext, Type?:
|
|
39
|
+
toJSON<T = unknown>(_?: unknown, ctx?: ToJSContext, Type?: {
|
|
40
|
+
new (): T;
|
|
41
|
+
}): any;
|
|
40
42
|
toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
|
|
41
43
|
}
|
package/dist/nodes/YAMLMap.js
CHANGED
|
@@ -34,6 +34,7 @@ class YAMLMap extends Collection.Collection {
|
|
|
34
34
|
* collection will throw. Otherwise, overwrites the previous value.
|
|
35
35
|
*/
|
|
36
36
|
add(pair, overwrite) {
|
|
37
|
+
var _a;
|
|
37
38
|
let _pair;
|
|
38
39
|
if (Node.isPair(pair))
|
|
39
40
|
_pair = pair;
|
|
@@ -44,7 +45,7 @@ class YAMLMap extends Collection.Collection {
|
|
|
44
45
|
else
|
|
45
46
|
_pair = new Pair.Pair(pair.key, pair.value);
|
|
46
47
|
const prev = findPair(this.items, _pair.key);
|
|
47
|
-
const sortEntries = this.schema
|
|
48
|
+
const sortEntries = (_a = this.schema) === null || _a === void 0 ? void 0 : _a.sortMapEntries;
|
|
48
49
|
if (prev) {
|
|
49
50
|
if (!overwrite)
|
|
50
51
|
throw new Error(`Key ${_pair.key} already set`);
|
|
@@ -74,7 +75,7 @@ class YAMLMap extends Collection.Collection {
|
|
|
74
75
|
}
|
|
75
76
|
get(key, keepScalar) {
|
|
76
77
|
const it = findPair(this.items, key);
|
|
77
|
-
const node = it
|
|
78
|
+
const node = it === null || it === void 0 ? void 0 : it.value;
|
|
78
79
|
return !keepScalar && Node.isScalar(node) ? node.value : node;
|
|
79
80
|
}
|
|
80
81
|
has(key) {
|
|
@@ -89,8 +90,8 @@ class YAMLMap extends Collection.Collection {
|
|
|
89
90
|
* @returns Instance of Type, Map, or Object
|
|
90
91
|
*/
|
|
91
92
|
toJSON(_, ctx, Type) {
|
|
92
|
-
const map = Type ? new Type() : ctx
|
|
93
|
-
if (ctx
|
|
93
|
+
const map = Type ? new Type() : (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
|
|
94
|
+
if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
|
|
94
95
|
ctx.onCreate(map);
|
|
95
96
|
for (const item of this.items)
|
|
96
97
|
addPairToJSMap.addPairToJSMap(ctx, map, item);
|
|
@@ -106,7 +107,7 @@ class YAMLMap extends Collection.Collection {
|
|
|
106
107
|
if (!ctx.allNullValues && this.hasAllNullValues(false))
|
|
107
108
|
ctx = Object.assign({}, ctx, { allNullValues: true });
|
|
108
109
|
return stringifyCollection.stringifyCollection(this, ctx, {
|
|
109
|
-
|
|
110
|
+
blockItemPrefix: '',
|
|
110
111
|
flowChars: { start: '{', end: '}' },
|
|
111
112
|
itemIndent: ctx.indent || '',
|
|
112
113
|
onChompKeep,
|
package/dist/nodes/YAMLSeq.js
CHANGED
|
@@ -76,7 +76,7 @@ class YAMLSeq extends Collection.Collection {
|
|
|
76
76
|
}
|
|
77
77
|
toJSON(_, ctx) {
|
|
78
78
|
const seq = [];
|
|
79
|
-
if (ctx
|
|
79
|
+
if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
|
|
80
80
|
ctx.onCreate(seq);
|
|
81
81
|
let i = 0;
|
|
82
82
|
for (const item of this.items)
|
|
@@ -87,7 +87,7 @@ class YAMLSeq extends Collection.Collection {
|
|
|
87
87
|
if (!ctx)
|
|
88
88
|
return JSON.stringify(this);
|
|
89
89
|
return stringifyCollection.stringifyCollection(this, ctx, {
|
|
90
|
-
|
|
90
|
+
blockItemPrefix: '- ',
|
|
91
91
|
flowChars: { start: '[', end: ']' },
|
|
92
92
|
itemIndent: (ctx.indent || '') + ' ',
|
|
93
93
|
onChompKeep,
|
|
@@ -8,7 +8,7 @@ var toJS = require('./toJS.js');
|
|
|
8
8
|
|
|
9
9
|
const MERGE_KEY = '<<';
|
|
10
10
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
11
|
-
if (ctx
|
|
11
|
+
if ((ctx === null || ctx === void 0 ? void 0 : ctx.doc.schema.merge) && isMergeKey(key)) {
|
|
12
12
|
value = Node.isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
13
13
|
if (Node.isSeq(value))
|
|
14
14
|
for (const it of value.items)
|
package/dist/nodes/toJS.js
CHANGED
|
@@ -13,9 +13,11 @@ var Node = require('./Node.js');
|
|
|
13
13
|
* stringification.
|
|
14
14
|
*/
|
|
15
15
|
function toJS(value, arg, ctx) {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
16
17
|
if (Array.isArray(value))
|
|
17
18
|
return value.map((v, i) => toJS(v, String(i), ctx));
|
|
18
19
|
if (value && typeof value.toJSON === 'function') {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
19
21
|
if (!ctx || !Node.hasAnchor(value))
|
|
20
22
|
return value.toJSON(arg, ctx);
|
|
21
23
|
const data = { aliasCount: 0, count: 1, res: undefined };
|
|
@@ -29,7 +31,7 @@ function toJS(value, arg, ctx) {
|
|
|
29
31
|
ctx.onCreate(res);
|
|
30
32
|
return res;
|
|
31
33
|
}
|
|
32
|
-
if (typeof value === 'bigint' && !(ctx
|
|
34
|
+
if (typeof value === 'bigint' && !(ctx === null || ctx === void 0 ? void 0 : ctx.keep))
|
|
33
35
|
return Number(value);
|
|
34
36
|
return value;
|
|
35
37
|
}
|
package/dist/options.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { ParsedNode } from './nodes/Node.js';
|
|
|
5
5
|
import type { Pair } from './nodes/Pair.js';
|
|
6
6
|
import type { Scalar } from './nodes/Scalar.js';
|
|
7
7
|
import type { LineCounter } from './parse/line-counter.js';
|
|
8
|
-
import type {
|
|
8
|
+
import type { Schema } from './schema/Schema.js';
|
|
9
9
|
import type { Tags } from './schema/tags.js';
|
|
10
10
|
import type { CollectionTag, ScalarTag } from './schema/types.js';
|
|
11
11
|
export declare type ParseOptions = {
|
|
@@ -73,9 +73,17 @@ export declare type DocumentOptions = {
|
|
|
73
73
|
*
|
|
74
74
|
* Default: `"1.2"`
|
|
75
75
|
*/
|
|
76
|
-
version?: '1.1' | '1.2';
|
|
76
|
+
version?: '1.1' | '1.2' | 'next';
|
|
77
77
|
};
|
|
78
78
|
export declare type SchemaOptions = {
|
|
79
|
+
/**
|
|
80
|
+
* When parsing, warn about compatibility issues with the given schema.
|
|
81
|
+
* When stringifying, use scalar styles that are parsed correctly
|
|
82
|
+
* by the `compat` schema as well as the actual schema.
|
|
83
|
+
*
|
|
84
|
+
* Default: `null`
|
|
85
|
+
*/
|
|
86
|
+
compat?: string | Tags | null;
|
|
79
87
|
/**
|
|
80
88
|
* Array of additional tags to include in the schema, or a function that may
|
|
81
89
|
* modify the schema's base tag array.
|
|
@@ -99,9 +107,18 @@ export declare type SchemaOptions = {
|
|
|
99
107
|
/**
|
|
100
108
|
* The base schema to use.
|
|
101
109
|
*
|
|
102
|
-
*
|
|
110
|
+
* The core library has built-in support for the following:
|
|
111
|
+
* - `'failsafe'`: A minimal schema that parses all scalars as strings
|
|
112
|
+
* - `'core'`: The YAML 1.2 core schema
|
|
113
|
+
* - `'json'`: The YAML 1.2 JSON schema, with minimal rules for JSON compatibility
|
|
114
|
+
* - `'yaml-1.1'`: The YAML 1.1 schema
|
|
115
|
+
*
|
|
116
|
+
* If using another (custom) schema, the `customTags` array needs to
|
|
117
|
+
* fully define the schema's tags.
|
|
118
|
+
*
|
|
119
|
+
* Default: `'core'` for YAML 1.2, `'yaml-1.1'` for earlier versions
|
|
103
120
|
*/
|
|
104
|
-
schema?:
|
|
121
|
+
schema?: string | Schema;
|
|
105
122
|
/**
|
|
106
123
|
* When adding to or stringifying a map, sort the entries.
|
|
107
124
|
* If `true`, sort by comparing key values with `<`.
|
|
@@ -110,6 +127,10 @@ export declare type SchemaOptions = {
|
|
|
110
127
|
* Default: `false`
|
|
111
128
|
*/
|
|
112
129
|
sortMapEntries?: boolean | ((a: Pair, b: Pair) => number);
|
|
130
|
+
/**
|
|
131
|
+
* Override default values for `toString()` options.
|
|
132
|
+
*/
|
|
133
|
+
toStringDefaults?: ToStringOptions;
|
|
113
134
|
};
|
|
114
135
|
export declare type CreateNodeOptions = {
|
|
115
136
|
/**
|
|
@@ -175,6 +196,23 @@ export declare type ToStringOptions = {
|
|
|
175
196
|
* Default: `true`
|
|
176
197
|
*/
|
|
177
198
|
blockQuote?: boolean | 'folded' | 'literal';
|
|
199
|
+
/**
|
|
200
|
+
* Enforce `'block'` or `'flow'` style on maps and sequences.
|
|
201
|
+
* Empty collections will always be stringified as `{}` or `[]`.
|
|
202
|
+
*
|
|
203
|
+
* Default: `'any'`, allowing each node to set its style separately
|
|
204
|
+
* with its `flow: boolean` (default `false`) property.
|
|
205
|
+
*/
|
|
206
|
+
collectionStyle?: 'any' | 'block' | 'flow';
|
|
207
|
+
/**
|
|
208
|
+
* Comment stringifier.
|
|
209
|
+
* Output should be valid for the current schema.
|
|
210
|
+
*
|
|
211
|
+
* By default, empty comment lines are left empty,
|
|
212
|
+
* lines consisting of a single space are replaced by `#`,
|
|
213
|
+
* and all other lines are prefixed with a `#`.
|
|
214
|
+
*/
|
|
215
|
+
commentString?: (comment: string) => string;
|
|
178
216
|
/**
|
|
179
217
|
* The default type of string literal used to stringify implicit key values.
|
|
180
218
|
* Output may use other types if required to fully represent the value.
|
|
@@ -290,11 +328,3 @@ export declare type ToStringOptions = {
|
|
|
290
328
|
*/
|
|
291
329
|
verifyAliasOrder?: boolean;
|
|
292
330
|
};
|
|
293
|
-
/**
|
|
294
|
-
* `yaml` defines document-specific options in three places: as an argument of
|
|
295
|
-
* parse, create and stringify calls, in the values of `YAML.defaultOptions`,
|
|
296
|
-
* and in the version-dependent `YAML.Document.defaults` object. Values set in
|
|
297
|
-
* `YAML.defaultOptions` override version-dependent defaults, and argument
|
|
298
|
-
* options override both.
|
|
299
|
-
*/
|
|
300
|
-
export declare const defaultOptions: Required<Omit<ParseOptions, 'lineCounter'> & Omit<DocumentOptions, 'directives'>>;
|