yaml 2.0.0 → 2.1.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/browser/dist/compose/compose-collection.js +1 -1
- package/browser/dist/compose/compose-doc.js +2 -2
- package/browser/dist/compose/compose-scalar.js +6 -7
- package/browser/dist/compose/composer.js +2 -3
- package/browser/dist/compose/resolve-block-map.js +8 -8
- package/browser/dist/compose/resolve-block-scalar.js +1 -1
- package/browser/dist/compose/resolve-flow-collection.js +3 -4
- package/browser/dist/compose/resolve-flow-scalar.js +1 -2
- package/browser/dist/compose/resolve-props.js +6 -2
- package/browser/dist/compose/util-empty-scalar-position.js +1 -1
- package/browser/dist/compose/util-flow-indent-check.js +1 -1
- package/browser/dist/doc/Document.js +6 -6
- package/browser/dist/doc/createNode.js +5 -7
- package/browser/dist/nodes/Collection.js +2 -1
- package/browser/dist/nodes/Pair.js +2 -2
- package/browser/dist/nodes/Scalar.js +1 -1
- package/browser/dist/nodes/YAMLMap.js +6 -7
- package/browser/dist/nodes/YAMLSeq.js +1 -9
- package/browser/dist/nodes/addPairToJSMap.js +1 -1
- package/browser/dist/nodes/toJS.js +1 -1
- package/browser/dist/parse/cst-scalar.js +1 -2
- package/browser/dist/parse/cst-visit.js +2 -2
- package/browser/dist/parse/lexer.js +1 -2
- package/browser/dist/parse/parser.js +24 -26
- package/browser/dist/public-api.js +3 -4
- package/browser/dist/schema/Schema.js +1 -1
- package/browser/dist/schema/yaml-1.1/omap.js +1 -1
- package/browser/dist/schema/yaml-1.1/pairs.js +1 -2
- package/browser/dist/schema/yaml-1.1/set.js +4 -0
- package/browser/dist/stringify/stringify.js +6 -8
- package/browser/dist/stringify/stringifyCollection.js +1 -2
- package/browser/dist/stringify/stringifyDocument.js +1 -2
- package/browser/dist/stringify/stringifyString.js +2 -2
- package/browser/dist/visit.js +5 -6
- package/dist/compose/compose-collection.js +1 -1
- package/dist/compose/compose-doc.js +2 -2
- package/dist/compose/compose-scalar.js +6 -7
- package/dist/compose/composer.js +2 -3
- package/dist/compose/resolve-block-map.js +8 -8
- package/dist/compose/resolve-block-scalar.js +1 -1
- package/dist/compose/resolve-flow-collection.js +3 -4
- package/dist/compose/resolve-flow-scalar.js +1 -2
- package/dist/compose/resolve-props.d.ts +1 -0
- package/dist/compose/resolve-props.js +6 -2
- package/dist/compose/util-empty-scalar-position.js +1 -1
- package/dist/compose/util-flow-indent-check.js +1 -1
- package/dist/doc/Document.d.ts +10 -10
- package/dist/doc/Document.js +6 -6
- package/dist/doc/anchors.d.ts +1 -1
- package/dist/doc/createNode.js +5 -7
- package/dist/index.d.ts +2 -0
- package/dist/nodes/Collection.d.ts +2 -2
- package/dist/nodes/Collection.js +2 -1
- package/dist/nodes/Node.d.ts +15 -9
- package/dist/nodes/Pair.d.ts +1 -1
- package/dist/nodes/Pair.js +2 -2
- package/dist/nodes/Scalar.js +1 -1
- package/dist/nodes/YAMLMap.d.ts +6 -3
- package/dist/nodes/YAMLMap.js +6 -7
- package/dist/nodes/YAMLSeq.d.ts +4 -1
- package/dist/nodes/YAMLSeq.js +1 -9
- package/dist/nodes/addPairToJSMap.js +1 -1
- package/dist/nodes/toJS.js +1 -1
- package/dist/options.d.ts +2 -1
- package/dist/parse/cst-scalar.js +1 -2
- package/dist/parse/cst-visit.js +2 -2
- package/dist/parse/lexer.js +1 -2
- package/dist/parse/parser.js +24 -26
- package/dist/public-api.js +3 -4
- package/dist/schema/Schema.d.ts +3 -3
- package/dist/schema/Schema.js +1 -1
- package/dist/schema/json-schema.d.ts +69 -0
- package/dist/schema/yaml-1.1/omap.d.ts +7 -3
- package/dist/schema/yaml-1.1/omap.js +1 -1
- package/dist/schema/yaml-1.1/pairs.js +1 -2
- package/dist/schema/yaml-1.1/set.d.ts +6 -2
- package/dist/schema/yaml-1.1/set.js +4 -0
- package/dist/stringify/stringify.js +6 -8
- package/dist/stringify/stringifyCollection.js +1 -2
- package/dist/stringify/stringifyDocument.js +1 -2
- package/dist/stringify/stringifyString.js +2 -2
- package/dist/test-events.js +2 -3
- package/dist/visit.js +5 -6
- package/package.json +3 -3
- package/dist/node_modules/tslib/tslib.es6.js +0 -76
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var utilContainsNewline = require('./util-contains-newline.js');
|
|
4
4
|
|
|
5
5
|
function flowIndentCheck(indent, fc, onError) {
|
|
6
|
-
if (
|
|
6
|
+
if (fc?.type === 'flow-collection') {
|
|
7
7
|
const end = fc.end[0];
|
|
8
8
|
if (end.indent === indent &&
|
|
9
9
|
(end.source === ']' || end.source === '}') &&
|
package/dist/doc/Document.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { YAMLError, YAMLWarning } from '../errors.js';
|
|
2
2
|
import { Alias } from '../nodes/Alias.js';
|
|
3
|
-
import { Node, NODE_TYPE, ParsedNode, Range } from '../nodes/Node.js';
|
|
3
|
+
import { Node, NodeType, NODE_TYPE, ParsedNode, Range } from '../nodes/Node.js';
|
|
4
4
|
import { Pair } from '../nodes/Pair.js';
|
|
5
5
|
import type { Scalar } from '../nodes/Scalar.js';
|
|
6
6
|
import type { YAMLMap } from '../nodes/YAMLMap.js';
|
|
@@ -15,7 +15,7 @@ export declare namespace Document {
|
|
|
15
15
|
range: Range;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
export declare class Document<T =
|
|
18
|
+
export declare class Document<T extends Node = Node> {
|
|
19
19
|
readonly [NODE_TYPE]: symbol;
|
|
20
20
|
/** A comment before this Document */
|
|
21
21
|
commentBefore: string | null;
|
|
@@ -26,7 +26,7 @@ export declare class Document<T = unknown> {
|
|
|
26
26
|
directives?: Directives;
|
|
27
27
|
/** Errors encountered during parsing. */
|
|
28
28
|
errors: YAMLError[];
|
|
29
|
-
options: Required<Omit<ParseOptions & DocumentOptions, '
|
|
29
|
+
options: Required<Omit<ParseOptions & DocumentOptions, '_directives' | 'lineCounter' | 'version'>>;
|
|
30
30
|
/**
|
|
31
31
|
* The `[start, value-end, node-end]` character offsets for the part of the
|
|
32
32
|
* source parsed into this document (undefined if not parsed). The `value-end`
|
|
@@ -68,8 +68,8 @@ export declare class Document<T = unknown> {
|
|
|
68
68
|
* Convert any value into a `Node` using the current schema, recursively
|
|
69
69
|
* turning objects into collections.
|
|
70
70
|
*/
|
|
71
|
-
createNode(value:
|
|
72
|
-
createNode(value:
|
|
71
|
+
createNode<T = unknown>(value: T, options?: CreateNodeOptions): NodeType<T>;
|
|
72
|
+
createNode<T = unknown>(value: T, replacer: Replacer | CreateNodeOptions | null, options?: CreateNodeOptions): NodeType<T>;
|
|
73
73
|
/**
|
|
74
74
|
* Convert a key and a value into a `Pair` using the current schema,
|
|
75
75
|
* recursively wrapping all values as `Scalar` or `Collection` nodes.
|
|
@@ -79,12 +79,12 @@ export declare class Document<T = unknown> {
|
|
|
79
79
|
* Removes a value from the document.
|
|
80
80
|
* @returns `true` if the item was found and removed.
|
|
81
81
|
*/
|
|
82
|
-
delete(key:
|
|
82
|
+
delete(key: unknown): boolean;
|
|
83
83
|
/**
|
|
84
84
|
* Removes a value from the document.
|
|
85
85
|
* @returns `true` if the item was found and removed.
|
|
86
86
|
*/
|
|
87
|
-
deleteIn(path: Iterable<unknown>): boolean;
|
|
87
|
+
deleteIn(path: Iterable<unknown> | null): boolean;
|
|
88
88
|
/**
|
|
89
89
|
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
90
90
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
@@ -96,7 +96,7 @@ export declare class Document<T = unknown> {
|
|
|
96
96
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
97
97
|
* `true` (collections are always returned intact).
|
|
98
98
|
*/
|
|
99
|
-
getIn(path: Iterable<unknown
|
|
99
|
+
getIn(path: Iterable<unknown> | null, keepScalar?: boolean): unknown;
|
|
100
100
|
/**
|
|
101
101
|
* Checks if the document includes a value with the key `key`.
|
|
102
102
|
*/
|
|
@@ -104,7 +104,7 @@ export declare class Document<T = unknown> {
|
|
|
104
104
|
/**
|
|
105
105
|
* Checks if the document includes a value at `path`.
|
|
106
106
|
*/
|
|
107
|
-
hasIn(path: Iterable<unknown>): boolean;
|
|
107
|
+
hasIn(path: Iterable<unknown> | null): boolean;
|
|
108
108
|
/**
|
|
109
109
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
110
110
|
* boolean to add/remove the item from the set.
|
|
@@ -114,7 +114,7 @@ export declare class Document<T = unknown> {
|
|
|
114
114
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
115
115
|
* boolean to add/remove the item from the set.
|
|
116
116
|
*/
|
|
117
|
-
setIn(path: Iterable<unknown
|
|
117
|
+
setIn(path: Iterable<unknown> | null, value: unknown): void;
|
|
118
118
|
/**
|
|
119
119
|
* Change the YAML version and schema used by the document.
|
|
120
120
|
* A `null` version disables support for directives, explicit tags, anchors, and aliases.
|
package/dist/doc/Document.js
CHANGED
|
@@ -43,8 +43,8 @@ class Document {
|
|
|
43
43
|
}, options);
|
|
44
44
|
this.options = opt;
|
|
45
45
|
let { version } = opt;
|
|
46
|
-
if (options
|
|
47
|
-
this.directives = options.
|
|
46
|
+
if (options?._directives) {
|
|
47
|
+
this.directives = options._directives.atDocument();
|
|
48
48
|
if (this.directives.yaml.explicit)
|
|
49
49
|
version = this.directives.yaml.version;
|
|
50
50
|
}
|
|
@@ -126,13 +126,13 @@ class Document {
|
|
|
126
126
|
options = replacer;
|
|
127
127
|
replacer = undefined;
|
|
128
128
|
}
|
|
129
|
-
const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options
|
|
129
|
+
const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options ?? {};
|
|
130
130
|
const { onAnchor, setAnchors, sourceObjects } = anchors.createNodeAnchors(this,
|
|
131
131
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
132
132
|
anchorPrefix || 'a');
|
|
133
133
|
const ctx = {
|
|
134
|
-
aliasDuplicateObjects: aliasDuplicateObjects
|
|
135
|
-
keepUndefined: keepUndefined
|
|
134
|
+
aliasDuplicateObjects: aliasDuplicateObjects ?? true,
|
|
135
|
+
keepUndefined: keepUndefined ?? false,
|
|
136
136
|
onAnchor,
|
|
137
137
|
onTagObj,
|
|
138
138
|
replacer: _replacer,
|
|
@@ -296,7 +296,7 @@ class Document {
|
|
|
296
296
|
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100,
|
|
297
297
|
stringify: stringify.stringify
|
|
298
298
|
};
|
|
299
|
-
const res = toJS.toJS(this.contents, jsonArg
|
|
299
|
+
const res = toJS.toJS(this.contents, jsonArg ?? '', ctx);
|
|
300
300
|
if (typeof onAnchor === 'function')
|
|
301
301
|
for (const { count, res } of ctx.anchors.values())
|
|
302
302
|
onAnchor(res, count);
|
package/dist/doc/anchors.d.ts
CHANGED
package/dist/doc/createNode.js
CHANGED
|
@@ -6,24 +6,22 @@ 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;
|
|
10
9
|
if (tagName) {
|
|
11
10
|
const match = tags.filter(t => t.tag === tagName);
|
|
12
|
-
const tagObj =
|
|
11
|
+
const tagObj = match.find(t => !t.format) ?? match[0];
|
|
13
12
|
if (!tagObj)
|
|
14
13
|
throw new Error(`Tag ${tagName} not found`);
|
|
15
14
|
return tagObj;
|
|
16
15
|
}
|
|
17
|
-
return tags.find(t =>
|
|
16
|
+
return tags.find(t => t.identify?.(value) && !t.format);
|
|
18
17
|
}
|
|
19
18
|
function createNode(value, tagName, ctx) {
|
|
20
|
-
var _a, _b;
|
|
21
19
|
if (Node.isDocument(value))
|
|
22
20
|
value = value.contents;
|
|
23
21
|
if (Node.isNode(value))
|
|
24
22
|
return value;
|
|
25
23
|
if (Node.isPair(value)) {
|
|
26
|
-
const map =
|
|
24
|
+
const map = ctx.schema[Node.MAP].createNode?.(ctx.schema, null, ctx);
|
|
27
25
|
map.items.push(value);
|
|
28
26
|
return map;
|
|
29
27
|
}
|
|
@@ -51,7 +49,7 @@ function createNode(value, tagName, ctx) {
|
|
|
51
49
|
sourceObjects.set(value, ref);
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
|
-
if (tagName
|
|
52
|
+
if (tagName?.startsWith('!!'))
|
|
55
53
|
tagName = defaultTagPrefix + tagName.slice(2);
|
|
56
54
|
let tagObj = findTagObject(value, tagName, schema.tags);
|
|
57
55
|
if (!tagObj) {
|
|
@@ -76,7 +74,7 @@ function createNode(value, tagName, ctx) {
|
|
|
76
74
|
onTagObj(tagObj);
|
|
77
75
|
delete ctx.onTagObj;
|
|
78
76
|
}
|
|
79
|
-
const node =
|
|
77
|
+
const node = tagObj?.createNode
|
|
80
78
|
? tagObj.createNode(ctx.schema, value, ctx)
|
|
81
79
|
: new Scalar.Scalar(value);
|
|
82
80
|
if (tagName)
|
package/dist/index.d.ts
CHANGED
|
@@ -16,4 +16,6 @@ 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 type { YAMLOMap } from './schema/yaml-1.1/omap';
|
|
20
|
+
export type { YAMLSet } from './schema/yaml-1.1/set';
|
|
19
21
|
export { asyncVisitor, asyncVisitorFn, visit, visitAsync, visitor, visitorFn } from './visit.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Schema } from '../schema/Schema.js';
|
|
2
2
|
import { NodeBase, NODE_TYPE } from './Node.js';
|
|
3
|
-
export declare function collectionFromPath(schema: Schema, path: unknown[], value: unknown): import("./Node.js").Node
|
|
4
|
-
export declare const isEmptyPath: (path: Iterable<unknown> | null | undefined) =>
|
|
3
|
+
export declare function collectionFromPath(schema: Schema, path: unknown[], value: unknown): import("./Node.js").Node<unknown>;
|
|
4
|
+
export declare const isEmptyPath: (path: Iterable<unknown> | null | undefined) => path is null | undefined;
|
|
5
5
|
export declare abstract class Collection extends NodeBase {
|
|
6
6
|
static maxFlowStringSingleLineLength: number;
|
|
7
7
|
schema: Schema | undefined;
|
package/dist/nodes/Collection.js
CHANGED
|
@@ -26,7 +26,8 @@ function collectionFromPath(schema, path, value) {
|
|
|
26
26
|
sourceObjects: new Map()
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
//
|
|
29
|
+
// Type guard is intentionally a little wrong so as to be more useful,
|
|
30
|
+
// as it does not cover untypable empty non-string iterables (e.g. []).
|
|
30
31
|
const isEmptyPath = (path) => path == null ||
|
|
31
32
|
(typeof path === 'object' && !!path[Symbol.iterator]().next().done);
|
|
32
33
|
class Collection extends Node.NodeBase {
|
package/dist/nodes/Node.d.ts
CHANGED
|
@@ -6,7 +6,13 @@ import type { Pair } from './Pair.js';
|
|
|
6
6
|
import type { Scalar } from './Scalar.js';
|
|
7
7
|
import type { YAMLMap } from './YAMLMap.js';
|
|
8
8
|
import type { YAMLSeq } from './YAMLSeq.js';
|
|
9
|
-
export declare type Node = Alias | Scalar | YAMLMap | YAMLSeq
|
|
9
|
+
export declare type Node<T = unknown> = Alias | Scalar<T> | YAMLMap<unknown, T> | YAMLSeq<T>;
|
|
10
|
+
/** Utility type mapper */
|
|
11
|
+
export declare type NodeType<T> = T extends string | number | bigint | boolean | null ? Scalar<T> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
} ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : T extends {
|
|
14
|
+
[key: number]: any;
|
|
15
|
+
} ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
|
|
10
16
|
export declare type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
|
|
11
17
|
export declare type Range = [number, number, number];
|
|
12
18
|
export declare const ALIAS: unique symbol;
|
|
@@ -17,14 +23,14 @@ export declare const SCALAR: unique symbol;
|
|
|
17
23
|
export declare const SEQ: unique symbol;
|
|
18
24
|
export declare const NODE_TYPE: unique symbol;
|
|
19
25
|
export declare const isAlias: (node: any) => node is Alias;
|
|
20
|
-
export declare const isDocument: (node: any) => node is Document<
|
|
21
|
-
export declare const isMap: (node: any) => node is YAMLMap<
|
|
22
|
-
export declare const isPair: (node: any) => node is Pair<
|
|
23
|
-
export declare const isScalar: (node: any) => node is Scalar<
|
|
24
|
-
export declare const isSeq: (node: any) => node is YAMLSeq<
|
|
25
|
-
export declare function isCollection(node: any): node is YAMLMap | YAMLSeq
|
|
26
|
-
export declare function isNode(node: any): node is Node
|
|
27
|
-
export declare const hasAnchor: (node: unknown) => node is Scalar<
|
|
26
|
+
export declare const isDocument: <T extends Node<unknown> = Node<unknown>>(node: any) => node is Document<T>;
|
|
27
|
+
export declare const isMap: <K = unknown, V = unknown>(node: any) => node is YAMLMap<K, V>;
|
|
28
|
+
export declare const isPair: <K = unknown, V = unknown>(node: any) => node is Pair<K, V>;
|
|
29
|
+
export declare const isScalar: <T = unknown>(node: any) => node is Scalar<T>;
|
|
30
|
+
export declare const isSeq: <T = unknown>(node: any) => node is YAMLSeq<T>;
|
|
31
|
+
export declare function isCollection<K = unknown, V = unknown>(node: any): node is YAMLMap<K, V> | YAMLSeq<V>;
|
|
32
|
+
export declare function isNode<T = unknown>(node: any): node is Node<T>;
|
|
33
|
+
export declare const hasAnchor: <K = unknown, V = unknown>(node: unknown) => node is Scalar<V> | YAMLMap<K, V> | YAMLSeq<V>;
|
|
28
34
|
export declare abstract class NodeBase {
|
|
29
35
|
readonly [NODE_TYPE]: symbol;
|
|
30
36
|
/** A comment on or immediately after this */
|
package/dist/nodes/Pair.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { StringifyContext } from '../stringify/stringify.js';
|
|
|
5
5
|
import { addPairToJSMap } from './addPairToJSMap.js';
|
|
6
6
|
import { NODE_TYPE } from './Node.js';
|
|
7
7
|
import type { ToJSContext } from './toJS.js';
|
|
8
|
-
export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node
|
|
8
|
+
export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node<unknown>, import("./Alias.js").Alias | import("./Scalar.js").Scalar<unknown> | import("./YAMLMap.js").YAMLMap<unknown, unknown> | import("./YAMLSeq.js").YAMLSeq<unknown>>;
|
|
9
9
|
export declare class Pair<K = unknown, V = unknown> {
|
|
10
10
|
readonly [NODE_TYPE]: symbol;
|
|
11
11
|
/** Always Node or null when parsed, but can be set to anything. */
|
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 =
|
|
28
|
+
const pair = ctx?.mapAsMap ? new Map() : {};
|
|
29
29
|
return addPairToJSMap.addPairToJSMap(ctx, pair, this);
|
|
30
30
|
}
|
|
31
31
|
toString(ctx, onComment, onChompKeep) {
|
|
32
|
-
return
|
|
32
|
+
return 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
|
|
13
|
+
return 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
|
@@ -4,6 +4,7 @@ import type { StringifyContext } from '../stringify/stringify.js';
|
|
|
4
4
|
import { Collection } from './Collection.js';
|
|
5
5
|
import { ParsedNode, Range } from './Node.js';
|
|
6
6
|
import { Pair } from './Pair.js';
|
|
7
|
+
import { Scalar } from './Scalar.js';
|
|
7
8
|
import type { ToJSContext } from './toJS.js';
|
|
8
9
|
export declare function findPair<K = unknown, V = unknown>(items: Iterable<Pair<K, V>>, key: unknown): Pair<K, V> | undefined;
|
|
9
10
|
export declare namespace YAMLMap {
|
|
@@ -27,9 +28,11 @@ export declare class YAMLMap<K = unknown, V = unknown> extends Collection {
|
|
|
27
28
|
key: K;
|
|
28
29
|
value: V;
|
|
29
30
|
}, overwrite?: boolean): void;
|
|
30
|
-
delete(key:
|
|
31
|
-
get(key:
|
|
32
|
-
|
|
31
|
+
delete(key: unknown): boolean;
|
|
32
|
+
get(key: unknown, keepScalar: true): Scalar<V> | undefined;
|
|
33
|
+
get(key: unknown, keepScalar?: false): V | undefined;
|
|
34
|
+
get(key: unknown, keepScalar?: boolean): V | Scalar<V> | undefined;
|
|
35
|
+
has(key: unknown): boolean;
|
|
33
36
|
set(key: K, value: V): void;
|
|
34
37
|
/**
|
|
35
38
|
* @param ctx - Conversion context, originally set in Document#toJS()
|
package/dist/nodes/YAMLMap.js
CHANGED
|
@@ -34,18 +34,17 @@ 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;
|
|
38
37
|
let _pair;
|
|
39
38
|
if (Node.isPair(pair))
|
|
40
39
|
_pair = pair;
|
|
41
40
|
else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
|
|
42
41
|
// In TypeScript, this never happens.
|
|
43
|
-
_pair = new Pair.Pair(pair, pair
|
|
42
|
+
_pair = new Pair.Pair(pair, pair?.value);
|
|
44
43
|
}
|
|
45
44
|
else
|
|
46
45
|
_pair = new Pair.Pair(pair.key, pair.value);
|
|
47
46
|
const prev = findPair(this.items, _pair.key);
|
|
48
|
-
const sortEntries =
|
|
47
|
+
const sortEntries = this.schema?.sortMapEntries;
|
|
49
48
|
if (prev) {
|
|
50
49
|
if (!overwrite)
|
|
51
50
|
throw new Error(`Key ${_pair.key} already set`);
|
|
@@ -75,8 +74,8 @@ class YAMLMap extends Collection.Collection {
|
|
|
75
74
|
}
|
|
76
75
|
get(key, keepScalar) {
|
|
77
76
|
const it = findPair(this.items, key);
|
|
78
|
-
const node = it
|
|
79
|
-
return !keepScalar && Node.isScalar(node) ? node.value : node;
|
|
77
|
+
const node = it?.value;
|
|
78
|
+
return (!keepScalar && Node.isScalar(node) ? node.value : node) ?? undefined;
|
|
80
79
|
}
|
|
81
80
|
has(key) {
|
|
82
81
|
return !!findPair(this.items, key);
|
|
@@ -90,8 +89,8 @@ class YAMLMap extends Collection.Collection {
|
|
|
90
89
|
* @returns Instance of Type, Map, or Object
|
|
91
90
|
*/
|
|
92
91
|
toJSON(_, ctx, Type) {
|
|
93
|
-
const map = Type ? new Type() :
|
|
94
|
-
if (ctx
|
|
92
|
+
const map = Type ? new Type() : ctx?.mapAsMap ? new Map() : {};
|
|
93
|
+
if (ctx?.onCreate)
|
|
95
94
|
ctx.onCreate(map);
|
|
96
95
|
for (const item of this.items)
|
|
97
96
|
addPairToJSMap.addPairToJSMap(ctx, map, item);
|
package/dist/nodes/YAMLSeq.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { StringifyContext } from '../stringify/stringify.js';
|
|
|
4
4
|
import { Collection } from './Collection.js';
|
|
5
5
|
import { ParsedNode, Range } from './Node.js';
|
|
6
6
|
import type { Pair } from './Pair.js';
|
|
7
|
+
import { Scalar } from './Scalar.js';
|
|
7
8
|
import { ToJSContext } from './toJS.js';
|
|
8
9
|
export declare namespace YAMLSeq {
|
|
9
10
|
interface Parsed<T extends ParsedNode | Pair<ParsedNode, ParsedNode | null> = ParsedNode> extends YAMLSeq<T> {
|
|
@@ -34,7 +35,9 @@ export declare class YAMLSeq<T = unknown> extends Collection {
|
|
|
34
35
|
* `key` must contain a representation of an integer for this to succeed.
|
|
35
36
|
* It may be wrapped in a `Scalar`.
|
|
36
37
|
*/
|
|
37
|
-
get(key: unknown, keepScalar
|
|
38
|
+
get(key: unknown, keepScalar: true): Scalar<T> | undefined;
|
|
39
|
+
get(key: unknown, keepScalar?: false): T | undefined;
|
|
40
|
+
get(key: unknown, keepScalar?: boolean): T | Scalar<T> | undefined;
|
|
38
41
|
/**
|
|
39
42
|
* Checks if the collection includes a value with the key `key`.
|
|
40
43
|
*
|
package/dist/nodes/YAMLSeq.js
CHANGED
|
@@ -32,14 +32,6 @@ class YAMLSeq extends Collection.Collection {
|
|
|
32
32
|
const del = this.items.splice(idx, 1);
|
|
33
33
|
return del.length > 0;
|
|
34
34
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
37
|
-
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
38
|
-
* `true` (collections are always returned intact).
|
|
39
|
-
*
|
|
40
|
-
* `key` must contain a representation of an integer for this to succeed.
|
|
41
|
-
* It may be wrapped in a `Scalar`.
|
|
42
|
-
*/
|
|
43
35
|
get(key, keepScalar) {
|
|
44
36
|
const idx = asItemIndex(key);
|
|
45
37
|
if (typeof idx !== 'number')
|
|
@@ -76,7 +68,7 @@ class YAMLSeq extends Collection.Collection {
|
|
|
76
68
|
}
|
|
77
69
|
toJSON(_, ctx) {
|
|
78
70
|
const seq = [];
|
|
79
|
-
if (ctx
|
|
71
|
+
if (ctx?.onCreate)
|
|
80
72
|
ctx.onCreate(seq);
|
|
81
73
|
let i = 0;
|
|
82
74
|
for (const item of this.items)
|
|
@@ -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 (
|
|
11
|
+
if (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
|
@@ -31,7 +31,7 @@ function toJS(value, arg, ctx) {
|
|
|
31
31
|
ctx.onCreate(res);
|
|
32
32
|
return res;
|
|
33
33
|
}
|
|
34
|
-
if (typeof value === 'bigint' && !
|
|
34
|
+
if (typeof value === 'bigint' && !ctx?.keep)
|
|
35
35
|
return Number(value);
|
|
36
36
|
return value;
|
|
37
37
|
}
|
package/dist/options.d.ts
CHANGED
|
@@ -58,10 +58,11 @@ export declare type ParseOptions = {
|
|
|
58
58
|
};
|
|
59
59
|
export declare type DocumentOptions = {
|
|
60
60
|
/**
|
|
61
|
+
* @internal
|
|
61
62
|
* Used internally by Composer. If set and includes an explicit version,
|
|
62
63
|
* that overrides the `version` option.
|
|
63
64
|
*/
|
|
64
|
-
|
|
65
|
+
_directives?: Directives;
|
|
65
66
|
/**
|
|
66
67
|
* Control the logging level during parsing
|
|
67
68
|
*
|
package/dist/parse/cst-scalar.js
CHANGED
|
@@ -40,7 +40,6 @@ function resolveAsScalar(token, strict = true, onError) {
|
|
|
40
40
|
* @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
|
|
41
41
|
*/
|
|
42
42
|
function createScalarToken(value, context) {
|
|
43
|
-
var _a;
|
|
44
43
|
const { implicitKey = false, indent, inFlow = false, offset = -1, type = 'PLAIN' } = context;
|
|
45
44
|
const source = stringifyString.stringifyString({ type, value }, {
|
|
46
45
|
implicitKey,
|
|
@@ -48,7 +47,7 @@ function createScalarToken(value, context) {
|
|
|
48
47
|
inFlow,
|
|
49
48
|
options: { blockQuote: true, lineWidth: -1 }
|
|
50
49
|
});
|
|
51
|
-
const end =
|
|
50
|
+
const end = context.end ?? [
|
|
52
51
|
{ type: 'newline', offset: -1, indent, source: '\n' }
|
|
53
52
|
];
|
|
54
53
|
switch (source[0]) {
|
package/dist/parse/cst-visit.js
CHANGED
|
@@ -49,7 +49,7 @@ visit.REMOVE = REMOVE;
|
|
|
49
49
|
visit.itemAtPath = (cst, path) => {
|
|
50
50
|
let item = cst;
|
|
51
51
|
for (const [field, index] of path) {
|
|
52
|
-
const tok = item
|
|
52
|
+
const tok = item?.[field];
|
|
53
53
|
if (tok && 'items' in tok) {
|
|
54
54
|
item = tok.items[index];
|
|
55
55
|
}
|
|
@@ -66,7 +66,7 @@ visit.itemAtPath = (cst, path) => {
|
|
|
66
66
|
visit.parentCollection = (cst, path) => {
|
|
67
67
|
const parent = visit.itemAtPath(cst, path.slice(0, -1));
|
|
68
68
|
const field = path[path.length - 1][0];
|
|
69
|
-
const coll = parent
|
|
69
|
+
const coll = parent?.[field];
|
|
70
70
|
if (coll && 'items' in coll)
|
|
71
71
|
return coll;
|
|
72
72
|
throw new Error('Parent collection not found');
|
package/dist/parse/lexer.js
CHANGED
|
@@ -150,13 +150,12 @@ class Lexer {
|
|
|
150
150
|
* @returns A generator of lexical tokens
|
|
151
151
|
*/
|
|
152
152
|
*lex(source, incomplete = false) {
|
|
153
|
-
var _a;
|
|
154
153
|
if (source) {
|
|
155
154
|
this.buffer = this.buffer ? this.buffer + source : source;
|
|
156
155
|
this.lineEndPos = null;
|
|
157
156
|
}
|
|
158
157
|
this.atEnd = !incomplete;
|
|
159
|
-
let next =
|
|
158
|
+
let next = this.next ?? 'stream';
|
|
160
159
|
while (next && (incomplete || this.hasChars(1)))
|
|
161
160
|
next = yield* this.parseNext(next);
|
|
162
161
|
}
|