yaml 2.0.0-4 → 2.0.0-8
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 +5 -5
- package/browser/dist/compose/compose-collection.js +12 -9
- package/browser/dist/compose/compose-doc.js +23 -6
- package/browser/dist/compose/compose-node.js +27 -17
- package/browser/dist/compose/compose-scalar.js +21 -23
- package/browser/dist/compose/composer.js +108 -78
- package/browser/dist/compose/resolve-block-map.js +41 -29
- package/browser/dist/compose/resolve-block-scalar.js +14 -17
- package/browser/dist/compose/resolve-block-seq.js +21 -17
- package/browser/dist/compose/resolve-end.js +7 -8
- package/browser/dist/compose/resolve-flow-collection.js +158 -199
- package/browser/dist/compose/resolve-flow-scalar.js +62 -26
- package/browser/dist/compose/resolve-props.js +72 -37
- package/browser/dist/compose/util-contains-newline.js +15 -12
- package/browser/dist/compose/util-map-includes.js +17 -0
- package/browser/dist/doc/Document.js +74 -99
- package/browser/dist/doc/anchors.js +72 -0
- package/browser/dist/doc/createNode.js +35 -19
- package/browser/dist/doc/directives.js +5 -0
- package/browser/dist/errors.js +16 -12
- package/browser/dist/index.js +3 -3
- package/browser/dist/nodes/Alias.js +51 -28
- package/browser/dist/nodes/Collection.js +23 -92
- package/browser/dist/nodes/Node.js +9 -1
- package/browser/dist/nodes/Pair.js +16 -231
- package/browser/dist/nodes/YAMLMap.js +8 -4
- package/browser/dist/nodes/YAMLSeq.js +7 -4
- package/browser/dist/nodes/addPairToJSMap.js +103 -0
- package/browser/dist/nodes/toJS.js +12 -10
- package/browser/dist/options.js +1 -2
- package/browser/dist/parse/cst-scalar.js +219 -0
- package/browser/dist/parse/cst-stringify.js +61 -0
- package/browser/dist/parse/cst-visit.js +97 -0
- package/{dist/parse/tokens.js → browser/dist/parse/cst.js} +12 -7
- package/browser/dist/parse/lexer.js +149 -125
- package/browser/dist/parse/parser.js +272 -196
- package/browser/dist/public-api.js +11 -14
- package/browser/dist/schema/Schema.js +28 -0
- package/browser/dist/{tags/failsafe → schema/common}/map.js +0 -0
- package/browser/dist/schema/common/null.js +13 -0
- package/browser/dist/{tags/failsafe → schema/common}/seq.js +1 -1
- package/browser/dist/{tags/failsafe → schema/common}/string.js +0 -0
- package/browser/dist/schema/core/bool.js +19 -0
- package/browser/dist/schema/core/float.js +40 -0
- package/browser/dist/schema/core/int.js +38 -0
- package/browser/dist/schema/core/schema.js +23 -0
- package/browser/dist/{tags/json.js → schema/json/schema.js} +5 -6
- package/browser/dist/schema/tags.js +79 -0
- package/browser/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
- package/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/browser/dist/schema/yaml-1.1/float.js +43 -0
- package/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/browser/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
- package/browser/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
- package/browser/dist/schema/yaml-1.1/schema.js +37 -0
- package/browser/dist/{tags → schema}/yaml-1.1/set.js +0 -0
- package/browser/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
- package/browser/dist/stringify/stringify.js +8 -6
- package/browser/dist/stringify/stringifyCollection.js +122 -0
- package/browser/dist/stringify/stringifyComment.js +14 -0
- package/browser/dist/stringify/stringifyDocument.js +64 -0
- package/browser/dist/stringify/stringifyPair.js +111 -0
- package/browser/dist/stringify/stringifyString.js +53 -52
- package/browser/dist/visit.js +20 -1
- package/dist/compose/compose-collection.d.ts +4 -4
- package/dist/compose/compose-collection.js +12 -9
- package/dist/compose/compose-doc.d.ts +4 -3
- package/dist/compose/compose-doc.js +23 -6
- package/dist/compose/compose-node.d.ts +15 -7
- package/dist/compose/compose-node.js +27 -17
- package/dist/compose/compose-scalar.d.ts +4 -3
- package/dist/compose/compose-scalar.js +20 -22
- package/dist/compose/composer.d.ts +28 -23
- package/dist/compose/composer.js +109 -79
- package/dist/compose/resolve-block-map.d.ts +5 -4
- package/dist/compose/resolve-block-map.js +41 -29
- package/dist/compose/resolve-block-scalar.d.ts +5 -3
- package/dist/compose/resolve-block-scalar.js +14 -17
- package/dist/compose/resolve-block-seq.d.ts +4 -4
- package/dist/compose/resolve-block-seq.js +21 -17
- package/dist/compose/resolve-end.d.ts +3 -2
- package/dist/compose/resolve-end.js +7 -8
- package/dist/compose/resolve-flow-collection.d.ts +4 -5
- package/dist/compose/resolve-flow-collection.js +157 -198
- package/dist/compose/resolve-flow-scalar.d.ts +5 -3
- package/dist/compose/resolve-flow-scalar.js +62 -26
- package/dist/compose/resolve-props.d.ts +16 -10
- package/dist/compose/resolve-props.js +72 -37
- package/dist/compose/util-contains-newline.d.ts +1 -1
- package/dist/compose/util-contains-newline.js +15 -12
- package/dist/compose/util-empty-scalar-position.d.ts +1 -1
- package/dist/compose/util-map-includes.d.ts +4 -0
- package/dist/compose/util-map-includes.js +19 -0
- package/dist/doc/Document.d.ts +35 -15
- package/dist/doc/Document.js +72 -97
- package/dist/doc/anchors.d.ts +24 -0
- package/dist/doc/anchors.js +77 -0
- package/dist/doc/createNode.d.ts +10 -11
- package/dist/doc/createNode.js +34 -18
- package/dist/doc/directives.d.ts +1 -0
- package/dist/doc/directives.js +5 -0
- package/dist/errors.d.ts +11 -8
- package/dist/errors.js +16 -12
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -3
- package/dist/nodes/Alias.d.ts +19 -9
- package/dist/nodes/Alias.js +51 -28
- package/dist/nodes/Collection.d.ts +9 -17
- package/dist/nodes/Collection.js +22 -91
- package/dist/nodes/Node.d.ts +10 -4
- package/dist/nodes/Node.js +9 -0
- package/dist/nodes/Pair.d.ts +10 -13
- package/dist/nodes/Pair.js +15 -230
- package/dist/nodes/Scalar.d.ts +6 -3
- package/dist/nodes/YAMLMap.d.ts +3 -3
- package/dist/nodes/YAMLMap.js +8 -4
- package/dist/nodes/YAMLSeq.d.ts +3 -3
- package/dist/nodes/YAMLSeq.js +7 -4
- package/dist/nodes/addPairToJSMap.d.ts +3 -0
- package/dist/nodes/addPairToJSMap.js +105 -0
- package/dist/nodes/toJS.d.ts +4 -5
- package/dist/nodes/toJS.js +12 -10
- package/dist/options.d.ts +41 -25
- package/dist/options.js +1 -2
- package/dist/parse/cst-scalar.d.ts +58 -0
- package/dist/parse/cst-scalar.js +223 -0
- package/dist/parse/cst-stringify.d.ts +8 -0
- package/dist/parse/cst-stringify.js +63 -0
- package/dist/parse/cst-visit.d.ts +39 -0
- package/dist/parse/cst-visit.js +99 -0
- package/dist/parse/{tokens.d.ts → cst.d.ts} +23 -7
- package/{browser/dist/parse/tokens.js → dist/parse/cst.js} +27 -1
- package/dist/parse/lexer.d.ts +7 -14
- package/dist/parse/lexer.js +150 -126
- package/dist/parse/parser.d.ts +31 -24
- package/dist/parse/parser.js +274 -198
- package/dist/public-api.d.ts +7 -7
- package/dist/public-api.js +11 -14
- package/dist/{doc → schema}/Schema.d.ts +6 -3
- package/dist/schema/Schema.js +30 -0
- package/dist/{tags/failsafe → schema/common}/map.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/map.js +0 -0
- package/dist/schema/common/null.d.ts +4 -0
- package/dist/schema/common/null.js +15 -0
- package/dist/{tags/failsafe → schema/common}/seq.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/seq.js +1 -1
- package/dist/{tags/failsafe → schema/common}/string.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/string.js +0 -0
- package/dist/schema/core/bool.d.ts +4 -0
- package/dist/schema/core/bool.js +21 -0
- package/dist/schema/core/float.d.ts +4 -0
- package/dist/schema/core/float.js +44 -0
- package/dist/schema/core/int.d.ts +4 -0
- package/dist/schema/core/int.js +42 -0
- package/dist/schema/core/schema.d.ts +1 -0
- package/dist/schema/core/schema.js +25 -0
- package/dist/schema/json/schema.d.ts +2 -0
- package/dist/{tags/json.js → schema/json/schema.js} +5 -6
- package/dist/schema/tags.d.ts +41 -0
- package/dist/schema/tags.js +82 -0
- package/dist/{tags → schema}/types.d.ts +3 -7
- package/dist/{tags → schema}/yaml-1.1/binary.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
- package/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/dist/schema/yaml-1.1/bool.js +29 -0
- package/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/dist/schema/yaml-1.1/float.js +47 -0
- package/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/dist/schema/yaml-1.1/int.js +76 -0
- package/dist/{tags → schema}/yaml-1.1/omap.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
- package/dist/{tags → schema}/yaml-1.1/pairs.d.ts +3 -2
- package/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
- package/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/dist/schema/yaml-1.1/schema.js +39 -0
- package/dist/{tags → schema}/yaml-1.1/set.d.ts +1 -1
- package/dist/{tags → schema}/yaml-1.1/set.js +0 -0
- package/dist/{tags → schema}/yaml-1.1/timestamp.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
- package/dist/stringify/stringify.d.ts +1 -2
- package/dist/stringify/stringify.js +8 -6
- package/dist/stringify/stringifyCollection.d.ts +21 -0
- package/dist/stringify/stringifyCollection.js +124 -0
- package/dist/stringify/stringifyComment.d.ts +2 -0
- package/dist/stringify/stringifyComment.js +17 -0
- package/dist/stringify/stringifyDocument.d.ts +3 -0
- package/dist/stringify/stringifyDocument.js +66 -0
- package/dist/stringify/stringifyPair.d.ts +3 -0
- package/dist/stringify/stringifyPair.js +113 -0
- package/dist/stringify/stringifyString.js +53 -52
- package/dist/test-events.d.ts +1 -2
- package/dist/test-events.js +25 -12
- package/dist/util.d.ts +1 -1
- package/dist/visit.d.ts +10 -1
- package/dist/visit.js +20 -1
- package/package.json +9 -8
- package/browser/dist/doc/Anchors.js +0 -102
- package/browser/dist/doc/Schema.js +0 -27
- package/browser/dist/doc/getSchemaTags.js +0 -30
- package/browser/dist/stringify/addComment.js +0 -17
- package/browser/dist/tags/core.js +0 -109
- package/browser/dist/tags/failsafe/index.js +0 -7
- package/browser/dist/tags/index.js +0 -34
- package/browser/dist/tags/yaml-1.1/index.js +0 -152
- package/dist/doc/Anchors.d.ts +0 -36
- package/dist/doc/Anchors.js +0 -104
- package/dist/doc/Schema.js +0 -29
- package/dist/doc/getSchemaTags.d.ts +0 -3
- package/dist/doc/getSchemaTags.js +0 -32
- package/dist/stringify/addComment.d.ts +0 -2
- package/dist/stringify/addComment.js +0 -20
- package/dist/tags/core.d.ts +0 -14
- package/dist/tags/core.js +0 -119
- package/dist/tags/failsafe/index.d.ts +0 -1
- package/dist/tags/failsafe/index.js +0 -9
- package/dist/tags/index.d.ts +0 -31
- package/dist/tags/index.js +0 -37
- package/dist/tags/json.d.ts +0 -2
- package/dist/tags/yaml-1.1/index.d.ts +0 -2
- package/dist/tags/yaml-1.1/index.js +0 -154
package/dist/public-api.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Composer } from './compose/composer.js';
|
|
|
2
2
|
import type { Reviver } from './doc/applyReviver.js';
|
|
3
3
|
import { Document, Replacer } from './doc/Document.js';
|
|
4
4
|
import type { ParsedNode } from './nodes/Node.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options.js';
|
|
6
6
|
export interface EmptyStream extends Array<Document.Parsed>, ReturnType<Composer['streamInfo']> {
|
|
7
7
|
empty: true;
|
|
8
8
|
}
|
|
@@ -15,9 +15,9 @@ export interface EmptyStream extends Array<Document.Parsed>, ReturnType<Composer
|
|
|
15
15
|
* EmptyStream and contain additional stream information. In
|
|
16
16
|
* TypeScript, you should use `'empty' in docs` as a type guard for it.
|
|
17
17
|
*/
|
|
18
|
-
export declare function parseAllDocuments<T extends ParsedNode = ParsedNode>(source: string, options?:
|
|
18
|
+
export declare function parseAllDocuments<T extends ParsedNode = ParsedNode>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<T>[] | EmptyStream;
|
|
19
19
|
/** Parse an input string into a single YAML.Document */
|
|
20
|
-
export declare function parseDocument<T extends ParsedNode = ParsedNode>(source: string, options?:
|
|
20
|
+
export declare function parseDocument<T extends ParsedNode = ParsedNode>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<T>;
|
|
21
21
|
/**
|
|
22
22
|
* Parse an input string into JavaScript.
|
|
23
23
|
*
|
|
@@ -31,13 +31,13 @@ export declare function parseDocument<T extends ParsedNode = ParsedNode>(source:
|
|
|
31
31
|
* document, so Maps become objects, Sequences arrays, and scalars result in
|
|
32
32
|
* nulls, booleans, numbers and strings.
|
|
33
33
|
*/
|
|
34
|
-
export declare function parse(src: string, options?:
|
|
35
|
-
export declare function parse(src: string, reviver: Reviver, options?:
|
|
34
|
+
export declare function parse(src: string, options?: ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions): any;
|
|
35
|
+
export declare function parse(src: string, reviver: Reviver, options?: ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions): any;
|
|
36
36
|
/**
|
|
37
37
|
* Stringify a value as a YAML document.
|
|
38
38
|
*
|
|
39
39
|
* @param replacer - A replacer array or function, as in `JSON.stringify()`
|
|
40
40
|
* @returns Will always include `\n` as the last character, as is expected of YAML documents.
|
|
41
41
|
*/
|
|
42
|
-
export declare function stringify(value: any, options?:
|
|
43
|
-
export declare function stringify(value: any, replacer?: Replacer | null, options?: string | number | (
|
|
42
|
+
export declare function stringify(value: any, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions): string;
|
|
43
|
+
export declare function stringify(value: any, replacer?: Replacer | null, options?: string | number | (DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions)): string;
|
package/dist/public-api.js
CHANGED
|
@@ -23,13 +23,11 @@ function parseOptions(options) {
|
|
|
23
23
|
* EmptyStream and contain additional stream information. In
|
|
24
24
|
* TypeScript, you should use `'empty' in docs` as a type guard for it.
|
|
25
25
|
*/
|
|
26
|
-
function parseAllDocuments(source, options) {
|
|
26
|
+
function parseAllDocuments(source, options = {}) {
|
|
27
27
|
const { lineCounter, prettyErrors } = parseOptions(options);
|
|
28
|
-
const
|
|
29
|
-
const composer$1 = new composer.Composer(
|
|
30
|
-
const
|
|
31
|
-
parser$1.parse(source);
|
|
32
|
-
composer$1.end();
|
|
28
|
+
const parser$1 = new parser.Parser(lineCounter === null || lineCounter === void 0 ? void 0 : lineCounter.addNewLine);
|
|
29
|
+
const composer$1 = new composer.Composer(options);
|
|
30
|
+
const docs = Array.from(composer$1.compose(parser$1.parse(source)));
|
|
33
31
|
if (prettyErrors && lineCounter)
|
|
34
32
|
for (const doc of docs) {
|
|
35
33
|
doc.errors.forEach(errors.prettifyError(source, lineCounter));
|
|
@@ -40,21 +38,20 @@ function parseAllDocuments(source, options) {
|
|
|
40
38
|
return Object.assign([], { empty: true }, composer$1.streamInfo());
|
|
41
39
|
}
|
|
42
40
|
/** Parse an input string into a single YAML.Document */
|
|
43
|
-
function parseDocument(source, options) {
|
|
41
|
+
function parseDocument(source, options = {}) {
|
|
44
42
|
const { lineCounter, prettyErrors } = parseOptions(options);
|
|
43
|
+
const parser$1 = new parser.Parser(lineCounter === null || lineCounter === void 0 ? void 0 : lineCounter.addNewLine);
|
|
44
|
+
const composer$1 = new composer.Composer(options);
|
|
45
45
|
// `doc` is always set by compose.end(true) at the very latest
|
|
46
46
|
let doc = null;
|
|
47
|
-
const composer$1
|
|
47
|
+
for (const _doc of composer$1.compose(parser$1.parse(source), true, source.length)) {
|
|
48
48
|
if (!doc)
|
|
49
49
|
doc = _doc;
|
|
50
50
|
else if (doc.options.logLevel !== 'silent') {
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
doc.errors.push(new errors.YAMLParseError(_doc.range.slice(0, 2), 'MULTIPLE_DOCS', 'Source contains multiple documents; please use YAML.parseAllDocuments()'));
|
|
52
|
+
break;
|
|
53
53
|
}
|
|
54
|
-
}
|
|
55
|
-
const parser$1 = new parser.Parser(composer$1.next, lineCounter === null || lineCounter === void 0 ? void 0 : lineCounter.addNewLine);
|
|
56
|
-
parser$1.parse(source);
|
|
57
|
-
composer$1.end(true, source.length);
|
|
54
|
+
}
|
|
58
55
|
if (prettyErrors && lineCounter) {
|
|
59
56
|
doc.errors.forEach(errors.prettifyError(source, lineCounter));
|
|
60
57
|
doc.warnings.forEach(errors.prettifyError(source, lineCounter));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { MAP, SCALAR, SEQ } from '../nodes/Node.js';
|
|
1
2
|
import type { Pair } from '../nodes/Pair.js';
|
|
2
3
|
import type { SchemaOptions } from '../options.js';
|
|
3
|
-
import type { CollectionTag, ScalarTag } from '
|
|
4
|
+
import type { CollectionTag, ScalarTag } from './types.js';
|
|
4
5
|
export declare type SchemaName = 'core' | 'failsafe' | 'json' | 'yaml-1.1';
|
|
5
6
|
export declare class Schema {
|
|
6
7
|
knownTags: Record<string, CollectionTag | ScalarTag>;
|
|
@@ -8,7 +9,9 @@ export declare class Schema {
|
|
|
8
9
|
name: SchemaName;
|
|
9
10
|
sortMapEntries: ((a: Pair, b: Pair) => number) | null;
|
|
10
11
|
tags: Array<CollectionTag | ScalarTag>;
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
[MAP]: CollectionTag;
|
|
13
|
+
[SCALAR]: ScalarTag;
|
|
14
|
+
[SEQ]: CollectionTag;
|
|
13
15
|
constructor({ customTags, merge, resolveKnownTags, schema, sortMapEntries }: SchemaOptions);
|
|
16
|
+
clone(): Schema;
|
|
14
17
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Node = require('../nodes/Node.js');
|
|
4
|
+
var map = require('./common/map.js');
|
|
5
|
+
var seq = require('./common/seq.js');
|
|
6
|
+
var string = require('./common/string.js');
|
|
7
|
+
var tags = require('./tags.js');
|
|
8
|
+
|
|
9
|
+
const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
|
|
10
|
+
class Schema {
|
|
11
|
+
constructor({ customTags, merge, resolveKnownTags, schema, sortMapEntries }) {
|
|
12
|
+
this.merge = !!merge;
|
|
13
|
+
this.name = schema || 'core';
|
|
14
|
+
this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
|
|
15
|
+
this.tags = tags.getTags(customTags, this.name);
|
|
16
|
+
Object.defineProperty(this, Node.MAP, { value: map.map });
|
|
17
|
+
Object.defineProperty(this, Node.SCALAR, { value: string.string });
|
|
18
|
+
Object.defineProperty(this, Node.SEQ, { value: seq.seq });
|
|
19
|
+
// Used by createMap()
|
|
20
|
+
this.sortMapEntries =
|
|
21
|
+
sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null;
|
|
22
|
+
}
|
|
23
|
+
clone() {
|
|
24
|
+
const copy = Object.create(Schema.prototype, Object.getOwnPropertyDescriptors(this));
|
|
25
|
+
copy.tags = this.tags.slice();
|
|
26
|
+
return copy;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.Schema = Schema;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Scalar = require('../../nodes/Scalar.js');
|
|
4
|
+
|
|
5
|
+
const nullTag = {
|
|
6
|
+
identify: value => value == null,
|
|
7
|
+
createNode: () => new Scalar.Scalar(null),
|
|
8
|
+
default: true,
|
|
9
|
+
tag: 'tag:yaml.org,2002:null',
|
|
10
|
+
test: /^(?:~|[Nn]ull|NULL)?$/,
|
|
11
|
+
resolve: () => new Scalar.Scalar(null),
|
|
12
|
+
stringify: ({ source }, ctx) => source && nullTag.test.test(source) ? source : ctx.options.nullStr
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
exports.nullTag = nullTag;
|
|
File without changes
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var createNode = require('../../doc/createNode.js');
|
|
3
4
|
var Node = require('../../nodes/Node.js');
|
|
4
5
|
var YAMLSeq = require('../../nodes/YAMLSeq.js');
|
|
5
|
-
var createNode = require('../../doc/createNode.js');
|
|
6
6
|
|
|
7
7
|
function createSeq(schema, obj, ctx) {
|
|
8
8
|
const { replacer } = ctx;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Scalar = require('../../nodes/Scalar.js');
|
|
4
|
+
|
|
5
|
+
const boolTag = {
|
|
6
|
+
identify: value => typeof value === 'boolean',
|
|
7
|
+
default: true,
|
|
8
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
9
|
+
test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
|
|
10
|
+
resolve: str => new Scalar.Scalar(str[0] === 't' || str[0] === 'T'),
|
|
11
|
+
stringify({ source, value }, ctx) {
|
|
12
|
+
if (source && boolTag.test.test(source)) {
|
|
13
|
+
const sv = source[0] === 't' || source[0] === 'T';
|
|
14
|
+
if (value === sv)
|
|
15
|
+
return source;
|
|
16
|
+
}
|
|
17
|
+
return value ? ctx.options.trueStr : ctx.options.falseStr;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.boolTag = boolTag;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Scalar = require('../../nodes/Scalar.js');
|
|
4
|
+
var stringifyNumber = require('../../stringify/stringifyNumber.js');
|
|
5
|
+
|
|
6
|
+
const floatNaN = {
|
|
7
|
+
identify: value => typeof value === 'number',
|
|
8
|
+
default: true,
|
|
9
|
+
tag: 'tag:yaml.org,2002:float',
|
|
10
|
+
test: /^(?:[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN))$/,
|
|
11
|
+
resolve: str => str.slice(-3).toLowerCase() === 'nan'
|
|
12
|
+
? NaN
|
|
13
|
+
: str[0] === '-'
|
|
14
|
+
? Number.NEGATIVE_INFINITY
|
|
15
|
+
: Number.POSITIVE_INFINITY,
|
|
16
|
+
stringify: stringifyNumber.stringifyNumber
|
|
17
|
+
};
|
|
18
|
+
const floatExp = {
|
|
19
|
+
identify: value => typeof value === 'number',
|
|
20
|
+
default: true,
|
|
21
|
+
tag: 'tag:yaml.org,2002:float',
|
|
22
|
+
format: 'EXP',
|
|
23
|
+
test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
|
|
24
|
+
resolve: str => parseFloat(str),
|
|
25
|
+
stringify: ({ value }) => Number(value).toExponential()
|
|
26
|
+
};
|
|
27
|
+
const float = {
|
|
28
|
+
identify: value => typeof value === 'number',
|
|
29
|
+
default: true,
|
|
30
|
+
tag: 'tag:yaml.org,2002:float',
|
|
31
|
+
test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
|
|
32
|
+
resolve(str) {
|
|
33
|
+
const node = new Scalar.Scalar(parseFloat(str));
|
|
34
|
+
const dot = str.indexOf('.');
|
|
35
|
+
if (dot !== -1 && str[str.length - 1] === '0')
|
|
36
|
+
node.minFractionDigits = str.length - dot - 1;
|
|
37
|
+
return node;
|
|
38
|
+
},
|
|
39
|
+
stringify: stringifyNumber.stringifyNumber
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
exports.float = float;
|
|
43
|
+
exports.floatExp = floatExp;
|
|
44
|
+
exports.floatNaN = floatNaN;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stringifyNumber = require('../../stringify/stringifyNumber.js');
|
|
4
|
+
|
|
5
|
+
const intIdentify = (value) => typeof value === 'bigint' || Number.isInteger(value);
|
|
6
|
+
const intResolve = (str, offset, radix, { intAsBigInt }) => (intAsBigInt ? BigInt(str) : parseInt(str.substring(offset), radix));
|
|
7
|
+
function intStringify(node, radix, prefix) {
|
|
8
|
+
const { value } = node;
|
|
9
|
+
if (intIdentify(value) && value >= 0)
|
|
10
|
+
return prefix + value.toString(radix);
|
|
11
|
+
return stringifyNumber.stringifyNumber(node);
|
|
12
|
+
}
|
|
13
|
+
const intOct = {
|
|
14
|
+
identify: value => intIdentify(value) && value >= 0,
|
|
15
|
+
default: true,
|
|
16
|
+
tag: 'tag:yaml.org,2002:int',
|
|
17
|
+
format: 'OCT',
|
|
18
|
+
test: /^0o[0-7]+$/,
|
|
19
|
+
resolve: (str, _onError, opt) => intResolve(str, 2, 8, opt),
|
|
20
|
+
stringify: node => intStringify(node, 8, '0o')
|
|
21
|
+
};
|
|
22
|
+
const int = {
|
|
23
|
+
identify: intIdentify,
|
|
24
|
+
default: true,
|
|
25
|
+
tag: 'tag:yaml.org,2002:int',
|
|
26
|
+
test: /^[-+]?[0-9]+$/,
|
|
27
|
+
resolve: (str, _onError, opt) => intResolve(str, 0, 10, opt),
|
|
28
|
+
stringify: stringifyNumber.stringifyNumber
|
|
29
|
+
};
|
|
30
|
+
const intHex = {
|
|
31
|
+
identify: value => intIdentify(value) && value >= 0,
|
|
32
|
+
default: true,
|
|
33
|
+
tag: 'tag:yaml.org,2002:int',
|
|
34
|
+
format: 'HEX',
|
|
35
|
+
test: /^0x[0-9a-fA-F]+$/,
|
|
36
|
+
resolve: (str, _onError, opt) => intResolve(str, 2, 16, opt),
|
|
37
|
+
stringify: node => intStringify(node, 16, '0x')
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.int = int;
|
|
41
|
+
exports.intHex = intHex;
|
|
42
|
+
exports.intOct = intOct;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const schema: (import("../types.js").ScalarTag | import("../types.js").CollectionTag)[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var map = require('../common/map.js');
|
|
4
|
+
var _null = require('../common/null.js');
|
|
5
|
+
var seq = require('../common/seq.js');
|
|
6
|
+
var string = require('../common/string.js');
|
|
7
|
+
var bool = require('./bool.js');
|
|
8
|
+
var float = require('./float.js');
|
|
9
|
+
var int = require('./int.js');
|
|
10
|
+
|
|
11
|
+
const schema = [
|
|
12
|
+
map.map,
|
|
13
|
+
seq.seq,
|
|
14
|
+
string.string,
|
|
15
|
+
_null.nullTag,
|
|
16
|
+
bool.boolTag,
|
|
17
|
+
int.intOct,
|
|
18
|
+
int.int,
|
|
19
|
+
int.intHex,
|
|
20
|
+
float.floatNaN,
|
|
21
|
+
float.floatExp,
|
|
22
|
+
float.float
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
exports.schema = schema;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var Scalar = require('
|
|
4
|
-
var map = require('
|
|
5
|
-
var seq = require('
|
|
3
|
+
var Scalar = require('../../nodes/Scalar.js');
|
|
4
|
+
var map = require('../common/map.js');
|
|
5
|
+
var seq = require('../common/seq.js');
|
|
6
6
|
|
|
7
|
-
/* global BigInt */
|
|
8
7
|
function intIdentify(value) {
|
|
9
8
|
return typeof value === 'bigint' || Number.isInteger(value);
|
|
10
9
|
}
|
|
@@ -60,6 +59,6 @@ const jsonError = {
|
|
|
60
59
|
return str;
|
|
61
60
|
}
|
|
62
61
|
};
|
|
63
|
-
const
|
|
62
|
+
const schema = [map.map, seq.seq].concat(jsonScalars, jsonError);
|
|
64
63
|
|
|
65
|
-
exports.
|
|
64
|
+
exports.schema = schema;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { SchemaOptions } from '../options.js';
|
|
2
|
+
import type { SchemaName } from './Schema.js';
|
|
3
|
+
import type { CollectionTag, ScalarTag } from './types.js';
|
|
4
|
+
declare const tagsByName: {
|
|
5
|
+
binary: ScalarTag;
|
|
6
|
+
bool: ScalarTag & {
|
|
7
|
+
test: RegExp;
|
|
8
|
+
};
|
|
9
|
+
float: ScalarTag;
|
|
10
|
+
floatExp: ScalarTag;
|
|
11
|
+
floatNaN: ScalarTag;
|
|
12
|
+
floatTime: ScalarTag;
|
|
13
|
+
int: ScalarTag;
|
|
14
|
+
intHex: ScalarTag;
|
|
15
|
+
intOct: ScalarTag;
|
|
16
|
+
intTime: ScalarTag;
|
|
17
|
+
map: CollectionTag;
|
|
18
|
+
null: ScalarTag & {
|
|
19
|
+
test: RegExp;
|
|
20
|
+
};
|
|
21
|
+
omap: CollectionTag;
|
|
22
|
+
pairs: CollectionTag;
|
|
23
|
+
seq: CollectionTag;
|
|
24
|
+
set: CollectionTag;
|
|
25
|
+
timestamp: ScalarTag & {
|
|
26
|
+
test: RegExp;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export declare type TagId = keyof typeof tagsByName;
|
|
30
|
+
export declare type Tags = Array<ScalarTag | CollectionTag | TagId>;
|
|
31
|
+
export declare const coreKnownTags: {
|
|
32
|
+
'tag:yaml.org,2002:binary': ScalarTag;
|
|
33
|
+
'tag:yaml.org,2002:omap': CollectionTag;
|
|
34
|
+
'tag:yaml.org,2002:pairs': CollectionTag;
|
|
35
|
+
'tag:yaml.org,2002:set': CollectionTag;
|
|
36
|
+
'tag:yaml.org,2002:timestamp': ScalarTag & {
|
|
37
|
+
test: RegExp;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: SchemaName): (ScalarTag | CollectionTag)[];
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var map = require('./common/map.js');
|
|
4
|
+
var _null = require('./common/null.js');
|
|
5
|
+
var seq = require('./common/seq.js');
|
|
6
|
+
var string = require('./common/string.js');
|
|
7
|
+
var bool = require('./core/bool.js');
|
|
8
|
+
var float = require('./core/float.js');
|
|
9
|
+
var int = require('./core/int.js');
|
|
10
|
+
var schema = require('./core/schema.js');
|
|
11
|
+
var schema$1 = require('./json/schema.js');
|
|
12
|
+
var binary = require('./yaml-1.1/binary.js');
|
|
13
|
+
var omap = require('./yaml-1.1/omap.js');
|
|
14
|
+
var pairs = require('./yaml-1.1/pairs.js');
|
|
15
|
+
var schema$2 = require('./yaml-1.1/schema.js');
|
|
16
|
+
var set = require('./yaml-1.1/set.js');
|
|
17
|
+
var timestamp = require('./yaml-1.1/timestamp.js');
|
|
18
|
+
|
|
19
|
+
const schemas = {
|
|
20
|
+
core: schema.schema,
|
|
21
|
+
failsafe: [map.map, seq.seq, string.string],
|
|
22
|
+
json: schema$1.schema,
|
|
23
|
+
yaml11: schema$2.schema,
|
|
24
|
+
'yaml-1.1': schema$2.schema
|
|
25
|
+
};
|
|
26
|
+
const tagsByName = {
|
|
27
|
+
binary: binary.binary,
|
|
28
|
+
bool: bool.boolTag,
|
|
29
|
+
float: float.float,
|
|
30
|
+
floatExp: float.floatExp,
|
|
31
|
+
floatNaN: float.floatNaN,
|
|
32
|
+
floatTime: timestamp.floatTime,
|
|
33
|
+
int: int.int,
|
|
34
|
+
intHex: int.intHex,
|
|
35
|
+
intOct: int.intOct,
|
|
36
|
+
intTime: timestamp.intTime,
|
|
37
|
+
map: map.map,
|
|
38
|
+
null: _null.nullTag,
|
|
39
|
+
omap: omap.omap,
|
|
40
|
+
pairs: pairs.pairs,
|
|
41
|
+
seq: seq.seq,
|
|
42
|
+
set: set.set,
|
|
43
|
+
timestamp: timestamp.timestamp
|
|
44
|
+
};
|
|
45
|
+
const coreKnownTags = {
|
|
46
|
+
'tag:yaml.org,2002:binary': binary.binary,
|
|
47
|
+
'tag:yaml.org,2002:omap': omap.omap,
|
|
48
|
+
'tag:yaml.org,2002:pairs': pairs.pairs,
|
|
49
|
+
'tag:yaml.org,2002:set': set.set,
|
|
50
|
+
'tag:yaml.org,2002:timestamp': timestamp.timestamp
|
|
51
|
+
};
|
|
52
|
+
function getTags(customTags, schemaName) {
|
|
53
|
+
let tags = schemas[schemaName];
|
|
54
|
+
if (!tags) {
|
|
55
|
+
const keys = Object.keys(schemas)
|
|
56
|
+
.filter(key => key !== 'yaml11')
|
|
57
|
+
.map(key => JSON.stringify(key))
|
|
58
|
+
.join(', ');
|
|
59
|
+
throw new Error(`Unknown schema "${schemaName}"; use one of ${keys}`);
|
|
60
|
+
}
|
|
61
|
+
if (Array.isArray(customTags)) {
|
|
62
|
+
for (const tag of customTags)
|
|
63
|
+
tags = tags.concat(tag);
|
|
64
|
+
}
|
|
65
|
+
else if (typeof customTags === 'function') {
|
|
66
|
+
tags = customTags(tags.slice());
|
|
67
|
+
}
|
|
68
|
+
return tags.map(tag => {
|
|
69
|
+
if (typeof tag !== 'string')
|
|
70
|
+
return tag;
|
|
71
|
+
const tagObj = tagsByName[tag];
|
|
72
|
+
if (tagObj)
|
|
73
|
+
return tagObj;
|
|
74
|
+
const keys = Object.keys(tagsByName)
|
|
75
|
+
.map(key => JSON.stringify(key))
|
|
76
|
+
.join(', ');
|
|
77
|
+
throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
exports.coreKnownTags = coreKnownTags;
|
|
82
|
+
exports.getTags = getTags;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { CreateNodeContext } from '../doc/createNode.js';
|
|
2
|
-
import type { Schema } from '
|
|
2
|
+
import type { Schema } from './Schema.js';
|
|
3
3
|
import type { Node } from '../nodes/Node.js';
|
|
4
4
|
import type { Scalar } from '../nodes/Scalar.js';
|
|
5
5
|
import type { YAMLMap } from '../nodes/YAMLMap.js';
|
|
6
6
|
import type { YAMLSeq } from '../nodes/YAMLSeq.js';
|
|
7
|
-
import { ParseOptions } from '../options.js';
|
|
7
|
+
import type { ParseOptions } from '../options.js';
|
|
8
8
|
import type { StringifyContext } from '../stringify/stringify.js';
|
|
9
|
-
export declare type SchemaId = 'core' | 'failsafe' | 'json' | 'yaml11';
|
|
10
|
-
export declare type TagId = 'binary' | 'bool' | 'float' | 'floatExp' | 'floatNaN' | 'floatTime' | 'int' | 'intHex' | 'intOct' | 'intTime' | 'null' | 'omap' | 'pairs' | 'set' | 'timestamp';
|
|
11
9
|
interface TagBase {
|
|
12
10
|
/**
|
|
13
11
|
* An optional factory function, used e.g. by collections when wrapping JS objects as AST nodes.
|
|
@@ -79,8 +77,6 @@ export interface CollectionTag extends TagBase {
|
|
|
79
77
|
* Turns a value into an AST node.
|
|
80
78
|
* If returning a non-`Node` value, the output will be wrapped as a `Scalar`.
|
|
81
79
|
*/
|
|
82
|
-
resolve(value: YAMLMap | YAMLSeq, onError: (message: string) => void, options: ParseOptions): unknown;
|
|
80
|
+
resolve(value: YAMLMap.Parsed | YAMLSeq.Parsed, onError: (message: string) => void, options: ParseOptions): unknown;
|
|
83
81
|
}
|
|
84
|
-
export declare type TagObj = ScalarTag | CollectionTag;
|
|
85
|
-
export declare type TagValue = TagId | ScalarTag | CollectionTag;
|
|
86
82
|
export {};
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Scalar = require('../../nodes/Scalar.js');
|
|
4
|
+
|
|
5
|
+
function boolStringify({ value, source }, ctx) {
|
|
6
|
+
const boolObj = value ? trueTag : falseTag;
|
|
7
|
+
if (source && boolObj.test.test(source))
|
|
8
|
+
return source;
|
|
9
|
+
return value ? ctx.options.trueStr : ctx.options.falseStr;
|
|
10
|
+
}
|
|
11
|
+
const trueTag = {
|
|
12
|
+
identify: value => value === true,
|
|
13
|
+
default: true,
|
|
14
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
15
|
+
test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
|
|
16
|
+
resolve: () => new Scalar.Scalar(true),
|
|
17
|
+
stringify: boolStringify
|
|
18
|
+
};
|
|
19
|
+
const falseTag = {
|
|
20
|
+
identify: value => value === false,
|
|
21
|
+
default: true,
|
|
22
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
23
|
+
test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
|
|
24
|
+
resolve: () => new Scalar.Scalar(false),
|
|
25
|
+
stringify: boolStringify
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.falseTag = falseTag;
|
|
29
|
+
exports.trueTag = trueTag;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Scalar = require('../../nodes/Scalar.js');
|
|
4
|
+
var stringifyNumber = require('../../stringify/stringifyNumber.js');
|
|
5
|
+
|
|
6
|
+
const floatNaN = {
|
|
7
|
+
identify: value => typeof value === 'number',
|
|
8
|
+
default: true,
|
|
9
|
+
tag: 'tag:yaml.org,2002:float',
|
|
10
|
+
test: /^[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/,
|
|
11
|
+
resolve: (str) => str.slice(-3).toLowerCase() === 'nan'
|
|
12
|
+
? NaN
|
|
13
|
+
: str[0] === '-'
|
|
14
|
+
? Number.NEGATIVE_INFINITY
|
|
15
|
+
: Number.POSITIVE_INFINITY,
|
|
16
|
+
stringify: stringifyNumber.stringifyNumber
|
|
17
|
+
};
|
|
18
|
+
const floatExp = {
|
|
19
|
+
identify: value => typeof value === 'number',
|
|
20
|
+
default: true,
|
|
21
|
+
tag: 'tag:yaml.org,2002:float',
|
|
22
|
+
format: 'EXP',
|
|
23
|
+
test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
|
|
24
|
+
resolve: (str) => parseFloat(str.replace(/_/g, '')),
|
|
25
|
+
stringify: ({ value }) => Number(value).toExponential()
|
|
26
|
+
};
|
|
27
|
+
const float = {
|
|
28
|
+
identify: value => typeof value === 'number',
|
|
29
|
+
default: true,
|
|
30
|
+
tag: 'tag:yaml.org,2002:float',
|
|
31
|
+
test: /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,
|
|
32
|
+
resolve(str) {
|
|
33
|
+
const node = new Scalar.Scalar(parseFloat(str.replace(/_/g, '')));
|
|
34
|
+
const dot = str.indexOf('.');
|
|
35
|
+
if (dot !== -1) {
|
|
36
|
+
const f = str.substring(dot + 1).replace(/_/g, '');
|
|
37
|
+
if (f[f.length - 1] === '0')
|
|
38
|
+
node.minFractionDigits = f.length;
|
|
39
|
+
}
|
|
40
|
+
return node;
|
|
41
|
+
},
|
|
42
|
+
stringify: stringifyNumber.stringifyNumber
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.float = float;
|
|
46
|
+
exports.floatExp = floatExp;
|
|
47
|
+
exports.floatNaN = floatNaN;
|