yaml 2.2.1 → 2.3.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/browser/dist/compose/compose-collection.js +1 -1
- package/browser/dist/compose/compose-doc.js +1 -0
- package/browser/dist/compose/compose-scalar.js +1 -1
- package/browser/dist/compose/composer.js +1 -1
- package/browser/dist/compose/resolve-flow-collection.js +1 -1
- package/browser/dist/compose/util-map-includes.js +1 -1
- package/browser/dist/doc/Document.js +12 -10
- package/browser/dist/doc/anchors.js +1 -1
- package/browser/dist/doc/createNode.js +1 -1
- package/browser/dist/doc/directives.js +1 -1
- package/browser/dist/index.js +1 -1
- package/browser/dist/nodes/Alias.js +9 -2
- package/browser/dist/nodes/Collection.js +2 -1
- package/browser/dist/nodes/Node.js +23 -35
- package/browser/dist/nodes/Pair.js +1 -1
- package/browser/dist/nodes/Scalar.js +2 -1
- package/browser/dist/nodes/YAMLMap.js +1 -1
- package/browser/dist/nodes/YAMLSeq.js +1 -1
- package/browser/dist/nodes/addPairToJSMap.js +1 -1
- package/browser/dist/nodes/identity.js +36 -0
- package/browser/dist/nodes/toJS.js +1 -1
- package/browser/dist/schema/Schema.js +1 -1
- package/browser/dist/schema/common/map.js +1 -1
- package/browser/dist/schema/common/seq.js +1 -1
- package/browser/dist/schema/tags.js +1 -1
- package/browser/dist/schema/yaml-1.1/omap.js +2 -2
- package/browser/dist/schema/yaml-1.1/pairs.js +1 -1
- package/browser/dist/schema/yaml-1.1/set.js +1 -1
- package/browser/dist/stringify/stringify.js +1 -1
- package/browser/dist/stringify/stringifyCollection.js +2 -2
- package/browser/dist/stringify/stringifyDocument.js +1 -1
- package/browser/dist/stringify/stringifyPair.js +1 -1
- package/browser/dist/stringify/stringifyString.js +16 -7
- package/browser/dist/util.js +2 -0
- package/browser/dist/visit.js +1 -1
- package/dist/compose/compose-collection.d.ts +1 -1
- package/dist/compose/compose-collection.js +3 -3
- package/dist/compose/compose-doc.d.ts +2 -1
- package/dist/compose/compose-doc.js +1 -0
- package/dist/compose/compose-scalar.js +7 -7
- package/dist/compose/composer.d.ts +5 -5
- package/dist/compose/composer.js +3 -3
- package/dist/compose/resolve-flow-collection.d.ts +1 -1
- package/dist/compose/resolve-flow-collection.js +2 -2
- package/dist/compose/util-map-includes.d.ts +3 -3
- package/dist/compose/util-map-includes.js +3 -3
- package/dist/doc/Document.d.ts +11 -9
- package/dist/doc/Document.js +22 -20
- package/dist/doc/anchors.d.ts +4 -4
- package/dist/doc/anchors.js +2 -2
- package/dist/doc/createNode.d.ts +1 -1
- package/dist/doc/createNode.js +8 -8
- package/dist/doc/directives.js +3 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +9 -9
- package/dist/nodes/Alias.d.ts +1 -1
- package/dist/nodes/Alias.js +12 -5
- package/dist/nodes/Collection.d.ts +3 -2
- package/dist/nodes/Collection.js +10 -9
- package/dist/nodes/Node.d.ts +5 -18
- package/dist/nodes/Node.js +23 -51
- package/dist/nodes/Pair.d.ts +2 -2
- package/dist/nodes/Pair.js +4 -4
- package/dist/nodes/Scalar.js +2 -1
- package/dist/nodes/YAMLMap.d.ts +1 -1
- package/dist/nodes/YAMLMap.js +9 -9
- package/dist/nodes/YAMLSeq.d.ts +1 -1
- package/dist/nodes/YAMLSeq.js +5 -5
- package/dist/nodes/addPairToJSMap.js +7 -7
- package/dist/nodes/identity.d.ts +23 -0
- package/dist/nodes/identity.js +53 -0
- package/dist/nodes/toJS.d.ts +2 -5
- package/dist/nodes/toJS.js +2 -2
- package/dist/public-api.d.ts +3 -3
- package/dist/schema/Schema.d.ts +1 -1
- package/dist/schema/Schema.js +4 -4
- package/dist/schema/common/map.js +2 -2
- package/dist/schema/common/seq.js +2 -2
- package/dist/schema/core/schema.d.ts +1 -1
- package/dist/schema/json/schema.d.ts +1 -1
- package/dist/schema/tags.d.ts +1 -1
- package/dist/schema/yaml-1.1/omap.d.ts +1 -1
- package/dist/schema/yaml-1.1/omap.js +4 -4
- package/dist/schema/yaml-1.1/pairs.d.ts +1 -1
- package/dist/schema/yaml-1.1/pairs.js +5 -5
- package/dist/schema/yaml-1.1/schema.d.ts +1 -1
- package/dist/schema/yaml-1.1/set.js +5 -5
- package/dist/stringify/stringify.js +8 -8
- package/dist/stringify/stringifyCollection.js +9 -9
- package/dist/stringify/stringifyDocument.d.ts +4 -3
- package/dist/stringify/stringifyDocument.js +2 -2
- package/dist/stringify/stringifyPair.js +9 -9
- package/dist/stringify/stringifyString.js +16 -7
- package/dist/test-events.js +8 -8
- package/dist/util.d.ts +3 -1
- package/dist/util.js +4 -0
- package/dist/visit.js +18 -18
- package/package.json +13 -6
- package/util.d.ts +0 -3
package/README.md
CHANGED
|
@@ -14,6 +14,10 @@ It has no external dependencies and runs on Node.js as well as modern browsers.
|
|
|
14
14
|
For the purposes of versioning, any changes that break any of the documented endpoints or APIs will be considered semver-major breaking changes.
|
|
15
15
|
Undocumented library internals may change between minor versions, and previous APIs may be deprecated (but not removed).
|
|
16
16
|
|
|
17
|
+
The minimum supported TypeScript version of the included typings is 3.9;
|
|
18
|
+
for use in earlier versions you may need to set `skipLibCheck: true` in your config.
|
|
19
|
+
This requirement may be updated between minor versions of the library.
|
|
20
|
+
|
|
17
21
|
For more information, see the project's documentation site: [**eemeli.org/yaml**](https://eemeli.org/yaml/)
|
|
18
22
|
|
|
19
23
|
To install:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isNode, isMap } from '../nodes/
|
|
1
|
+
import { isNode, isMap } from '../nodes/identity.js';
|
|
2
2
|
import { Scalar } from '../nodes/Scalar.js';
|
|
3
3
|
import { resolveBlockMap } from './resolve-block-map.js';
|
|
4
4
|
import { resolveBlockSeq } from './resolve-block-seq.js';
|
|
@@ -26,6 +26,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError)
|
|
|
26
26
|
!props.hasNewline)
|
|
27
27
|
onError(props.end, 'MISSING_CHAR', 'Block collection cannot start on same line with directives-end marker');
|
|
28
28
|
}
|
|
29
|
+
// @ts-expect-error If Contents is set, let's trust the user
|
|
29
30
|
doc.contents = value
|
|
30
31
|
? composeNode(ctx, value, props, onError)
|
|
31
32
|
: composeEmptyNode(ctx, props.end, start, null, props, onError);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SCALAR, isScalar } from '../nodes/
|
|
1
|
+
import { SCALAR, isScalar } from '../nodes/identity.js';
|
|
2
2
|
import { Scalar } from '../nodes/Scalar.js';
|
|
3
3
|
import { resolveBlockScalar } from './resolve-block-scalar.js';
|
|
4
4
|
import { resolveFlowScalar } from './resolve-flow-scalar.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Directives } from '../doc/directives.js';
|
|
2
2
|
import { Document } from '../doc/Document.js';
|
|
3
3
|
import { YAMLWarning, YAMLParseError } from '../errors.js';
|
|
4
|
-
import { isCollection, isPair } from '../nodes/
|
|
4
|
+
import { isCollection, isPair } from '../nodes/identity.js';
|
|
5
5
|
import { composeDoc } from './compose-doc.js';
|
|
6
6
|
import { resolveEnd } from './resolve-end.js';
|
|
7
7
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Alias } from '../nodes/Alias.js';
|
|
2
2
|
import { isEmptyPath, collectionFromPath } from '../nodes/Collection.js';
|
|
3
|
-
import { NODE_TYPE, DOC, isNode, isCollection, isScalar } from '../nodes/
|
|
3
|
+
import { NODE_TYPE, DOC, isNode, isCollection, isScalar } from '../nodes/identity.js';
|
|
4
4
|
import { Pair } from '../nodes/Pair.js';
|
|
5
5
|
import { toJS } from '../nodes/toJS.js';
|
|
6
6
|
import { Schema } from '../schema/Schema.js';
|
|
7
|
-
import { stringify } from '../stringify/stringify.js';
|
|
8
7
|
import { stringifyDocument } from '../stringify/stringifyDocument.js';
|
|
9
8
|
import { anchorNames, findNewAnchor, createNodeAnchors } from './anchors.js';
|
|
10
9
|
import { applyReviver } from './applyReviver.js';
|
|
@@ -49,11 +48,9 @@ class Document {
|
|
|
49
48
|
else
|
|
50
49
|
this.directives = new Directives({ version });
|
|
51
50
|
this.setSchema(version, options);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.contents = this.createNode(value, _replacer, options);
|
|
56
|
-
}
|
|
51
|
+
// @ts-expect-error We can't really know that this matches Contents.
|
|
52
|
+
this.contents =
|
|
53
|
+
value === undefined ? null : this.createNode(value, _replacer, options);
|
|
57
54
|
}
|
|
58
55
|
/**
|
|
59
56
|
* Create a deep copy of this Document and its contents.
|
|
@@ -72,6 +69,7 @@ class Document {
|
|
|
72
69
|
if (this.directives)
|
|
73
70
|
copy.directives = this.directives.clone();
|
|
74
71
|
copy.schema = this.schema.clone();
|
|
72
|
+
// @ts-expect-error We can't really know that this matches Contents.
|
|
75
73
|
copy.contents = isNode(this.contents)
|
|
76
74
|
? this.contents.clone(copy.schema)
|
|
77
75
|
: this.contents;
|
|
@@ -167,6 +165,7 @@ class Document {
|
|
|
167
165
|
if (isEmptyPath(path)) {
|
|
168
166
|
if (this.contents == null)
|
|
169
167
|
return false;
|
|
168
|
+
// @ts-expect-error Presumed impossible if Strict extends false
|
|
170
169
|
this.contents = null;
|
|
171
170
|
return true;
|
|
172
171
|
}
|
|
@@ -218,6 +217,7 @@ class Document {
|
|
|
218
217
|
*/
|
|
219
218
|
set(key, value) {
|
|
220
219
|
if (this.contents == null) {
|
|
220
|
+
// @ts-expect-error We can't really know that this matches Contents.
|
|
221
221
|
this.contents = collectionFromPath(this.schema, [key], value);
|
|
222
222
|
}
|
|
223
223
|
else if (assertCollection(this.contents)) {
|
|
@@ -229,9 +229,12 @@ class Document {
|
|
|
229
229
|
* boolean to add/remove the item from the set.
|
|
230
230
|
*/
|
|
231
231
|
setIn(path, value) {
|
|
232
|
-
if (isEmptyPath(path))
|
|
232
|
+
if (isEmptyPath(path)) {
|
|
233
|
+
// @ts-expect-error We can't really know that this matches Contents.
|
|
233
234
|
this.contents = value;
|
|
235
|
+
}
|
|
234
236
|
else if (this.contents == null) {
|
|
237
|
+
// @ts-expect-error We can't really know that this matches Contents.
|
|
235
238
|
this.contents = collectionFromPath(this.schema, Array.from(path), value);
|
|
236
239
|
}
|
|
237
240
|
else if (assertCollection(this.contents)) {
|
|
@@ -291,8 +294,7 @@ class Document {
|
|
|
291
294
|
keep: !json,
|
|
292
295
|
mapAsMap: mapAsMap === true,
|
|
293
296
|
mapKeyWarned: false,
|
|
294
|
-
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100
|
|
295
|
-
stringify
|
|
297
|
+
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100
|
|
296
298
|
};
|
|
297
299
|
const res = toJS(this.contents, jsonArg ?? '', ctx);
|
|
298
300
|
if (typeof onAnchor === 'function')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Alias } from '../nodes/Alias.js';
|
|
2
|
-
import { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/
|
|
2
|
+
import { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/identity.js';
|
|
3
3
|
import { Scalar } from '../nodes/Scalar.js';
|
|
4
4
|
|
|
5
5
|
const defaultTagPrefix = 'tag:yaml.org,2002:';
|
package/browser/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { Document } from './doc/Document.js';
|
|
|
3
3
|
export { Schema } from './schema/Schema.js';
|
|
4
4
|
export { YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
|
|
5
5
|
export { Alias } from './nodes/Alias.js';
|
|
6
|
-
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/
|
|
6
|
+
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/identity.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';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { anchorIsValid } from '../doc/anchors.js';
|
|
2
2
|
import { visit } from '../visit.js';
|
|
3
|
-
import {
|
|
3
|
+
import { ALIAS, isAlias, isCollection, isPair } from './identity.js';
|
|
4
|
+
import { NodeBase } from './Node.js';
|
|
5
|
+
import { toJS } from './toJS.js';
|
|
4
6
|
|
|
5
7
|
class Alias extends NodeBase {
|
|
6
8
|
constructor(source) {
|
|
@@ -37,7 +39,12 @@ class Alias extends NodeBase {
|
|
|
37
39
|
const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
|
|
38
40
|
throw new ReferenceError(msg);
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
let data = anchors.get(source);
|
|
43
|
+
if (!data) {
|
|
44
|
+
// Resolve anchors for Node.prototype.toJS()
|
|
45
|
+
toJS(source, null, ctx);
|
|
46
|
+
data = anchors.get(source);
|
|
47
|
+
}
|
|
41
48
|
/* istanbul ignore if */
|
|
42
49
|
if (!data || data.res === undefined) {
|
|
43
50
|
const msg = 'This should not happen: Alias anchor was not resolved?';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createNode } from '../doc/createNode.js';
|
|
2
|
-
import {
|
|
2
|
+
import { isNode, isPair, isCollection, isScalar } from './identity.js';
|
|
3
|
+
import { NodeBase } from './Node.js';
|
|
3
4
|
|
|
4
5
|
function collectionFromPath(schema, path, value) {
|
|
5
6
|
let v = value;
|
|
@@ -1,37 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const SCALAR = Symbol.for('yaml.scalar');
|
|
6
|
-
const SEQ = Symbol.for('yaml.seq');
|
|
7
|
-
const NODE_TYPE = Symbol.for('yaml.node.type');
|
|
8
|
-
const isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS;
|
|
9
|
-
const isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC;
|
|
10
|
-
const isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP;
|
|
11
|
-
const isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR;
|
|
12
|
-
const isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR;
|
|
13
|
-
const isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ;
|
|
14
|
-
function isCollection(node) {
|
|
15
|
-
if (node && typeof node === 'object')
|
|
16
|
-
switch (node[NODE_TYPE]) {
|
|
17
|
-
case MAP:
|
|
18
|
-
case SEQ:
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
function isNode(node) {
|
|
24
|
-
if (node && typeof node === 'object')
|
|
25
|
-
switch (node[NODE_TYPE]) {
|
|
26
|
-
case ALIAS:
|
|
27
|
-
case MAP:
|
|
28
|
-
case SCALAR:
|
|
29
|
-
case SEQ:
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
|
|
1
|
+
import { applyReviver } from '../doc/applyReviver.js';
|
|
2
|
+
import { NODE_TYPE } from './identity.js';
|
|
3
|
+
import { toJS } from './toJS.js';
|
|
4
|
+
|
|
35
5
|
class NodeBase {
|
|
36
6
|
constructor(type) {
|
|
37
7
|
Object.defineProperty(this, NODE_TYPE, { value: type });
|
|
@@ -43,6 +13,24 @@ class NodeBase {
|
|
|
43
13
|
copy.range = this.range.slice();
|
|
44
14
|
return copy;
|
|
45
15
|
}
|
|
16
|
+
/** A plain JavaScript representation of this node. */
|
|
17
|
+
toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
|
|
18
|
+
const ctx = {
|
|
19
|
+
anchors: new Map(),
|
|
20
|
+
doc,
|
|
21
|
+
keep: true,
|
|
22
|
+
mapAsMap: mapAsMap === true,
|
|
23
|
+
mapKeyWarned: false,
|
|
24
|
+
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100
|
|
25
|
+
};
|
|
26
|
+
const res = toJS(this, '', ctx);
|
|
27
|
+
if (typeof onAnchor === 'function')
|
|
28
|
+
for (const { count, res } of ctx.anchors.values())
|
|
29
|
+
onAnchor(res, count);
|
|
30
|
+
return typeof reviver === 'function'
|
|
31
|
+
? applyReviver(reviver, { '': res }, '', res)
|
|
32
|
+
: res;
|
|
33
|
+
}
|
|
46
34
|
}
|
|
47
35
|
|
|
48
|
-
export {
|
|
36
|
+
export { NodeBase };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createNode } from '../doc/createNode.js';
|
|
2
2
|
import { stringifyPair } from '../stringify/stringifyPair.js';
|
|
3
3
|
import { addPairToJSMap } from './addPairToJSMap.js';
|
|
4
|
-
import { NODE_TYPE, PAIR, isNode } from './
|
|
4
|
+
import { NODE_TYPE, PAIR, isNode } from './identity.js';
|
|
5
5
|
|
|
6
6
|
function createPair(key, value, ctx) {
|
|
7
7
|
const k = createNode(key, undefined, ctx);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SCALAR } from './identity.js';
|
|
2
|
+
import { NodeBase } from './Node.js';
|
|
2
3
|
import { toJS } from './toJS.js';
|
|
3
4
|
|
|
4
5
|
const isScalarValue = (value) => !value || (typeof value !== 'function' && typeof value !== 'object');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { stringifyCollection } from '../stringify/stringifyCollection.js';
|
|
2
2
|
import { addPairToJSMap } from './addPairToJSMap.js';
|
|
3
3
|
import { Collection } from './Collection.js';
|
|
4
|
-
import { isPair, isScalar, MAP } from './
|
|
4
|
+
import { isPair, isScalar, MAP } from './identity.js';
|
|
5
5
|
import { Pair } from './Pair.js';
|
|
6
6
|
import { isScalarValue } from './Scalar.js';
|
|
7
7
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { stringifyCollection } from '../stringify/stringifyCollection.js';
|
|
2
2
|
import { Collection } from './Collection.js';
|
|
3
|
-
import { SEQ, isScalar } from './
|
|
3
|
+
import { SEQ, isScalar } from './identity.js';
|
|
4
4
|
import { isScalarValue } from './Scalar.js';
|
|
5
5
|
import { toJS } from './toJS.js';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { warn } from '../log.js';
|
|
2
2
|
import { createStringifyContext } from '../stringify/stringify.js';
|
|
3
|
-
import { isAlias, isSeq, isScalar, isMap, isNode } from './
|
|
3
|
+
import { isAlias, isSeq, isScalar, isMap, isNode } from './identity.js';
|
|
4
4
|
import { Scalar } from './Scalar.js';
|
|
5
5
|
import { toJS } from './toJS.js';
|
|
6
6
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const ALIAS = Symbol.for('yaml.alias');
|
|
2
|
+
const DOC = Symbol.for('yaml.document');
|
|
3
|
+
const MAP = Symbol.for('yaml.map');
|
|
4
|
+
const PAIR = Symbol.for('yaml.pair');
|
|
5
|
+
const SCALAR = Symbol.for('yaml.scalar');
|
|
6
|
+
const SEQ = Symbol.for('yaml.seq');
|
|
7
|
+
const NODE_TYPE = Symbol.for('yaml.node.type');
|
|
8
|
+
const isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS;
|
|
9
|
+
const isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC;
|
|
10
|
+
const isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP;
|
|
11
|
+
const isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR;
|
|
12
|
+
const isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR;
|
|
13
|
+
const isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ;
|
|
14
|
+
function isCollection(node) {
|
|
15
|
+
if (node && typeof node === 'object')
|
|
16
|
+
switch (node[NODE_TYPE]) {
|
|
17
|
+
case MAP:
|
|
18
|
+
case SEQ:
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
function isNode(node) {
|
|
24
|
+
if (node && typeof node === 'object')
|
|
25
|
+
switch (node[NODE_TYPE]) {
|
|
26
|
+
case ALIAS:
|
|
27
|
+
case MAP:
|
|
28
|
+
case SCALAR:
|
|
29
|
+
case SEQ:
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
|
|
35
|
+
|
|
36
|
+
export { ALIAS, DOC, MAP, NODE_TYPE, PAIR, SCALAR, SEQ, hasAnchor, isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq };
|
|
@@ -12,7 +12,7 @@ import { omap } from './yaml-1.1/omap.js';
|
|
|
12
12
|
import { pairs } from './yaml-1.1/pairs.js';
|
|
13
13
|
import { schema as schema$2 } from './yaml-1.1/schema.js';
|
|
14
14
|
import { set } from './yaml-1.1/set.js';
|
|
15
|
-
import { floatTime, intTime
|
|
15
|
+
import { timestamp, floatTime, intTime } from './yaml-1.1/timestamp.js';
|
|
16
16
|
|
|
17
17
|
const schemas = new Map([
|
|
18
18
|
['core', schema],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isScalar, isPair } from '../../nodes/identity.js';
|
|
2
2
|
import { toJS } from '../../nodes/toJS.js';
|
|
3
|
-
import { isScalar, isPair } from '../../nodes/Node.js';
|
|
4
3
|
import { YAMLMap } from '../../nodes/YAMLMap.js';
|
|
4
|
+
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
|
|
5
5
|
import { resolvePairs, createPairs } from './pairs.js';
|
|
6
6
|
|
|
7
7
|
class YAMLOMap extends YAMLSeq {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isSeq, isPair, isMap } from '../../nodes/
|
|
1
|
+
import { isSeq, isPair, isMap } from '../../nodes/identity.js';
|
|
2
2
|
import { Pair, createPair } from '../../nodes/Pair.js';
|
|
3
3
|
import { Scalar } from '../../nodes/Scalar.js';
|
|
4
4
|
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { anchorIsValid } from '../doc/anchors.js';
|
|
2
|
-
import { isPair, isAlias, isNode, isScalar, isCollection } from '../nodes/
|
|
2
|
+
import { isPair, isAlias, isNode, isScalar, isCollection } from '../nodes/identity.js';
|
|
3
3
|
import { stringifyComment } from './stringifyComment.js';
|
|
4
4
|
import { stringifyString } from './stringifyString.js';
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Collection } from '../nodes/Collection.js';
|
|
2
|
-
import { isNode, isPair } from '../nodes/
|
|
2
|
+
import { isNode, isPair } from '../nodes/identity.js';
|
|
3
3
|
import { stringify } from './stringify.js';
|
|
4
4
|
import { lineComment, indentComment } from './stringifyComment.js';
|
|
5
5
|
|
|
@@ -133,7 +133,7 @@ function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemInden
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
if (comment) {
|
|
136
|
-
str += lineComment(str, commentString(comment)
|
|
136
|
+
str += lineComment(str, indent, commentString(comment));
|
|
137
137
|
if (onComment)
|
|
138
138
|
onComment();
|
|
139
139
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isCollection, isNode, isScalar, isSeq } from '../nodes/
|
|
1
|
+
import { isCollection, isNode, isScalar, isSeq } from '../nodes/identity.js';
|
|
2
2
|
import { Scalar } from '../nodes/Scalar.js';
|
|
3
3
|
import { stringify } from './stringify.js';
|
|
4
4
|
import { lineComment, indentComment } from './stringifyComment.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Scalar } from '../nodes/Scalar.js';
|
|
2
2
|
import { foldFlowLines, FOLD_QUOTED, FOLD_FLOW, FOLD_BLOCK } from './foldFlowLines.js';
|
|
3
3
|
|
|
4
|
-
const getFoldOptions = (ctx) => ({
|
|
5
|
-
indentAtStart: ctx.indentAtStart,
|
|
4
|
+
const getFoldOptions = (ctx, isBlock) => ({
|
|
5
|
+
indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
|
|
6
6
|
lineWidth: ctx.options.lineWidth,
|
|
7
7
|
minContentWidth: ctx.options.minContentWidth
|
|
8
8
|
});
|
|
@@ -115,7 +115,7 @@ function doubleQuotedString(value, ctx) {
|
|
|
115
115
|
str = start ? str + json.slice(start) : json;
|
|
116
116
|
return implicitKey
|
|
117
117
|
? str
|
|
118
|
-
: foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
|
|
118
|
+
: foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx, false));
|
|
119
119
|
}
|
|
120
120
|
function singleQuotedString(value, ctx) {
|
|
121
121
|
if (ctx.options.singleQuote === false ||
|
|
@@ -127,7 +127,7 @@ function singleQuotedString(value, ctx) {
|
|
|
127
127
|
const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
|
|
128
128
|
return ctx.implicitKey
|
|
129
129
|
? res
|
|
130
|
-
: foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
|
|
130
|
+
: foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx, false));
|
|
131
131
|
}
|
|
132
132
|
function quotedString(value, ctx) {
|
|
133
133
|
const { singleQuote } = ctx.options;
|
|
@@ -146,6 +146,15 @@ function quotedString(value, ctx) {
|
|
|
146
146
|
}
|
|
147
147
|
return qs(value, ctx);
|
|
148
148
|
}
|
|
149
|
+
// The negative lookbehind avoids a polynomial search,
|
|
150
|
+
// but isn't supported yet on Safari: https://caniuse.com/js-regexp-lookbehind
|
|
151
|
+
let blockEndNewlines;
|
|
152
|
+
try {
|
|
153
|
+
blockEndNewlines = new RegExp('(^|(?<!\n))\n+(?!\n|$)', 'g');
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
blockEndNewlines = /\n+(?!\n|$)/g;
|
|
157
|
+
}
|
|
149
158
|
function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
|
|
150
159
|
const { blockQuote, commentString, lineWidth } = ctx.options;
|
|
151
160
|
// 1. Block can't end in whitespace unless the last line is non-empty.
|
|
@@ -189,7 +198,7 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
|
|
|
189
198
|
value = value.slice(0, -end.length);
|
|
190
199
|
if (end[end.length - 1] === '\n')
|
|
191
200
|
end = end.slice(0, -1);
|
|
192
|
-
end = end.replace(
|
|
201
|
+
end = end.replace(blockEndNewlines, `$&${indent}`);
|
|
193
202
|
}
|
|
194
203
|
// determine indent indicator from whitespace at value start
|
|
195
204
|
let startWithSpace = false;
|
|
@@ -225,7 +234,7 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
|
|
|
225
234
|
.replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
|
|
226
235
|
// ^ more-ind. ^ empty ^ capture next empty lines only at end of indent
|
|
227
236
|
.replace(/\n+/g, `$&${indent}`);
|
|
228
|
-
const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx));
|
|
237
|
+
const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx, true));
|
|
229
238
|
return `${header}\n${indent}${body}`;
|
|
230
239
|
}
|
|
231
240
|
function plainString(item, ctx, onComment, onChompKeep) {
|
|
@@ -275,7 +284,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
275
284
|
}
|
|
276
285
|
return implicitKey
|
|
277
286
|
? str
|
|
278
|
-
: foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx));
|
|
287
|
+
: foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx, false));
|
|
279
288
|
}
|
|
280
289
|
function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
281
290
|
const { implicitKey, inFlow } = ctx;
|
package/browser/dist/util.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { createNode } from './doc/createNode.js';
|
|
1
2
|
export { debug, warn } from './log.js';
|
|
3
|
+
export { createPair } from './nodes/Pair.js';
|
|
2
4
|
export { findPair } from './nodes/YAMLMap.js';
|
|
3
5
|
export { toJS } from './nodes/toJS.js';
|
|
4
6
|
export { map as mapTag } from './schema/common/map.js';
|
package/browser/dist/visit.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/
|
|
1
|
+
import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/identity.js';
|
|
2
2
|
|
|
3
3
|
const BREAK = Symbol('break visit');
|
|
4
4
|
const SKIP = Symbol('skip children');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParsedNode } from '../nodes/Node.js';
|
|
1
|
+
import type { ParsedNode } from '../nodes/Node.js';
|
|
2
2
|
import type { BlockMap, BlockSequence, FlowCollection, SourceToken } from '../parse/cst.js';
|
|
3
3
|
import type { ComposeContext, ComposeNode } from './compose-node.js';
|
|
4
4
|
import type { ComposeErrorHandler } from './composer.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var identity = require('../nodes/identity.js');
|
|
4
4
|
var Scalar = require('../nodes/Scalar.js');
|
|
5
5
|
var resolveBlockMap = require('./resolve-block-map.js');
|
|
6
6
|
var resolveBlockSeq = require('./resolve-block-seq.js');
|
|
@@ -33,7 +33,7 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
|
|
|
33
33
|
coll.tag = Coll.tagName;
|
|
34
34
|
return coll;
|
|
35
35
|
}
|
|
36
|
-
const expType =
|
|
36
|
+
const expType = identity.isMap(coll) ? 'map' : 'seq';
|
|
37
37
|
let tag = ctx.schema.tags.find(t => t.collection === expType && t.tag === tagName);
|
|
38
38
|
if (!tag) {
|
|
39
39
|
const kt = ctx.schema.knownTags[tagName];
|
|
@@ -48,7 +48,7 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
const res = tag.resolve(coll, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg), ctx.options);
|
|
51
|
-
const node =
|
|
51
|
+
const node = identity.isNode(res)
|
|
52
52
|
? res
|
|
53
53
|
: new Scalar.Scalar(res);
|
|
54
54
|
node.range = coll.range;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Directives } from '../doc/directives.js';
|
|
2
2
|
import { Document } from '../doc/Document.js';
|
|
3
|
+
import type { ParsedNode } from '../nodes/Node.js';
|
|
3
4
|
import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
|
|
4
5
|
import type * as CST from '../parse/cst.js';
|
|
5
6
|
import type { ComposeErrorHandler } from './composer.js';
|
|
6
|
-
export declare function composeDoc(options: ParseOptions & DocumentOptions & SchemaOptions, directives: Directives, { offset, start, value, end }: CST.Document, onError: ComposeErrorHandler): Document.Parsed<
|
|
7
|
+
export declare function composeDoc<Contents extends ParsedNode = ParsedNode, Strict extends boolean = true>(options: ParseOptions & DocumentOptions & SchemaOptions, directives: Directives, { offset, start, value, end }: CST.Document, onError: ComposeErrorHandler): Document.Parsed<Contents, Strict>;
|
|
@@ -28,6 +28,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError)
|
|
|
28
28
|
!props.hasNewline)
|
|
29
29
|
onError(props.end, 'MISSING_CHAR', 'Block collection cannot start on same line with directives-end marker');
|
|
30
30
|
}
|
|
31
|
+
// @ts-expect-error If Contents is set, let's trust the user
|
|
31
32
|
doc.contents = value
|
|
32
33
|
? composeNode.composeNode(ctx, value, props, onError)
|
|
33
34
|
: composeNode.composeEmptyNode(ctx, props.end, start, null, props, onError);
|