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 = new Map([
|
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.get(schemaName);
|
54 | if (!tags) {
|
55 | if (Array.isArray(customTags))
|
56 | tags = [];
|
57 | else {
|
58 | const keys = Array.from(schemas.keys())
|
59 | .filter(key => key !== 'yaml11')
|
60 | .map(key => JSON.stringify(key))
|
61 | .join(', ');
|
62 | throw new Error(`Unknown schema "${schemaName}"; use one of ${keys} or define customTags array`);
|
63 | }
|
64 | }
|
65 | if (Array.isArray(customTags)) {
|
66 | for (const tag of customTags)
|
67 | tags = tags.concat(tag);
|
68 | }
|
69 | else if (typeof customTags === 'function') {
|
70 | tags = customTags(tags.slice());
|
71 | }
|
72 | return tags.map(tag => {
|
73 | if (typeof tag !== 'string')
|
74 | return tag;
|
75 | const tagObj = tagsByName[tag];
|
76 | if (tagObj)
|
77 | return tagObj;
|
78 | const keys = Object.keys(tagsByName)
|
79 | .map(key => JSON.stringify(key))
|
80 | .join(', ');
|
81 | throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
|
82 | });
|
83 | }
|
84 |
|
85 | exports.coreKnownTags = coreKnownTags;
|
86 | exports.getTags = getTags;
|