yaml 2.0.0-7 → 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 +14 -3
- package/browser/dist/compose/compose-scalar.js +17 -10
- package/browser/dist/compose/composer.js +6 -7
- package/browser/dist/compose/resolve-block-map.js +19 -5
- 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 +18 -6
- package/browser/dist/compose/resolve-flow-scalar.js +9 -2
- 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 +73 -16
- package/browser/dist/doc/anchors.js +2 -2
- package/browser/dist/doc/createNode.js +12 -7
- package/browser/dist/doc/directives.js +11 -3
- package/browser/dist/index.js +1 -2
- package/browser/dist/node_modules/tslib/tslib.es6.js +164 -0
- package/browser/dist/nodes/Collection.js +28 -15
- package/browser/dist/nodes/Node.js +7 -0
- package/browser/dist/nodes/Pair.js +11 -3
- 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 +3 -2
- package/browser/dist/nodes/toJS.js +3 -1
- package/browser/dist/parse/cst-scalar.js +2 -6
- package/browser/dist/parse/cst-visit.js +2 -2
- package/browser/dist/parse/lexer.js +50 -22
- package/browser/dist/parse/parser.js +121 -45
- package/browser/dist/public-api.js +4 -5
- package/browser/dist/schema/Schema.js +19 -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 +17 -13
- 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 +53 -23
- 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 +35 -21
- package/browser/dist/stringify/stringifyString.js +41 -43
- package/browser/dist/util.js +3 -0
- 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 +14 -3
- package/dist/compose/compose-scalar.js +16 -9
- package/dist/compose/composer.d.ts +1 -1
- package/dist/compose/composer.js +8 -9
- package/dist/compose/resolve-block-map.js +19 -5
- 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 +18 -6
- package/dist/compose/resolve-flow-scalar.js +9 -2
- 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 +13 -4
- package/dist/doc/Document.js +79 -22
- package/dist/doc/anchors.d.ts +2 -2
- package/dist/doc/anchors.js +2 -2
- package/dist/doc/createNode.d.ts +3 -2
- package/dist/doc/createNode.js +11 -6
- package/dist/doc/directives.d.ts +5 -2
- package/dist/doc/directives.js +11 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -2
- package/dist/node_modules/tslib/tslib.es6.js +76 -0
- package/dist/nodes/Alias.d.ts +7 -3
- package/dist/nodes/Collection.d.ts +10 -4
- package/dist/nodes/Collection.js +27 -14
- package/dist/nodes/Node.d.ts +6 -1
- package/dist/nodes/Node.js +7 -0
- package/dist/nodes/Pair.d.ts +7 -2
- package/dist/nodes/Pair.js +10 -2
- package/dist/nodes/Scalar.d.ts +2 -0
- package/dist/nodes/Scalar.js +1 -1
- package/dist/nodes/YAMLMap.d.ts +5 -1
- package/dist/nodes/YAMLMap.js +6 -5
- package/dist/nodes/YAMLSeq.d.ts +2 -0
- package/dist/nodes/YAMLSeq.js +2 -2
- package/dist/nodes/addPairToJSMap.js +2 -1
- package/dist/nodes/toJS.js +3 -1
- package/dist/options.d.ts +67 -15
- package/dist/parse/cst-scalar.d.ts +6 -0
- package/dist/parse/cst-scalar.js +2 -6
- package/dist/parse/cst-visit.js +2 -2
- package/dist/parse/lexer.d.ts +2 -0
- package/dist/parse/lexer.js +50 -22
- package/dist/parse/parser.js +121 -45
- package/dist/public-api.js +4 -5
- package/dist/schema/Schema.d.ts +6 -4
- package/dist/schema/Schema.js +18 -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 +17 -13
- 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 +53 -23
- 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 +34 -20
- package/dist/stringify/stringifyString.js +41 -43
- package/dist/test-events.d.ts +1 -1
- package/dist/test-events.js +13 -12
- package/dist/util.d.ts +3 -0
- package/dist/util.js +6 -0
- package/dist/visit.d.ts +49 -10
- package/dist/visit.js +149 -60
- package/package.json +12 -10
- package/util.d.ts +3 -0
- package/browser/dist/options.js +0 -17
- package/dist/options.js +0 -19
package/dist/doc/directives.js
CHANGED
|
@@ -18,10 +18,17 @@ 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
|
}
|
|
27
|
+
clone() {
|
|
28
|
+
const copy = new Directives(this.yaml, this.tags);
|
|
29
|
+
copy.docStart = this.docStart;
|
|
30
|
+
return copy;
|
|
31
|
+
}
|
|
25
32
|
/**
|
|
26
33
|
* During parsing, get a Directives instance for the current document and
|
|
27
34
|
* update the stream state according to the current version's spec.
|
|
@@ -68,7 +75,7 @@ class Directives {
|
|
|
68
75
|
}
|
|
69
76
|
case '%YAML': {
|
|
70
77
|
this.yaml.explicit = true;
|
|
71
|
-
if (parts.length
|
|
78
|
+
if (parts.length !== 1) {
|
|
72
79
|
onError(0, '%YAML directive should contain exactly one part');
|
|
73
80
|
return false;
|
|
74
81
|
}
|
|
@@ -78,7 +85,8 @@ class Directives {
|
|
|
78
85
|
return true;
|
|
79
86
|
}
|
|
80
87
|
else {
|
|
81
|
-
|
|
88
|
+
const isValid = /^\d+\.\d+$/.test(version);
|
|
89
|
+
onError(6, `Unsupported YAML version ${version}`, isValid);
|
|
82
90
|
return false;
|
|
83
91
|
}
|
|
84
92
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export { Composer } from './compose/composer.js';
|
|
2
2
|
export { Document } from './doc/Document.js';
|
|
3
3
|
export { Schema } from './schema/Schema.js';
|
|
4
|
-
export { YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
|
|
4
|
+
export { ErrorCode, YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
|
|
5
5
|
export { Alias } from './nodes/Alias.js';
|
|
6
|
-
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq, Node, ParsedNode } from './nodes/Node.js';
|
|
6
|
+
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq, Node, ParsedNode, Range } from './nodes/Node.js';
|
|
7
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;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*! *****************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
/* global Reflect, Promise */
|
|
18
|
+
|
|
19
|
+
var extendStatics = function(d, b) {
|
|
20
|
+
extendStatics = Object.setPrototypeOf ||
|
|
21
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
22
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
23
|
+
return extendStatics(d, b);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function __extends(d, b) {
|
|
27
|
+
if (typeof b !== "function" && b !== null)
|
|
28
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
29
|
+
extendStatics(d, b);
|
|
30
|
+
function __() { this.constructor = d; }
|
|
31
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function __generator(thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (_) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function __values(o) {
|
|
63
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
64
|
+
if (m) return m.call(o);
|
|
65
|
+
if (o && typeof o.length === "number") return {
|
|
66
|
+
next: function () {
|
|
67
|
+
if (o && i >= o.length) o = void 0;
|
|
68
|
+
return { value: o && o[i++], done: !o };
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
exports.__extends = __extends;
|
|
75
|
+
exports.__generator = __generator;
|
|
76
|
+
exports.__values = __values;
|
package/dist/nodes/Alias.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import type { Document } from '../doc/Document';
|
|
1
|
+
import type { Document } from '../doc/Document.js';
|
|
2
|
+
import type { FlowScalar } from '../parse/cst.js';
|
|
2
3
|
import type { StringifyContext } from '../stringify/stringify.js';
|
|
3
4
|
import { NodeBase, Range } from './Node.js';
|
|
4
5
|
import type { Scalar } from './Scalar';
|
|
5
6
|
import type { ToJSContext } from './toJS.js';
|
|
6
|
-
import type { YAMLMap } from './YAMLMap';
|
|
7
|
-
import type { YAMLSeq } from './YAMLSeq';
|
|
7
|
+
import type { YAMLMap } from './YAMLMap.js';
|
|
8
|
+
import type { YAMLSeq } from './YAMLSeq.js';
|
|
8
9
|
export declare namespace Alias {
|
|
9
10
|
interface Parsed extends Alias {
|
|
10
11
|
range: Range;
|
|
12
|
+
srcToken?: FlowScalar & {
|
|
13
|
+
type: 'alias';
|
|
14
|
+
};
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
export declare class Alias extends NodeBase {
|
|
@@ -15,6 +15,12 @@ export declare abstract class Collection extends NodeBase {
|
|
|
15
15
|
*/
|
|
16
16
|
flow?: boolean;
|
|
17
17
|
constructor(type: symbol, schema?: Schema);
|
|
18
|
+
/**
|
|
19
|
+
* Create a copy of this collection.
|
|
20
|
+
*
|
|
21
|
+
* @param schema - If defined, overwrites the original's schema
|
|
22
|
+
*/
|
|
23
|
+
clone(schema?: Schema): Collection;
|
|
18
24
|
/** Adds a value to the collection. */
|
|
19
25
|
abstract add(value: unknown): void;
|
|
20
26
|
/**
|
|
@@ -47,21 +53,21 @@ export declare abstract class Collection extends NodeBase {
|
|
|
47
53
|
* Removes a value from the collection.
|
|
48
54
|
* @returns `true` if the item was found and removed.
|
|
49
55
|
*/
|
|
50
|
-
deleteIn(
|
|
56
|
+
deleteIn(path: Iterable<unknown>): boolean;
|
|
51
57
|
/**
|
|
52
58
|
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
53
59
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
54
60
|
* `true` (collections are always returned intact).
|
|
55
61
|
*/
|
|
56
|
-
getIn(
|
|
62
|
+
getIn(path: Iterable<unknown>, keepScalar?: boolean): unknown;
|
|
57
63
|
hasAllNullValues(allowScalar?: boolean): boolean;
|
|
58
64
|
/**
|
|
59
65
|
* Checks if the collection includes a value with the key `key`.
|
|
60
66
|
*/
|
|
61
|
-
hasIn(
|
|
67
|
+
hasIn(path: Iterable<unknown>): boolean;
|
|
62
68
|
/**
|
|
63
69
|
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
64
70
|
* boolean to add/remove the item from the set.
|
|
65
71
|
*/
|
|
66
|
-
setIn(
|
|
72
|
+
setIn(path: Iterable<unknown>, value: unknown): void;
|
|
67
73
|
}
|
package/dist/nodes/Collection.js
CHANGED
|
@@ -13,19 +13,14 @@ function collectionFromPath(schema, path, value) {
|
|
|
13
13
|
v = a;
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
|
-
|
|
17
|
-
Object.defineProperty(o, typeof k === 'symbol' ? k : String(k), {
|
|
18
|
-
value: v,
|
|
19
|
-
writable: true,
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true
|
|
22
|
-
});
|
|
23
|
-
v = o;
|
|
16
|
+
v = new Map([[k, v]]);
|
|
24
17
|
}
|
|
25
18
|
}
|
|
26
19
|
return createNode.createNode(v, undefined, {
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
aliasDuplicateObjects: false,
|
|
21
|
+
keepUndefined: false,
|
|
22
|
+
onAnchor: () => {
|
|
23
|
+
throw new Error('This should not happen, please report a bug.');
|
|
29
24
|
},
|
|
30
25
|
schema,
|
|
31
26
|
sourceObjects: new Map()
|
|
@@ -44,6 +39,20 @@ class Collection extends Node.NodeBase {
|
|
|
44
39
|
writable: true
|
|
45
40
|
});
|
|
46
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a copy of this collection.
|
|
44
|
+
*
|
|
45
|
+
* @param schema - If defined, overwrites the original's schema
|
|
46
|
+
*/
|
|
47
|
+
clone(schema) {
|
|
48
|
+
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
49
|
+
if (schema)
|
|
50
|
+
copy.schema = schema;
|
|
51
|
+
copy.items = copy.items.map(it => Node.isNode(it) || Node.isPair(it) ? it.clone(schema) : it);
|
|
52
|
+
if (this.range)
|
|
53
|
+
copy.range = this.range.slice();
|
|
54
|
+
return copy;
|
|
55
|
+
}
|
|
47
56
|
/**
|
|
48
57
|
* Adds a value to the collection. For `!!map` and `!!omap` the value must
|
|
49
58
|
* be a Pair instance or a `{ key, value }` object, which may not have a key
|
|
@@ -67,7 +76,8 @@ class Collection extends Node.NodeBase {
|
|
|
67
76
|
* Removes a value from the collection.
|
|
68
77
|
* @returns `true` if the item was found and removed.
|
|
69
78
|
*/
|
|
70
|
-
deleteIn(
|
|
79
|
+
deleteIn(path) {
|
|
80
|
+
const [key, ...rest] = path;
|
|
71
81
|
if (rest.length === 0)
|
|
72
82
|
return this.delete(key);
|
|
73
83
|
const node = this.get(key, true);
|
|
@@ -81,7 +91,8 @@ class Collection extends Node.NodeBase {
|
|
|
81
91
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
82
92
|
* `true` (collections are always returned intact).
|
|
83
93
|
*/
|
|
84
|
-
getIn(
|
|
94
|
+
getIn(path, keepScalar) {
|
|
95
|
+
const [key, ...rest] = path;
|
|
85
96
|
const node = this.get(key, true);
|
|
86
97
|
if (rest.length === 0)
|
|
87
98
|
return !keepScalar && Node.isScalar(node) ? node.value : node;
|
|
@@ -105,7 +116,8 @@ class Collection extends Node.NodeBase {
|
|
|
105
116
|
/**
|
|
106
117
|
* Checks if the collection includes a value with the key `key`.
|
|
107
118
|
*/
|
|
108
|
-
hasIn(
|
|
119
|
+
hasIn(path) {
|
|
120
|
+
const [key, ...rest] = path;
|
|
109
121
|
if (rest.length === 0)
|
|
110
122
|
return this.has(key);
|
|
111
123
|
const node = this.get(key, true);
|
|
@@ -115,7 +127,8 @@ class Collection extends Node.NodeBase {
|
|
|
115
127
|
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
116
128
|
* boolean to add/remove the item from the set.
|
|
117
129
|
*/
|
|
118
|
-
setIn(
|
|
130
|
+
setIn(path, value) {
|
|
131
|
+
const [key, ...rest] = path;
|
|
119
132
|
if (rest.length === 0) {
|
|
120
133
|
this.set(key, value);
|
|
121
134
|
}
|
package/dist/nodes/Node.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Document } from '../doc/Document.js';
|
|
2
|
+
import { Token } from '../parse/cst.js';
|
|
2
3
|
import type { StringifyContext } from '../stringify/stringify.js';
|
|
3
4
|
import type { Alias } from './Alias.js';
|
|
4
5
|
import type { Pair } from './Pair.js';
|
|
@@ -23,7 +24,7 @@ export declare const isScalar: (node: any) => node is Scalar<unknown>;
|
|
|
23
24
|
export declare const isSeq: (node: any) => node is YAMLSeq<unknown>;
|
|
24
25
|
export declare function isCollection(node: any): node is YAMLMap | YAMLSeq;
|
|
25
26
|
export declare function isNode(node: any): node is Node;
|
|
26
|
-
export declare const hasAnchor: (node: unknown) => node is
|
|
27
|
+
export declare const hasAnchor: (node: unknown) => node is Scalar<unknown> | YAMLMap<unknown, unknown> | YAMLSeq<unknown>;
|
|
27
28
|
export declare abstract class NodeBase {
|
|
28
29
|
readonly [NODE_TYPE]: symbol;
|
|
29
30
|
/** A comment on or immediately after this */
|
|
@@ -39,10 +40,14 @@ export declare abstract class NodeBase {
|
|
|
39
40
|
range?: Range | null;
|
|
40
41
|
/** A blank line before this node and its commentBefore */
|
|
41
42
|
spaceBefore?: boolean;
|
|
43
|
+
/** The CST token that was composed into this node. */
|
|
44
|
+
srcToken?: Token;
|
|
42
45
|
/** A fully qualified tag, if required */
|
|
43
46
|
tag?: string;
|
|
44
47
|
/** A plain JS representation of this node */
|
|
45
48
|
abstract toJSON(): any;
|
|
46
49
|
abstract toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
|
|
47
50
|
constructor(type: symbol);
|
|
51
|
+
/** Create a copy of this node. */
|
|
52
|
+
clone(): NodeBase;
|
|
48
53
|
}
|
package/dist/nodes/Node.js
CHANGED
|
@@ -38,6 +38,13 @@ class NodeBase {
|
|
|
38
38
|
constructor(type) {
|
|
39
39
|
Object.defineProperty(this, NODE_TYPE, { value: type });
|
|
40
40
|
}
|
|
41
|
+
/** Create a copy of this node. */
|
|
42
|
+
clone() {
|
|
43
|
+
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
44
|
+
if (this.range)
|
|
45
|
+
copy.range = this.range.slice();
|
|
46
|
+
return copy;
|
|
47
|
+
}
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
exports.ALIAS = ALIAS;
|
package/dist/nodes/Pair.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { CreateNodeContext } from '../doc/createNode.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { CollectionItem } from '../parse/cst.js';
|
|
3
|
+
import type { Schema } from '../schema/Schema.js';
|
|
4
|
+
import type { StringifyContext } from '../stringify/stringify.js';
|
|
3
5
|
import { addPairToJSMap } from './addPairToJSMap.js';
|
|
4
6
|
import { NODE_TYPE } from './Node.js';
|
|
5
|
-
import { ToJSContext } from './toJS.js';
|
|
7
|
+
import type { ToJSContext } from './toJS.js';
|
|
6
8
|
export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node, import("./Alias.js").Alias | import("./Scalar.js").Scalar<unknown> | import("./YAMLMap.js").YAMLMap<unknown, unknown> | import("./YAMLSeq.js").YAMLSeq<unknown>>;
|
|
7
9
|
export declare class Pair<K = unknown, V = unknown> {
|
|
8
10
|
readonly [NODE_TYPE]: symbol;
|
|
@@ -10,7 +12,10 @@ export declare class Pair<K = unknown, V = unknown> {
|
|
|
10
12
|
key: K;
|
|
11
13
|
/** Always Node or null when parsed, but can be set to anything. */
|
|
12
14
|
value: V | null;
|
|
15
|
+
/** The CST token that was composed into this pair. */
|
|
16
|
+
srcToken?: CollectionItem;
|
|
13
17
|
constructor(key: K, value?: V | null);
|
|
18
|
+
clone(schema?: Schema): Pair<K, V>;
|
|
14
19
|
toJSON(_?: unknown, ctx?: ToJSContext): ReturnType<typeof addPairToJSMap>;
|
|
15
20
|
toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
|
|
16
21
|
}
|
package/dist/nodes/Pair.js
CHANGED
|
@@ -16,12 +16,20 @@ class Pair {
|
|
|
16
16
|
this.key = key;
|
|
17
17
|
this.value = value;
|
|
18
18
|
}
|
|
19
|
+
clone(schema) {
|
|
20
|
+
let { key, value } = this;
|
|
21
|
+
if (Node.isNode(key))
|
|
22
|
+
key = key.clone(schema);
|
|
23
|
+
if (Node.isNode(value))
|
|
24
|
+
value = value.clone(schema);
|
|
25
|
+
return new Pair(key, value);
|
|
26
|
+
}
|
|
19
27
|
toJSON(_, ctx) {
|
|
20
|
-
const pair = ctx
|
|
28
|
+
const pair = (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
|
|
21
29
|
return addPairToJSMap.addPairToJSMap(ctx, pair, this);
|
|
22
30
|
}
|
|
23
31
|
toString(ctx, onComment, onChompKeep) {
|
|
24
|
-
return ctx
|
|
32
|
+
return (ctx === null || ctx === void 0 ? void 0 : ctx.doc)
|
|
25
33
|
? stringifyPair.stringifyPair(this, ctx, onComment, onChompKeep)
|
|
26
34
|
: JSON.stringify(this);
|
|
27
35
|
}
|
package/dist/nodes/Scalar.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BlockScalar, FlowScalar } from '../parse/cst.js';
|
|
1
2
|
import { NodeBase, Range } from './Node.js';
|
|
2
3
|
import { ToJSContext } from './toJS.js';
|
|
3
4
|
export declare const isScalarValue: (value: unknown) => boolean;
|
|
@@ -5,6 +6,7 @@ export declare namespace Scalar {
|
|
|
5
6
|
interface Parsed extends Scalar {
|
|
6
7
|
range: Range;
|
|
7
8
|
source: string;
|
|
9
|
+
srcToken?: FlowScalar | BlockScalar;
|
|
8
10
|
}
|
|
9
11
|
type BLOCK_FOLDED = 'BLOCK_FOLDED';
|
|
10
12
|
type BLOCK_LITERAL = 'BLOCK_LITERAL';
|
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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BlockMap, FlowCollection } from '../parse/cst.js';
|
|
1
2
|
import type { Schema } from '../schema/Schema.js';
|
|
2
3
|
import type { StringifyContext } from '../stringify/stringify.js';
|
|
3
4
|
import { Collection } from './Collection.js';
|
|
@@ -9,6 +10,7 @@ export declare namespace YAMLMap {
|
|
|
9
10
|
interface Parsed<K extends ParsedNode = ParsedNode, V extends ParsedNode | null = ParsedNode | null> extends YAMLMap<K, V> {
|
|
10
11
|
items: Pair<K, V>[];
|
|
11
12
|
range: Range;
|
|
13
|
+
srcToken?: BlockMap | FlowCollection;
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
export declare class YAMLMap<K = unknown, V = unknown> extends Collection {
|
|
@@ -34,6 +36,8 @@ export declare class YAMLMap<K = unknown, V = unknown> extends Collection {
|
|
|
34
36
|
* @param {Class} Type - If set, forces the returned collection type
|
|
35
37
|
* @returns Instance of Type, Map, or Object
|
|
36
38
|
*/
|
|
37
|
-
toJSON(_?: unknown, ctx?: ToJSContext, Type?:
|
|
39
|
+
toJSON<T = unknown>(_?: unknown, ctx?: ToJSContext, Type?: {
|
|
40
|
+
new (): T;
|
|
41
|
+
}): any;
|
|
38
42
|
toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
|
|
39
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.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BlockSequence, FlowCollection } from '../parse/cst.js';
|
|
1
2
|
import type { Schema } from '../schema/Schema.js';
|
|
2
3
|
import type { StringifyContext } from '../stringify/stringify.js';
|
|
3
4
|
import { Collection } from './Collection.js';
|
|
@@ -8,6 +9,7 @@ export declare namespace YAMLSeq {
|
|
|
8
9
|
interface Parsed<T extends ParsedNode | Pair<ParsedNode, ParsedNode | null> = ParsedNode> extends YAMLSeq<T> {
|
|
9
10
|
items: T[];
|
|
10
11
|
range: Range;
|
|
12
|
+
srcToken?: BlockSequence | FlowCollection;
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
15
|
export declare class YAMLSeq<T = unknown> extends Collection {
|
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,8 @@ 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
|
+
value = Node.isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
12
13
|
if (Node.isSeq(value))
|
|
13
14
|
for (const it of value.items)
|
|
14
15
|
mergeToJSMap(ctx, map, it);
|
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
|
}
|