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.
Files changed (220) hide show
  1. package/README.md +5 -5
  2. package/browser/dist/compose/compose-collection.js +12 -9
  3. package/browser/dist/compose/compose-doc.js +23 -6
  4. package/browser/dist/compose/compose-node.js +27 -17
  5. package/browser/dist/compose/compose-scalar.js +21 -23
  6. package/browser/dist/compose/composer.js +108 -78
  7. package/browser/dist/compose/resolve-block-map.js +41 -29
  8. package/browser/dist/compose/resolve-block-scalar.js +14 -17
  9. package/browser/dist/compose/resolve-block-seq.js +21 -17
  10. package/browser/dist/compose/resolve-end.js +7 -8
  11. package/browser/dist/compose/resolve-flow-collection.js +158 -199
  12. package/browser/dist/compose/resolve-flow-scalar.js +62 -26
  13. package/browser/dist/compose/resolve-props.js +72 -37
  14. package/browser/dist/compose/util-contains-newline.js +15 -12
  15. package/browser/dist/compose/util-map-includes.js +17 -0
  16. package/browser/dist/doc/Document.js +74 -99
  17. package/browser/dist/doc/anchors.js +72 -0
  18. package/browser/dist/doc/createNode.js +35 -19
  19. package/browser/dist/doc/directives.js +5 -0
  20. package/browser/dist/errors.js +16 -12
  21. package/browser/dist/index.js +3 -3
  22. package/browser/dist/nodes/Alias.js +51 -28
  23. package/browser/dist/nodes/Collection.js +23 -92
  24. package/browser/dist/nodes/Node.js +9 -1
  25. package/browser/dist/nodes/Pair.js +16 -231
  26. package/browser/dist/nodes/YAMLMap.js +8 -4
  27. package/browser/dist/nodes/YAMLSeq.js +7 -4
  28. package/browser/dist/nodes/addPairToJSMap.js +103 -0
  29. package/browser/dist/nodes/toJS.js +12 -10
  30. package/browser/dist/options.js +1 -2
  31. package/browser/dist/parse/cst-scalar.js +219 -0
  32. package/browser/dist/parse/cst-stringify.js +61 -0
  33. package/browser/dist/parse/cst-visit.js +97 -0
  34. package/{dist/parse/tokens.js → browser/dist/parse/cst.js} +12 -7
  35. package/browser/dist/parse/lexer.js +149 -125
  36. package/browser/dist/parse/parser.js +272 -196
  37. package/browser/dist/public-api.js +11 -14
  38. package/browser/dist/schema/Schema.js +28 -0
  39. package/browser/dist/{tags/failsafe → schema/common}/map.js +0 -0
  40. package/browser/dist/schema/common/null.js +13 -0
  41. package/browser/dist/{tags/failsafe → schema/common}/seq.js +1 -1
  42. package/browser/dist/{tags/failsafe → schema/common}/string.js +0 -0
  43. package/browser/dist/schema/core/bool.js +19 -0
  44. package/browser/dist/schema/core/float.js +40 -0
  45. package/browser/dist/schema/core/int.js +38 -0
  46. package/browser/dist/schema/core/schema.js +23 -0
  47. package/browser/dist/{tags/json.js → schema/json/schema.js} +5 -6
  48. package/browser/dist/schema/tags.js +79 -0
  49. package/browser/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
  50. package/browser/dist/schema/yaml-1.1/bool.js +26 -0
  51. package/browser/dist/schema/yaml-1.1/float.js +43 -0
  52. package/browser/dist/schema/yaml-1.1/int.js +71 -0
  53. package/browser/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
  54. package/browser/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
  55. package/browser/dist/schema/yaml-1.1/schema.js +37 -0
  56. package/browser/dist/{tags → schema}/yaml-1.1/set.js +0 -0
  57. package/browser/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
  58. package/browser/dist/stringify/stringify.js +8 -6
  59. package/browser/dist/stringify/stringifyCollection.js +122 -0
  60. package/browser/dist/stringify/stringifyComment.js +14 -0
  61. package/browser/dist/stringify/stringifyDocument.js +64 -0
  62. package/browser/dist/stringify/stringifyPair.js +111 -0
  63. package/browser/dist/stringify/stringifyString.js +53 -52
  64. package/browser/dist/visit.js +20 -1
  65. package/dist/compose/compose-collection.d.ts +4 -4
  66. package/dist/compose/compose-collection.js +12 -9
  67. package/dist/compose/compose-doc.d.ts +4 -3
  68. package/dist/compose/compose-doc.js +23 -6
  69. package/dist/compose/compose-node.d.ts +15 -7
  70. package/dist/compose/compose-node.js +27 -17
  71. package/dist/compose/compose-scalar.d.ts +4 -3
  72. package/dist/compose/compose-scalar.js +20 -22
  73. package/dist/compose/composer.d.ts +28 -23
  74. package/dist/compose/composer.js +109 -79
  75. package/dist/compose/resolve-block-map.d.ts +5 -4
  76. package/dist/compose/resolve-block-map.js +41 -29
  77. package/dist/compose/resolve-block-scalar.d.ts +5 -3
  78. package/dist/compose/resolve-block-scalar.js +14 -17
  79. package/dist/compose/resolve-block-seq.d.ts +4 -4
  80. package/dist/compose/resolve-block-seq.js +21 -17
  81. package/dist/compose/resolve-end.d.ts +3 -2
  82. package/dist/compose/resolve-end.js +7 -8
  83. package/dist/compose/resolve-flow-collection.d.ts +4 -5
  84. package/dist/compose/resolve-flow-collection.js +157 -198
  85. package/dist/compose/resolve-flow-scalar.d.ts +5 -3
  86. package/dist/compose/resolve-flow-scalar.js +62 -26
  87. package/dist/compose/resolve-props.d.ts +16 -10
  88. package/dist/compose/resolve-props.js +72 -37
  89. package/dist/compose/util-contains-newline.d.ts +1 -1
  90. package/dist/compose/util-contains-newline.js +15 -12
  91. package/dist/compose/util-empty-scalar-position.d.ts +1 -1
  92. package/dist/compose/util-map-includes.d.ts +4 -0
  93. package/dist/compose/util-map-includes.js +19 -0
  94. package/dist/doc/Document.d.ts +35 -15
  95. package/dist/doc/Document.js +72 -97
  96. package/dist/doc/anchors.d.ts +24 -0
  97. package/dist/doc/anchors.js +77 -0
  98. package/dist/doc/createNode.d.ts +10 -11
  99. package/dist/doc/createNode.js +34 -18
  100. package/dist/doc/directives.d.ts +1 -0
  101. package/dist/doc/directives.js +5 -0
  102. package/dist/errors.d.ts +11 -8
  103. package/dist/errors.js +16 -12
  104. package/dist/index.d.ts +5 -3
  105. package/dist/index.js +3 -3
  106. package/dist/nodes/Alias.d.ts +19 -9
  107. package/dist/nodes/Alias.js +51 -28
  108. package/dist/nodes/Collection.d.ts +9 -17
  109. package/dist/nodes/Collection.js +22 -91
  110. package/dist/nodes/Node.d.ts +10 -4
  111. package/dist/nodes/Node.js +9 -0
  112. package/dist/nodes/Pair.d.ts +10 -13
  113. package/dist/nodes/Pair.js +15 -230
  114. package/dist/nodes/Scalar.d.ts +6 -3
  115. package/dist/nodes/YAMLMap.d.ts +3 -3
  116. package/dist/nodes/YAMLMap.js +8 -4
  117. package/dist/nodes/YAMLSeq.d.ts +3 -3
  118. package/dist/nodes/YAMLSeq.js +7 -4
  119. package/dist/nodes/addPairToJSMap.d.ts +3 -0
  120. package/dist/nodes/addPairToJSMap.js +105 -0
  121. package/dist/nodes/toJS.d.ts +4 -5
  122. package/dist/nodes/toJS.js +12 -10
  123. package/dist/options.d.ts +41 -25
  124. package/dist/options.js +1 -2
  125. package/dist/parse/cst-scalar.d.ts +58 -0
  126. package/dist/parse/cst-scalar.js +223 -0
  127. package/dist/parse/cst-stringify.d.ts +8 -0
  128. package/dist/parse/cst-stringify.js +63 -0
  129. package/dist/parse/cst-visit.d.ts +39 -0
  130. package/dist/parse/cst-visit.js +99 -0
  131. package/dist/parse/{tokens.d.ts → cst.d.ts} +23 -7
  132. package/{browser/dist/parse/tokens.js → dist/parse/cst.js} +27 -1
  133. package/dist/parse/lexer.d.ts +7 -14
  134. package/dist/parse/lexer.js +150 -126
  135. package/dist/parse/parser.d.ts +31 -24
  136. package/dist/parse/parser.js +274 -198
  137. package/dist/public-api.d.ts +7 -7
  138. package/dist/public-api.js +11 -14
  139. package/dist/{doc → schema}/Schema.d.ts +6 -3
  140. package/dist/schema/Schema.js +30 -0
  141. package/dist/{tags/failsafe → schema/common}/map.d.ts +0 -0
  142. package/dist/{tags/failsafe → schema/common}/map.js +0 -0
  143. package/dist/schema/common/null.d.ts +4 -0
  144. package/dist/schema/common/null.js +15 -0
  145. package/dist/{tags/failsafe → schema/common}/seq.d.ts +0 -0
  146. package/dist/{tags/failsafe → schema/common}/seq.js +1 -1
  147. package/dist/{tags/failsafe → schema/common}/string.d.ts +0 -0
  148. package/dist/{tags/failsafe → schema/common}/string.js +0 -0
  149. package/dist/schema/core/bool.d.ts +4 -0
  150. package/dist/schema/core/bool.js +21 -0
  151. package/dist/schema/core/float.d.ts +4 -0
  152. package/dist/schema/core/float.js +44 -0
  153. package/dist/schema/core/int.d.ts +4 -0
  154. package/dist/schema/core/int.js +42 -0
  155. package/dist/schema/core/schema.d.ts +1 -0
  156. package/dist/schema/core/schema.js +25 -0
  157. package/dist/schema/json/schema.d.ts +2 -0
  158. package/dist/{tags/json.js → schema/json/schema.js} +5 -6
  159. package/dist/schema/tags.d.ts +41 -0
  160. package/dist/schema/tags.js +82 -0
  161. package/dist/{tags → schema}/types.d.ts +3 -7
  162. package/dist/{tags → schema}/yaml-1.1/binary.d.ts +0 -0
  163. package/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
  164. package/dist/schema/yaml-1.1/bool.d.ts +7 -0
  165. package/dist/schema/yaml-1.1/bool.js +29 -0
  166. package/dist/schema/yaml-1.1/float.d.ts +4 -0
  167. package/dist/schema/yaml-1.1/float.js +47 -0
  168. package/dist/schema/yaml-1.1/int.d.ts +5 -0
  169. package/dist/schema/yaml-1.1/int.js +76 -0
  170. package/dist/{tags → schema}/yaml-1.1/omap.d.ts +0 -0
  171. package/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
  172. package/dist/{tags → schema}/yaml-1.1/pairs.d.ts +3 -2
  173. package/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
  174. package/dist/schema/yaml-1.1/schema.d.ts +1 -0
  175. package/dist/schema/yaml-1.1/schema.js +39 -0
  176. package/dist/{tags → schema}/yaml-1.1/set.d.ts +1 -1
  177. package/dist/{tags → schema}/yaml-1.1/set.js +0 -0
  178. package/dist/{tags → schema}/yaml-1.1/timestamp.d.ts +0 -0
  179. package/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
  180. package/dist/stringify/stringify.d.ts +1 -2
  181. package/dist/stringify/stringify.js +8 -6
  182. package/dist/stringify/stringifyCollection.d.ts +21 -0
  183. package/dist/stringify/stringifyCollection.js +124 -0
  184. package/dist/stringify/stringifyComment.d.ts +2 -0
  185. package/dist/stringify/stringifyComment.js +17 -0
  186. package/dist/stringify/stringifyDocument.d.ts +3 -0
  187. package/dist/stringify/stringifyDocument.js +66 -0
  188. package/dist/stringify/stringifyPair.d.ts +3 -0
  189. package/dist/stringify/stringifyPair.js +113 -0
  190. package/dist/stringify/stringifyString.js +53 -52
  191. package/dist/test-events.d.ts +1 -2
  192. package/dist/test-events.js +25 -12
  193. package/dist/util.d.ts +1 -1
  194. package/dist/visit.d.ts +10 -1
  195. package/dist/visit.js +20 -1
  196. package/package.json +9 -8
  197. package/browser/dist/doc/Anchors.js +0 -102
  198. package/browser/dist/doc/Schema.js +0 -27
  199. package/browser/dist/doc/getSchemaTags.js +0 -30
  200. package/browser/dist/stringify/addComment.js +0 -17
  201. package/browser/dist/tags/core.js +0 -109
  202. package/browser/dist/tags/failsafe/index.js +0 -7
  203. package/browser/dist/tags/index.js +0 -34
  204. package/browser/dist/tags/yaml-1.1/index.js +0 -152
  205. package/dist/doc/Anchors.d.ts +0 -36
  206. package/dist/doc/Anchors.js +0 -104
  207. package/dist/doc/Schema.js +0 -29
  208. package/dist/doc/getSchemaTags.d.ts +0 -3
  209. package/dist/doc/getSchemaTags.js +0 -32
  210. package/dist/stringify/addComment.d.ts +0 -2
  211. package/dist/stringify/addComment.js +0 -20
  212. package/dist/tags/core.d.ts +0 -14
  213. package/dist/tags/core.js +0 -119
  214. package/dist/tags/failsafe/index.d.ts +0 -1
  215. package/dist/tags/failsafe/index.js +0 -9
  216. package/dist/tags/index.d.ts +0 -31
  217. package/dist/tags/index.js +0 -37
  218. package/dist/tags/json.d.ts +0 -2
  219. package/dist/tags/yaml-1.1/index.d.ts +0 -2
  220. package/dist/tags/yaml-1.1/index.js +0 -154
@@ -1,7 +0,0 @@
1
- import { map } from './map.js';
2
- import { seq } from './seq.js';
3
- import { string } from './string.js';
4
-
5
- const failsafe = [map, seq, string];
6
-
7
- export { failsafe };
@@ -1,34 +0,0 @@
1
- import { boolObj, floatObj, expObj, nanObj, intObj, hexObj, octObj, nullObj, core } from './core.js';
2
- import { failsafe } from './failsafe/index.js';
3
- import { json } from './json.js';
4
- import { yaml11 } from './yaml-1.1/index.js';
5
- import { map } from './failsafe/map.js';
6
- import { seq } from './failsafe/seq.js';
7
- import { binary } from './yaml-1.1/binary.js';
8
- import { omap } from './yaml-1.1/omap.js';
9
- import { pairs } from './yaml-1.1/pairs.js';
10
- import { set } from './yaml-1.1/set.js';
11
- import { floatTime, intTime, timestamp } from './yaml-1.1/timestamp.js';
12
-
13
- const schemas = { core, failsafe, json, yaml11 };
14
- const tags = {
15
- binary,
16
- bool: boolObj,
17
- float: floatObj,
18
- floatExp: expObj,
19
- floatNaN: nanObj,
20
- floatTime,
21
- int: intObj,
22
- intHex: hexObj,
23
- intOct: octObj,
24
- intTime,
25
- map,
26
- null: nullObj,
27
- omap,
28
- pairs,
29
- seq,
30
- set,
31
- timestamp
32
- };
33
-
34
- export { schemas, tags };
@@ -1,152 +0,0 @@
1
- import { Scalar } from '../../nodes/Scalar.js';
2
- import { stringifyNumber } from '../../stringify/stringifyNumber.js';
3
- import { failsafe } from '../failsafe/index.js';
4
- import { binary } from './binary.js';
5
- import { omap } from './omap.js';
6
- import { pairs } from './pairs.js';
7
- import { set } from './set.js';
8
- import { intTime, floatTime, timestamp } from './timestamp.js';
9
-
10
- const nullObj = {
11
- identify: value => value == null,
12
- createNode: () => new Scalar(null),
13
- default: true,
14
- tag: 'tag:yaml.org,2002:null',
15
- test: /^(?:~|[Nn]ull|NULL)?$/,
16
- resolve: () => new Scalar(null),
17
- stringify: ({ source }, ctx) => source && nullObj.test.test(source) ? source : ctx.options.nullStr
18
- };
19
- function boolStringify({ value, source }, ctx) {
20
- const boolObj = value ? trueObj : falseObj;
21
- if (source && boolObj.test.test(source))
22
- return source;
23
- return value ? ctx.options.trueStr : ctx.options.falseStr;
24
- }
25
- const trueObj = {
26
- identify: value => value === true,
27
- default: true,
28
- tag: 'tag:yaml.org,2002:bool',
29
- test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
30
- resolve: () => new Scalar(true),
31
- stringify: boolStringify
32
- };
33
- const falseObj = {
34
- identify: value => value === false,
35
- default: true,
36
- tag: 'tag:yaml.org,2002:bool',
37
- test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
38
- resolve: () => new Scalar(false),
39
- stringify: boolStringify
40
- };
41
- const intIdentify = (value) => typeof value === 'bigint' || Number.isInteger(value);
42
- function intResolve(str, offset, radix, { intAsBigInt }) {
43
- const sign = str[0];
44
- if (sign === '-' || sign === '+')
45
- offset += 1;
46
- str = str.substring(offset).replace(/_/g, '');
47
- if (intAsBigInt) {
48
- switch (radix) {
49
- case 2:
50
- str = `0b${str}`;
51
- break;
52
- case 8:
53
- str = `0o${str}`;
54
- break;
55
- case 16:
56
- str = `0x${str}`;
57
- break;
58
- }
59
- const n = BigInt(str);
60
- return sign === '-' ? BigInt(-1) * n : n;
61
- }
62
- const n = parseInt(str, radix);
63
- return sign === '-' ? -1 * n : n;
64
- }
65
- function intStringify(node, radix, prefix) {
66
- const { value } = node;
67
- if (intIdentify(value)) {
68
- const str = value.toString(radix);
69
- return value < 0 ? '-' + prefix + str.substr(1) : prefix + str;
70
- }
71
- return stringifyNumber(node);
72
- }
73
- const yaml11 = failsafe.concat([
74
- nullObj,
75
- trueObj,
76
- falseObj,
77
- {
78
- identify: intIdentify,
79
- default: true,
80
- tag: 'tag:yaml.org,2002:int',
81
- format: 'BIN',
82
- test: /^[-+]?0b[0-1_]+$/,
83
- resolve: (str, _onError, opt) => intResolve(str, 2, 2, opt),
84
- stringify: node => intStringify(node, 2, '0b')
85
- },
86
- {
87
- identify: intIdentify,
88
- default: true,
89
- tag: 'tag:yaml.org,2002:int',
90
- format: 'OCT',
91
- test: /^[-+]?0[0-7_]+$/,
92
- resolve: (str, _onError, opt) => intResolve(str, 1, 8, opt),
93
- stringify: node => intStringify(node, 8, '0')
94
- },
95
- {
96
- identify: intIdentify,
97
- default: true,
98
- tag: 'tag:yaml.org,2002:int',
99
- test: /^[-+]?[0-9][0-9_]*$/,
100
- resolve: (str, _onError, opt) => intResolve(str, 0, 10, opt),
101
- stringify: stringifyNumber
102
- },
103
- {
104
- identify: intIdentify,
105
- default: true,
106
- tag: 'tag:yaml.org,2002:int',
107
- format: 'HEX',
108
- test: /^[-+]?0x[0-9a-fA-F_]+$/,
109
- resolve: (str, _onError, opt) => intResolve(str, 2, 16, opt),
110
- stringify: node => intStringify(node, 16, '0x')
111
- },
112
- {
113
- identify: value => typeof value === 'number',
114
- default: true,
115
- tag: 'tag:yaml.org,2002:float',
116
- test: /^[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/,
117
- resolve: (str) => str.slice(-3).toLowerCase() === 'nan'
118
- ? NaN
119
- : str[0] === '-'
120
- ? Number.NEGATIVE_INFINITY
121
- : Number.POSITIVE_INFINITY,
122
- stringify: stringifyNumber
123
- },
124
- {
125
- identify: value => typeof value === 'number',
126
- default: true,
127
- tag: 'tag:yaml.org,2002:float',
128
- format: 'EXP',
129
- test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
130
- resolve: (str) => parseFloat(str.replace(/_/g, '')),
131
- stringify: ({ value }) => Number(value).toExponential()
132
- },
133
- {
134
- identify: value => typeof value === 'number',
135
- default: true,
136
- tag: 'tag:yaml.org,2002:float',
137
- test: /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,
138
- resolve(str) {
139
- const node = new Scalar(parseFloat(str.replace(/_/g, '')));
140
- const dot = str.indexOf('.');
141
- if (dot !== -1) {
142
- const f = str.substring(dot + 1).replace(/_/g, '');
143
- if (f[f.length - 1] === '0')
144
- node.minFractionDigits = f.length;
145
- }
146
- return node;
147
- },
148
- stringify: stringifyNumber
149
- }
150
- ], binary, omap, pairs, set, intTime, floatTime, timestamp);
151
-
152
- export { yaml11 };
@@ -1,36 +0,0 @@
1
- import { Alias } from '../nodes/Alias.js';
2
- import { Node } from '../nodes/Node.js';
3
- import { Pair } from '../nodes/Pair.js';
4
- import { Scalar } from '../nodes/Scalar.js';
5
- import { YAMLSeq } from '../nodes/YAMLSeq.js';
6
- export declare class Anchors {
7
- map: Record<string, Node>;
8
- private prefix;
9
- constructor(prefix: string);
10
- /**
11
- * Create a new `Alias` node, adding the required anchor for `node`.
12
- * If `name` is empty, a new anchor name will be generated.
13
- */
14
- createAlias(node: Node, name?: string): Alias<Node>;
15
- /**
16
- * Create a new merge `Pair` with the given source nodes.
17
- * Non-`Alias` sources will be automatically wrapped.
18
- */
19
- createMergePair(...sources: Node[]): Pair<Scalar<string>, Alias<Node>> | Pair<Scalar<string>, YAMLSeq<Alias<Node>>>;
20
- /** The anchor name associated with `node`, if set. */
21
- getName(node: Node): string | undefined;
22
- /** List of all defined anchor names. */
23
- getNames(): string[];
24
- /** The node associated with the anchor `name`, if set. */
25
- getNode(name: string): Node;
26
- /**
27
- * Find an available anchor name with the given `prefix` and a
28
- * numerical suffix.
29
- */
30
- newName(prefix?: string): string;
31
- /**
32
- * Associate an anchor with `node`. If `name` is empty, a new name will be generated.
33
- * To remove an anchor, use `setAnchor(null, name)`.
34
- */
35
- setAnchor(node: Node | null, name?: string): string | null;
36
- }
@@ -1,104 +0,0 @@
1
- 'use strict';
2
-
3
- var Alias = require('../nodes/Alias.js');
4
- var Node = require('../nodes/Node.js');
5
- var Pair = require('../nodes/Pair.js');
6
- var Scalar = require('../nodes/Scalar.js');
7
- var YAMLSeq = require('../nodes/YAMLSeq.js');
8
-
9
- class Anchors {
10
- constructor(prefix) {
11
- this.map = Object.create(null);
12
- this.prefix = prefix;
13
- }
14
- /**
15
- * Create a new `Alias` node, adding the required anchor for `node`.
16
- * If `name` is empty, a new anchor name will be generated.
17
- */
18
- createAlias(node, name) {
19
- this.setAnchor(node, name);
20
- return new Alias.Alias(node);
21
- }
22
- /**
23
- * Create a new merge `Pair` with the given source nodes.
24
- * Non-`Alias` sources will be automatically wrapped.
25
- */
26
- createMergePair(...sources) {
27
- const key = new Scalar.Scalar(Pair.Pair.MERGE_KEY);
28
- const items = sources.map(s => {
29
- if (Node.isAlias(s)) {
30
- if (Node.isMap(s.source))
31
- return s;
32
- }
33
- else if (Node.isMap(s)) {
34
- return this.createAlias(s);
35
- }
36
- throw new Error('Merge sources must be Map nodes or their Aliases');
37
- });
38
- if (items.length === 1)
39
- return new Pair.Pair(key, items[0]);
40
- const seq = new YAMLSeq.YAMLSeq();
41
- seq.items = items;
42
- return new Pair.Pair(key, seq);
43
- }
44
- /** The anchor name associated with `node`, if set. */
45
- getName(node) {
46
- return Object.keys(this.map).find(a => this.map[a] === node);
47
- }
48
- /** List of all defined anchor names. */
49
- getNames() {
50
- return Object.keys(this.map);
51
- }
52
- /** The node associated with the anchor `name`, if set. */
53
- getNode(name) {
54
- return this.map[name];
55
- }
56
- /**
57
- * Find an available anchor name with the given `prefix` and a
58
- * numerical suffix.
59
- */
60
- newName(prefix) {
61
- if (!prefix)
62
- prefix = this.prefix;
63
- const names = Object.keys(this.map);
64
- for (let i = 1; true; ++i) {
65
- const name = `${prefix}${i}`;
66
- if (!names.includes(name))
67
- return name;
68
- }
69
- }
70
- /**
71
- * Associate an anchor with `node`. If `name` is empty, a new name will be generated.
72
- * To remove an anchor, use `setAnchor(null, name)`.
73
- */
74
- setAnchor(node, name) {
75
- const { map } = this;
76
- if (!node) {
77
- if (!name)
78
- return null;
79
- delete map[name];
80
- return name;
81
- }
82
- if (!Node.isScalar(node) && !Node.isCollection(node))
83
- throw new Error('Anchors may only be set for Scalar, Seq and Map nodes');
84
- if (name) {
85
- if (/[\x00-\x19\s,[\]{}]/.test(name))
86
- throw new Error('Anchor names must not contain whitespace or control characters');
87
- const prevNode = map[name];
88
- if (prevNode && prevNode !== node)
89
- map[this.newName(name)] = prevNode;
90
- }
91
- const prevName = Object.keys(map).find(a => map[a] === node);
92
- if (prevName) {
93
- if (!name || prevName === name)
94
- return prevName;
95
- delete map[prevName];
96
- }
97
- else if (!name)
98
- name = this.newName();
99
- map[name] = node;
100
- return name;
101
- }
102
- }
103
-
104
- exports.Anchors = Anchors;
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- var index = require('../tags/index.js');
4
- var getSchemaTags = require('./getSchemaTags.js');
5
-
6
- const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
7
- const coreKnownTags = {
8
- 'tag:yaml.org,2002:binary': index.tags.binary,
9
- 'tag:yaml.org,2002:omap': index.tags.omap,
10
- 'tag:yaml.org,2002:pairs': index.tags.pairs,
11
- 'tag:yaml.org,2002:set': index.tags.set,
12
- 'tag:yaml.org,2002:timestamp': index.tags.timestamp
13
- };
14
- class Schema {
15
- constructor({ customTags, merge, resolveKnownTags, schema, sortMapEntries }) {
16
- // Used by createNode(), to avoid circular dependencies
17
- this.map = index.tags.map;
18
- this.seq = index.tags.seq;
19
- this.merge = !!merge;
20
- this.name = schema || 'core';
21
- this.knownTags = resolveKnownTags ? coreKnownTags : {};
22
- this.tags = getSchemaTags.getSchemaTags(index.schemas, index.tags, customTags, this.name);
23
- // Used by createMap()
24
- this.sortMapEntries =
25
- sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null;
26
- }
27
- }
28
-
29
- exports.Schema = Schema;
@@ -1,3 +0,0 @@
1
- import type { SchemaId, TagId, TagObj, TagValue } from '../tags/types.js';
2
- import type { SchemaName } from './Schema.js';
3
- export declare function getSchemaTags(schemas: Record<SchemaId, TagObj[]>, knownTags: Record<TagId, TagObj>, customTags: TagValue[] | ((tags: TagValue[]) => TagValue[]) | null | undefined, schemaName: SchemaName): TagObj[];
@@ -1,32 +0,0 @@
1
- 'use strict';
2
-
3
- function getSchemaTags(schemas, knownTags, customTags, schemaName) {
4
- const schemaId = schemaName.replace(/\W/g, ''); // 'yaml-1.1' -> 'yaml11'
5
- let tags = schemas[schemaId];
6
- if (!tags) {
7
- const keys = Object.keys(schemas)
8
- .map(key => JSON.stringify(key))
9
- .join(', ');
10
- throw new Error(`Unknown schema "${schemaName}"; use one of ${keys}`);
11
- }
12
- if (Array.isArray(customTags)) {
13
- for (const tag of customTags)
14
- tags = tags.concat(tag);
15
- }
16
- else if (typeof customTags === 'function') {
17
- tags = customTags(tags.slice());
18
- }
19
- return tags.map(tag => {
20
- if (typeof tag !== 'string')
21
- return tag;
22
- const tagObj = knownTags[tag];
23
- if (tagObj)
24
- return tagObj;
25
- const keys = Object.keys(knownTags)
26
- .map(key => JSON.stringify(key))
27
- .join(', ');
28
- throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
29
- });
30
- }
31
-
32
- exports.getSchemaTags = getSchemaTags;
@@ -1,2 +0,0 @@
1
- export declare function addCommentBefore(str: string, indent: string, comment?: string | null): string;
2
- export declare function addComment(str: string, indent: string, comment?: string | null): string;
@@ -1,20 +0,0 @@
1
- 'use strict';
2
-
3
- function addCommentBefore(str, indent, comment) {
4
- if (!comment)
5
- return str;
6
- const cc = comment.replace(/[\s\S]^/gm, `$&${indent}#`);
7
- return `#${cc}\n${indent}${str}`;
8
- }
9
- function addComment(str, indent, comment) {
10
- return !comment
11
- ? str
12
- : comment.includes('\n')
13
- ? `${str}\n` + comment.replace(/^/gm, `${indent || ''}#`)
14
- : str.endsWith(' ')
15
- ? `${str}#${comment}`
16
- : `${str} #${comment}`;
17
- }
18
-
19
- exports.addComment = addComment;
20
- exports.addCommentBefore = addCommentBefore;
@@ -1,14 +0,0 @@
1
- import { ScalarTag } from './types.js';
2
- export declare const nullObj: ScalarTag & {
3
- test: RegExp;
4
- };
5
- export declare const boolObj: ScalarTag & {
6
- test: RegExp;
7
- };
8
- export declare const octObj: ScalarTag;
9
- export declare const intObj: ScalarTag;
10
- export declare const hexObj: ScalarTag;
11
- export declare const nanObj: ScalarTag;
12
- export declare const expObj: ScalarTag;
13
- export declare const floatObj: ScalarTag;
14
- export declare const core: (ScalarTag | import("./types.js").CollectionTag)[];
package/dist/tags/core.js DELETED
@@ -1,119 +0,0 @@
1
- 'use strict';
2
-
3
- var Scalar = require('../nodes/Scalar.js');
4
- var stringifyNumber = require('../stringify/stringifyNumber.js');
5
- var index = require('./failsafe/index.js');
6
-
7
- const intIdentify = (value) => typeof value === 'bigint' || Number.isInteger(value);
8
- const intResolve = (str, offset, radix, { intAsBigInt }) => (intAsBigInt ? BigInt(str) : parseInt(str.substring(offset), radix));
9
- function intStringify(node, radix, prefix) {
10
- const { value } = node;
11
- if (intIdentify(value) && value >= 0)
12
- return prefix + value.toString(radix);
13
- return stringifyNumber.stringifyNumber(node);
14
- }
15
- const nullObj = {
16
- identify: value => value == null,
17
- createNode: () => new Scalar.Scalar(null),
18
- default: true,
19
- tag: 'tag:yaml.org,2002:null',
20
- test: /^(?:~|[Nn]ull|NULL)?$/,
21
- resolve: () => new Scalar.Scalar(null),
22
- stringify: ({ source }, ctx) => source && nullObj.test.test(source) ? source : ctx.options.nullStr
23
- };
24
- const boolObj = {
25
- identify: value => typeof value === 'boolean',
26
- default: true,
27
- tag: 'tag:yaml.org,2002:bool',
28
- test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
29
- resolve: str => new Scalar.Scalar(str[0] === 't' || str[0] === 'T'),
30
- stringify({ source, value }, ctx) {
31
- if (source && boolObj.test.test(source)) {
32
- const sv = source[0] === 't' || source[0] === 'T';
33
- if (value === sv)
34
- return source;
35
- }
36
- return value ? ctx.options.trueStr : ctx.options.falseStr;
37
- }
38
- };
39
- const octObj = {
40
- identify: value => intIdentify(value) && value >= 0,
41
- default: true,
42
- tag: 'tag:yaml.org,2002:int',
43
- format: 'OCT',
44
- test: /^0o[0-7]+$/,
45
- resolve: (str, _onError, opt) => intResolve(str, 2, 8, opt),
46
- stringify: node => intStringify(node, 8, '0o')
47
- };
48
- const intObj = {
49
- identify: intIdentify,
50
- default: true,
51
- tag: 'tag:yaml.org,2002:int',
52
- test: /^[-+]?[0-9]+$/,
53
- resolve: (str, _onError, opt) => intResolve(str, 0, 10, opt),
54
- stringify: stringifyNumber.stringifyNumber
55
- };
56
- const hexObj = {
57
- identify: value => intIdentify(value) && value >= 0,
58
- default: true,
59
- tag: 'tag:yaml.org,2002:int',
60
- format: 'HEX',
61
- test: /^0x[0-9a-fA-F]+$/,
62
- resolve: (str, _onError, opt) => intResolve(str, 2, 16, opt),
63
- stringify: node => intStringify(node, 16, '0x')
64
- };
65
- const nanObj = {
66
- identify: value => typeof value === 'number',
67
- default: true,
68
- tag: 'tag:yaml.org,2002:float',
69
- test: /^(?:[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN))$/,
70
- resolve: str => str.slice(-3).toLowerCase() === 'nan'
71
- ? NaN
72
- : str[0] === '-'
73
- ? Number.NEGATIVE_INFINITY
74
- : Number.POSITIVE_INFINITY,
75
- stringify: stringifyNumber.stringifyNumber
76
- };
77
- const expObj = {
78
- identify: value => typeof value === 'number',
79
- default: true,
80
- tag: 'tag:yaml.org,2002:float',
81
- format: 'EXP',
82
- test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
83
- resolve: str => parseFloat(str),
84
- stringify: ({ value }) => Number(value).toExponential()
85
- };
86
- const floatObj = {
87
- identify: value => typeof value === 'number',
88
- default: true,
89
- tag: 'tag:yaml.org,2002:float',
90
- test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
91
- resolve(str) {
92
- const node = new Scalar.Scalar(parseFloat(str));
93
- const dot = str.indexOf('.');
94
- if (dot !== -1 && str[str.length - 1] === '0')
95
- node.minFractionDigits = str.length - dot - 1;
96
- return node;
97
- },
98
- stringify: stringifyNumber.stringifyNumber
99
- };
100
- const core = index.failsafe.concat([
101
- nullObj,
102
- boolObj,
103
- octObj,
104
- intObj,
105
- hexObj,
106
- nanObj,
107
- expObj,
108
- floatObj
109
- ]);
110
-
111
- exports.boolObj = boolObj;
112
- exports.core = core;
113
- exports.expObj = expObj;
114
- exports.floatObj = floatObj;
115
- exports.hexObj = hexObj;
116
- exports.intObj = intObj;
117
- exports.nanObj = nanObj;
118
- exports.nullObj = nullObj;
119
- exports.octObj = octObj;
@@ -1 +0,0 @@
1
- export declare const failsafe: (import("../types.js").ScalarTag | import("../types.js").CollectionTag)[];
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- var map = require('./map.js');
4
- var seq = require('./seq.js');
5
- var string = require('./string.js');
6
-
7
- const failsafe = [map.map, seq.seq, string.string];
8
-
9
- exports.failsafe = failsafe;
@@ -1,31 +0,0 @@
1
- export declare const schemas: {
2
- core: (import("./types.js").ScalarTag | import("./types.js").CollectionTag)[];
3
- failsafe: (import("./types.js").ScalarTag | import("./types.js").CollectionTag)[];
4
- json: (import("./types.js").ScalarTag | import("./types.js").CollectionTag)[];
5
- yaml11: (import("./types.js").ScalarTag | import("./types.js").CollectionTag)[];
6
- };
7
- export declare const tags: {
8
- binary: import("./types.js").ScalarTag;
9
- bool: import("./types.js").ScalarTag & {
10
- test: RegExp;
11
- };
12
- float: import("./types.js").ScalarTag;
13
- floatExp: import("./types.js").ScalarTag;
14
- floatNaN: import("./types.js").ScalarTag;
15
- floatTime: import("./types.js").ScalarTag;
16
- int: import("./types.js").ScalarTag;
17
- intHex: import("./types.js").ScalarTag;
18
- intOct: import("./types.js").ScalarTag;
19
- intTime: import("./types.js").ScalarTag;
20
- map: import("./types.js").CollectionTag;
21
- null: import("./types.js").ScalarTag & {
22
- test: RegExp;
23
- };
24
- omap: import("./types.js").CollectionTag;
25
- pairs: import("./types.js").CollectionTag;
26
- seq: import("./types.js").CollectionTag;
27
- set: import("./types.js").CollectionTag;
28
- timestamp: import("./types.js").ScalarTag & {
29
- test: RegExp;
30
- };
31
- };
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- var core = require('./core.js');
4
- var index = require('./failsafe/index.js');
5
- var json = require('./json.js');
6
- var index$1 = require('./yaml-1.1/index.js');
7
- var map = require('./failsafe/map.js');
8
- var seq = require('./failsafe/seq.js');
9
- var binary = require('./yaml-1.1/binary.js');
10
- var omap = require('./yaml-1.1/omap.js');
11
- var pairs = require('./yaml-1.1/pairs.js');
12
- var set = require('./yaml-1.1/set.js');
13
- var timestamp = require('./yaml-1.1/timestamp.js');
14
-
15
- const schemas = { core: core.core, failsafe: index.failsafe, json: json.json, yaml11: index$1.yaml11 };
16
- const tags = {
17
- binary: binary.binary,
18
- bool: core.boolObj,
19
- float: core.floatObj,
20
- floatExp: core.expObj,
21
- floatNaN: core.nanObj,
22
- floatTime: timestamp.floatTime,
23
- int: core.intObj,
24
- intHex: core.hexObj,
25
- intOct: core.octObj,
26
- intTime: timestamp.intTime,
27
- map: map.map,
28
- null: core.nullObj,
29
- omap: omap.omap,
30
- pairs: pairs.pairs,
31
- seq: seq.seq,
32
- set: set.set,
33
- timestamp: timestamp.timestamp
34
- };
35
-
36
- exports.schemas = schemas;
37
- exports.tags = tags;
@@ -1,2 +0,0 @@
1
- import { CollectionTag, ScalarTag } from './types.js';
2
- export declare const json: (ScalarTag | CollectionTag)[];
@@ -1,2 +0,0 @@
1
- import type { ScalarTag } from '../types.js';
2
- export declare const yaml11: (ScalarTag | import("../types.js").CollectionTag)[];