yaml 2.0.0-2 → 2.0.0-6

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 (347) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +46 -26
  3. package/browser/dist/compose/compose-collection.js +59 -0
  4. package/browser/dist/compose/compose-doc.js +39 -0
  5. package/browser/dist/compose/compose-node.js +72 -0
  6. package/browser/dist/compose/compose-scalar.js +74 -0
  7. package/browser/dist/compose/composer.js +218 -0
  8. package/browser/dist/compose/resolve-block-map.js +93 -0
  9. package/browser/dist/compose/resolve-block-scalar.js +185 -0
  10. package/browser/dist/compose/resolve-block-seq.js +40 -0
  11. package/browser/dist/compose/resolve-end.js +37 -0
  12. package/browser/dist/compose/resolve-flow-collection.js +189 -0
  13. package/browser/dist/compose/resolve-flow-scalar.js +211 -0
  14. package/browser/dist/compose/resolve-props.js +126 -0
  15. package/browser/dist/compose/util-contains-newline.js +34 -0
  16. package/browser/dist/compose/util-empty-scalar-position.js +27 -0
  17. package/browser/dist/compose/util-map-includes.js +17 -0
  18. package/browser/dist/doc/Document.js +251 -348
  19. package/browser/dist/doc/anchors.js +72 -0
  20. package/browser/dist/doc/applyReviver.js +41 -28
  21. package/browser/dist/doc/createNode.js +71 -55
  22. package/browser/dist/doc/directives.js +161 -0
  23. package/browser/dist/errors.js +50 -72
  24. package/browser/dist/index.js +17 -73
  25. package/browser/dist/log.js +11 -7
  26. package/browser/dist/nodes/Alias.js +94 -0
  27. package/browser/dist/nodes/Collection.js +133 -0
  28. package/browser/dist/nodes/Node.js +41 -0
  29. package/browser/dist/nodes/Pair.js +28 -0
  30. package/browser/dist/nodes/Scalar.js +23 -0
  31. package/browser/dist/nodes/YAMLMap.js +116 -0
  32. package/browser/dist/nodes/YAMLSeq.js +105 -0
  33. package/browser/dist/nodes/addPairToJSMap.js +103 -0
  34. package/browser/dist/nodes/toJS.js +35 -0
  35. package/browser/dist/options.js +14 -95
  36. package/browser/dist/parse/cst-scalar.js +219 -0
  37. package/browser/dist/parse/cst-stringify.js +61 -0
  38. package/browser/dist/parse/cst-visit.js +97 -0
  39. package/browser/dist/parse/cst.js +98 -0
  40. package/browser/dist/parse/lexer.js +656 -0
  41. package/browser/dist/parse/line-counter.js +39 -0
  42. package/browser/dist/parse/parser.js +876 -0
  43. package/browser/dist/public-api.js +101 -0
  44. package/browser/dist/schema/Schema.js +23 -0
  45. package/browser/dist/schema/common/map.js +42 -0
  46. package/browser/dist/schema/common/null.js +13 -0
  47. package/browser/dist/schema/common/seq.js +33 -0
  48. package/browser/dist/schema/common/string.js +14 -0
  49. package/browser/dist/schema/core/bool.js +19 -0
  50. package/browser/dist/schema/core/float.js +40 -0
  51. package/browser/dist/schema/core/int.js +38 -0
  52. package/browser/dist/schema/core/schema.js +23 -0
  53. package/browser/dist/schema/json/schema.js +62 -0
  54. package/browser/dist/schema/tags.js +79 -0
  55. package/browser/dist/schema/yaml-1.1/binary.js +66 -0
  56. package/browser/dist/schema/yaml-1.1/bool.js +26 -0
  57. package/browser/dist/schema/yaml-1.1/float.js +43 -0
  58. package/browser/dist/schema/yaml-1.1/int.js +71 -0
  59. package/browser/dist/schema/yaml-1.1/omap.js +73 -0
  60. package/browser/dist/schema/yaml-1.1/pairs.js +77 -0
  61. package/browser/dist/schema/yaml-1.1/schema.js +37 -0
  62. package/browser/dist/schema/yaml-1.1/set.js +87 -0
  63. package/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  64. package/browser/dist/stringify/foldFlowLines.js +121 -139
  65. package/browser/dist/stringify/stringify.js +87 -72
  66. package/browser/dist/stringify/stringifyCollection.js +122 -0
  67. package/browser/dist/stringify/stringifyComment.js +14 -0
  68. package/browser/dist/stringify/stringifyDocument.js +64 -0
  69. package/browser/dist/stringify/stringifyNumber.js +20 -23
  70. package/browser/dist/stringify/stringifyPair.js +111 -0
  71. package/browser/dist/stringify/stringifyString.js +295 -322
  72. package/browser/dist/util.js +4 -4
  73. package/browser/dist/visit.js +146 -0
  74. package/browser/index.js +4 -1
  75. package/dist/compose/compose-collection.d.ts +5 -0
  76. package/dist/compose/compose-collection.js +61 -0
  77. package/dist/compose/compose-doc.d.ts +6 -0
  78. package/dist/compose/compose-doc.js +41 -0
  79. package/dist/compose/compose-node.d.ts +25 -0
  80. package/dist/compose/compose-node.js +75 -0
  81. package/dist/compose/compose-scalar.d.ts +5 -0
  82. package/dist/compose/compose-scalar.js +76 -0
  83. package/dist/compose/composer.d.ts +62 -0
  84. package/dist/compose/composer.js +222 -0
  85. package/dist/compose/resolve-block-map.d.ts +6 -0
  86. package/dist/compose/resolve-block-map.js +95 -0
  87. package/dist/compose/resolve-block-scalar.d.ts +10 -0
  88. package/dist/compose/resolve-block-scalar.js +187 -0
  89. package/dist/compose/resolve-block-seq.d.ts +5 -0
  90. package/dist/compose/resolve-block-seq.js +42 -0
  91. package/dist/compose/resolve-end.d.ts +6 -0
  92. package/dist/compose/resolve-end.js +39 -0
  93. package/dist/compose/resolve-flow-collection.d.ts +6 -0
  94. package/dist/compose/resolve-flow-collection.js +191 -0
  95. package/dist/compose/resolve-flow-scalar.d.ts +10 -0
  96. package/dist/compose/resolve-flow-scalar.js +213 -0
  97. package/dist/compose/resolve-props.d.ts +21 -0
  98. package/dist/compose/resolve-props.js +128 -0
  99. package/dist/compose/util-contains-newline.d.ts +2 -0
  100. package/dist/compose/util-contains-newline.js +36 -0
  101. package/dist/compose/util-empty-scalar-position.d.ts +2 -0
  102. package/dist/compose/util-empty-scalar-position.js +29 -0
  103. package/dist/compose/util-map-includes.d.ts +4 -0
  104. package/dist/compose/util-map-includes.js +19 -0
  105. package/dist/doc/Document.d.ts +130 -0
  106. package/dist/doc/Document.js +250 -347
  107. package/dist/doc/anchors.d.ts +24 -0
  108. package/dist/doc/anchors.js +77 -0
  109. package/dist/doc/applyReviver.d.ts +9 -0
  110. package/dist/doc/applyReviver.js +41 -28
  111. package/dist/doc/createNode.d.ts +16 -0
  112. package/dist/doc/createNode.js +71 -55
  113. package/dist/doc/directives.d.ts +46 -0
  114. package/dist/doc/directives.js +163 -0
  115. package/dist/errors.d.ts +21 -0
  116. package/dist/errors.js +51 -74
  117. package/dist/index.d.ts +19 -0
  118. package/dist/index.js +40 -71
  119. package/dist/log.d.ts +3 -0
  120. package/dist/log.js +11 -6
  121. package/dist/nodes/Alias.d.ts +24 -0
  122. package/dist/nodes/Alias.js +96 -0
  123. package/dist/nodes/Collection.d.ts +67 -0
  124. package/dist/nodes/Collection.js +137 -0
  125. package/dist/nodes/Node.d.ts +48 -0
  126. package/dist/nodes/Node.js +59 -0
  127. package/dist/nodes/Pair.d.ts +16 -0
  128. package/dist/nodes/Pair.js +31 -0
  129. package/dist/nodes/Scalar.d.ts +40 -0
  130. package/dist/nodes/Scalar.js +26 -0
  131. package/dist/nodes/YAMLMap.d.ts +39 -0
  132. package/dist/nodes/YAMLMap.js +119 -0
  133. package/dist/nodes/YAMLSeq.d.ts +53 -0
  134. package/dist/nodes/YAMLSeq.js +107 -0
  135. package/dist/nodes/addPairToJSMap.d.ts +3 -0
  136. package/dist/nodes/addPairToJSMap.js +105 -0
  137. package/dist/nodes/toJS.d.ts +30 -0
  138. package/dist/nodes/toJS.js +37 -0
  139. package/dist/options.d.ts +278 -0
  140. package/dist/options.js +13 -96
  141. package/dist/parse/cst-scalar.d.ts +58 -0
  142. package/dist/parse/cst-scalar.js +223 -0
  143. package/dist/parse/cst-stringify.d.ts +8 -0
  144. package/dist/parse/cst-stringify.js +63 -0
  145. package/dist/parse/cst-visit.d.ts +39 -0
  146. package/dist/parse/cst-visit.js +99 -0
  147. package/dist/parse/cst.d.ts +106 -0
  148. package/dist/parse/cst.js +112 -0
  149. package/dist/parse/lexer.d.ts +85 -0
  150. package/dist/parse/lexer.js +658 -0
  151. package/dist/parse/line-counter.d.ts +22 -0
  152. package/dist/parse/line-counter.js +41 -0
  153. package/dist/parse/parser.d.ts +84 -0
  154. package/dist/parse/parser.js +880 -0
  155. package/dist/public-api.d.ts +43 -0
  156. package/dist/public-api.js +106 -0
  157. package/dist/schema/Schema.d.ts +16 -0
  158. package/dist/schema/Schema.js +25 -0
  159. package/dist/schema/common/map.d.ts +2 -0
  160. package/dist/schema/common/map.js +44 -0
  161. package/dist/schema/common/null.d.ts +4 -0
  162. package/dist/schema/common/null.js +15 -0
  163. package/dist/schema/common/seq.d.ts +2 -0
  164. package/dist/schema/common/seq.js +35 -0
  165. package/dist/schema/common/string.d.ts +2 -0
  166. package/dist/schema/common/string.js +16 -0
  167. package/dist/schema/core/bool.d.ts +4 -0
  168. package/dist/schema/core/bool.js +21 -0
  169. package/dist/schema/core/float.d.ts +4 -0
  170. package/dist/schema/core/float.js +44 -0
  171. package/dist/schema/core/int.d.ts +4 -0
  172. package/dist/schema/core/int.js +42 -0
  173. package/dist/schema/core/schema.d.ts +1 -0
  174. package/dist/schema/core/schema.js +25 -0
  175. package/dist/schema/json/schema.d.ts +2 -0
  176. package/dist/schema/json/schema.js +64 -0
  177. package/dist/schema/tags.d.ts +41 -0
  178. package/dist/schema/tags.js +82 -0
  179. package/dist/schema/types.d.ts +82 -0
  180. package/dist/schema/yaml-1.1/binary.d.ts +2 -0
  181. package/dist/schema/yaml-1.1/binary.js +68 -0
  182. package/dist/schema/yaml-1.1/bool.d.ts +7 -0
  183. package/dist/schema/yaml-1.1/bool.js +29 -0
  184. package/dist/schema/yaml-1.1/float.d.ts +4 -0
  185. package/dist/schema/yaml-1.1/float.js +47 -0
  186. package/dist/schema/yaml-1.1/int.d.ts +5 -0
  187. package/dist/schema/yaml-1.1/int.js +76 -0
  188. package/dist/schema/yaml-1.1/omap.d.ts +21 -0
  189. package/dist/schema/yaml-1.1/omap.js +76 -0
  190. package/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  191. package/dist/schema/yaml-1.1/pairs.js +81 -0
  192. package/dist/schema/yaml-1.1/schema.d.ts +1 -0
  193. package/dist/schema/yaml-1.1/schema.js +39 -0
  194. package/dist/schema/yaml-1.1/set.d.ts +22 -0
  195. package/dist/schema/yaml-1.1/set.js +90 -0
  196. package/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  197. package/dist/schema/yaml-1.1/timestamp.js +105 -0
  198. package/dist/stringify/foldFlowLines.d.ts +34 -0
  199. package/dist/stringify/foldFlowLines.js +121 -139
  200. package/dist/stringify/stringify.d.ts +18 -0
  201. package/dist/stringify/stringify.js +87 -71
  202. package/dist/stringify/stringifyCollection.d.ts +21 -0
  203. package/dist/stringify/stringifyCollection.js +124 -0
  204. package/dist/stringify/stringifyComment.d.ts +2 -0
  205. package/dist/stringify/stringifyComment.js +17 -0
  206. package/dist/stringify/stringifyDocument.d.ts +3 -0
  207. package/dist/stringify/stringifyDocument.js +66 -0
  208. package/dist/stringify/stringifyNumber.d.ts +2 -0
  209. package/dist/stringify/stringifyNumber.js +20 -23
  210. package/dist/stringify/stringifyPair.d.ts +3 -0
  211. package/dist/stringify/stringifyPair.js +113 -0
  212. package/dist/stringify/stringifyString.d.ts +3 -0
  213. package/dist/stringify/stringifyString.js +295 -322
  214. package/dist/test-events.d.ts +4 -0
  215. package/dist/test-events.js +124 -148
  216. package/dist/util.d.ts +6 -0
  217. package/dist/util.js +9 -12
  218. package/dist/visit.d.ts +63 -0
  219. package/dist/visit.js +148 -0
  220. package/package.json +31 -39
  221. package/util.js +2 -14
  222. package/browser/dist/_virtual/_rollupPluginBabelHelpers.js +0 -16
  223. package/browser/dist/ast/Alias.js +0 -95
  224. package/browser/dist/ast/Collection.js +0 -192
  225. package/browser/dist/ast/Merge.js +0 -71
  226. package/browser/dist/ast/Node.js +0 -3
  227. package/browser/dist/ast/Pair.js +0 -200
  228. package/browser/dist/ast/Scalar.js +0 -21
  229. package/browser/dist/ast/YAMLMap.js +0 -91
  230. package/browser/dist/ast/YAMLSeq.js +0 -67
  231. package/browser/dist/ast/toJS.js +0 -29
  232. package/browser/dist/ast/visit.js +0 -83
  233. package/browser/dist/constants.js +0 -40
  234. package/browser/dist/cst/Alias.js +0 -26
  235. package/browser/dist/cst/BlankLine.js +0 -34
  236. package/browser/dist/cst/BlockValue.js +0 -240
  237. package/browser/dist/cst/Collection.js +0 -259
  238. package/browser/dist/cst/CollectionItem.js +0 -123
  239. package/browser/dist/cst/Comment.js +0 -27
  240. package/browser/dist/cst/Directive.js +0 -53
  241. package/browser/dist/cst/Document.js +0 -262
  242. package/browser/dist/cst/FlowCollection.js +0 -201
  243. package/browser/dist/cst/Node.js +0 -355
  244. package/browser/dist/cst/ParseContext.js +0 -234
  245. package/browser/dist/cst/PlainValue.js +0 -171
  246. package/browser/dist/cst/QuoteDouble.js +0 -224
  247. package/browser/dist/cst/QuoteSingle.js +0 -100
  248. package/browser/dist/cst/Range.js +0 -56
  249. package/browser/dist/cst/parse.js +0 -46
  250. package/browser/dist/cst/source-utils.js +0 -169
  251. package/browser/dist/doc/Anchors.js +0 -115
  252. package/browser/dist/doc/Schema.js +0 -34
  253. package/browser/dist/doc/getSchemaTags.js +0 -33
  254. package/browser/dist/doc/listTagNames.js +0 -27
  255. package/browser/dist/doc/parseContents.js +0 -60
  256. package/browser/dist/doc/parseDirectives.js +0 -107
  257. package/browser/dist/resolve/collection-utils.js +0 -86
  258. package/browser/dist/resolve/resolveMap.js +0 -315
  259. package/browser/dist/resolve/resolveNode.js +0 -173
  260. package/browser/dist/resolve/resolveScalar.js +0 -20
  261. package/browser/dist/resolve/resolveSeq.js +0 -170
  262. package/browser/dist/resolve/resolveTag.js +0 -107
  263. package/browser/dist/resolve/resolveTagName.js +0 -87
  264. package/browser/dist/stringify/addComment.js +0 -10
  265. package/browser/dist/stringify/stringifyTag.js +0 -28
  266. package/browser/dist/tags/core.js +0 -128
  267. package/browser/dist/tags/failsafe/index.js +0 -7
  268. package/browser/dist/tags/failsafe/map.js +0 -37
  269. package/browser/dist/tags/failsafe/seq.js +0 -34
  270. package/browser/dist/tags/failsafe/string.js +0 -20
  271. package/browser/dist/tags/index.js +0 -39
  272. package/browser/dist/tags/json.js +0 -62
  273. package/browser/dist/tags/options.js +0 -31
  274. package/browser/dist/tags/yaml-1.1/binary.js +0 -83
  275. package/browser/dist/tags/yaml-1.1/index.js +0 -174
  276. package/browser/dist/tags/yaml-1.1/omap.js +0 -86
  277. package/browser/dist/tags/yaml-1.1/pairs.js +0 -62
  278. package/browser/dist/tags/yaml-1.1/set.js +0 -78
  279. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -101
  280. package/browser/dist/types.js +0 -10
  281. package/cst.d.ts +0 -185
  282. package/dist/_virtual/_rollupPluginBabelHelpers.js +0 -18
  283. package/dist/ast/Alias.js +0 -97
  284. package/dist/ast/Collection.js +0 -196
  285. package/dist/ast/Merge.js +0 -74
  286. package/dist/ast/Node.js +0 -5
  287. package/dist/ast/Pair.js +0 -203
  288. package/dist/ast/Scalar.js +0 -24
  289. package/dist/ast/YAMLMap.js +0 -94
  290. package/dist/ast/YAMLSeq.js +0 -69
  291. package/dist/ast/toJS.js +0 -31
  292. package/dist/ast/visit.js +0 -85
  293. package/dist/constants.js +0 -46
  294. package/dist/cst/Alias.js +0 -28
  295. package/dist/cst/BlankLine.js +0 -36
  296. package/dist/cst/BlockValue.js +0 -243
  297. package/dist/cst/Collection.js +0 -262
  298. package/dist/cst/CollectionItem.js +0 -125
  299. package/dist/cst/Comment.js +0 -29
  300. package/dist/cst/Directive.js +0 -55
  301. package/dist/cst/Document.js +0 -264
  302. package/dist/cst/FlowCollection.js +0 -203
  303. package/dist/cst/Node.js +0 -357
  304. package/dist/cst/ParseContext.js +0 -236
  305. package/dist/cst/PlainValue.js +0 -173
  306. package/dist/cst/QuoteDouble.js +0 -226
  307. package/dist/cst/QuoteSingle.js +0 -102
  308. package/dist/cst/Range.js +0 -58
  309. package/dist/cst/parse.js +0 -48
  310. package/dist/cst/source-utils.js +0 -173
  311. package/dist/doc/Anchors.js +0 -117
  312. package/dist/doc/Schema.js +0 -36
  313. package/dist/doc/getSchemaTags.js +0 -35
  314. package/dist/doc/listTagNames.js +0 -29
  315. package/dist/doc/parseContents.js +0 -62
  316. package/dist/doc/parseDirectives.js +0 -109
  317. package/dist/resolve/collection-utils.js +0 -91
  318. package/dist/resolve/resolveMap.js +0 -317
  319. package/dist/resolve/resolveNode.js +0 -175
  320. package/dist/resolve/resolveScalar.js +0 -22
  321. package/dist/resolve/resolveSeq.js +0 -172
  322. package/dist/resolve/resolveTag.js +0 -109
  323. package/dist/resolve/resolveTagName.js +0 -89
  324. package/dist/stringify/addComment.js +0 -13
  325. package/dist/stringify/stringifyTag.js +0 -30
  326. package/dist/tags/core.js +0 -138
  327. package/dist/tags/failsafe/index.js +0 -9
  328. package/dist/tags/failsafe/map.js +0 -39
  329. package/dist/tags/failsafe/seq.js +0 -36
  330. package/dist/tags/failsafe/string.js +0 -22
  331. package/dist/tags/index.js +0 -42
  332. package/dist/tags/json.js +0 -64
  333. package/dist/tags/options.js +0 -37
  334. package/dist/tags/yaml-1.1/binary.js +0 -85
  335. package/dist/tags/yaml-1.1/index.js +0 -176
  336. package/dist/tags/yaml-1.1/omap.js +0 -89
  337. package/dist/tags/yaml-1.1/pairs.js +0 -66
  338. package/dist/tags/yaml-1.1/set.js +0 -81
  339. package/dist/tags/yaml-1.1/timestamp.js +0 -105
  340. package/dist/types.js +0 -29
  341. package/index.d.ts +0 -519
  342. package/index.js +0 -1
  343. package/types.d.ts +0 -379
  344. package/types.js +0 -17
  345. package/types.mjs +0 -17
  346. package/util.d.ts +0 -76
  347. package/util.mjs +0 -15
@@ -1,109 +0,0 @@
1
- 'use strict';
2
-
3
- var Collection = require('../ast/Collection.js');
4
- var Scalar = require('../ast/Scalar.js');
5
- var constants = require('../constants.js');
6
- var errors = require('../errors.js');
7
- var resolveMap = require('./resolveMap.js');
8
- var resolveScalar = require('./resolveScalar.js');
9
- var resolveSeq = require('./resolveSeq.js');
10
-
11
- function resolveByTagName({
12
- knownTags,
13
- tags
14
- }, tagName, value, onError) {
15
- const matchWithTest = [];
16
-
17
- for (const tag of tags) {
18
- if (tag.tag === tagName) {
19
- if (tag.test) {
20
- if (typeof value === 'string') matchWithTest.push(tag);else onError(`The tag ${tagName} cannot be applied to a collection`);
21
- } else {
22
- const res = tag.resolve(value, onError);
23
- return res instanceof Collection.Collection ? res : new Scalar.Scalar(res);
24
- }
25
- }
26
- }
27
-
28
- if (matchWithTest.length > 0) return resolveScalar.resolveScalar(value, matchWithTest);
29
- const kt = knownTags[tagName];
30
-
31
- if (kt) {
32
- tags.push(Object.assign({}, kt, {
33
- default: false,
34
- test: undefined
35
- }));
36
- const res = kt.resolve(value, onError);
37
- return res instanceof Collection.Collection ? res : new Scalar.Scalar(res);
38
- }
39
-
40
- return null;
41
- }
42
-
43
- function resolveTag(doc, node, tagName) {
44
- const {
45
- MAP,
46
- SEQ,
47
- STR
48
- } = constants.defaultTags;
49
- let value, fallback;
50
-
51
- const onError = message => doc.errors.push(new errors.YAMLSemanticError(node, message));
52
-
53
- try {
54
- switch (node.type) {
55
- case constants.Type.FLOW_MAP:
56
- case constants.Type.MAP:
57
- value = resolveMap.resolveMap(doc, node);
58
- fallback = MAP;
59
- if (tagName === SEQ || tagName === STR) onError(`The tag ${tagName} cannot be applied to a mapping`);
60
- break;
61
-
62
- case constants.Type.FLOW_SEQ:
63
- case constants.Type.SEQ:
64
- value = resolveSeq.resolveSeq(doc, node);
65
- fallback = SEQ;
66
- if (tagName === MAP || tagName === STR) onError(`The tag ${tagName} cannot be applied to a sequence`);
67
- break;
68
-
69
- default:
70
- value = node.strValue || '';
71
-
72
- if (typeof value !== 'string') {
73
- value.errors.forEach(error => doc.errors.push(error));
74
- value = value.str;
75
- }
76
-
77
- if (tagName === MAP || tagName === SEQ) onError(`The tag ${tagName} cannot be applied to a scalar`);
78
- fallback = STR;
79
- }
80
-
81
- const res = resolveByTagName(doc.schema, tagName, value, onError);
82
-
83
- if (res) {
84
- if (tagName && node.tag) res.tag = tagName;
85
- return res;
86
- }
87
- } catch (error) {
88
- /* istanbul ignore if */
89
- if (!error.source) error.source = node;
90
- doc.errors.push(error);
91
- return null;
92
- }
93
-
94
- try {
95
- if (!fallback) throw new Error(`The tag ${tagName} is unavailable`);
96
- const msg = `The tag ${tagName} is unavailable, falling back to ${fallback}`;
97
- doc.warnings.push(new errors.YAMLWarning(node, msg));
98
- const res = resolveByTagName(doc.schema, fallback, value, onError);
99
- res.tag = tagName;
100
- return res;
101
- } catch (error) {
102
- const refError = new errors.YAMLReferenceError(node, error.message);
103
- refError.stack = error.stack;
104
- doc.errors.push(refError);
105
- return null;
106
- }
107
- }
108
-
109
- exports.resolveTag = resolveTag;
@@ -1,89 +0,0 @@
1
- 'use strict';
2
-
3
- var constants = require('../constants.js');
4
- var errors = require('../errors.js');
5
-
6
- function resolveTagHandle(doc, node) {
7
- const {
8
- handle,
9
- suffix
10
- } = node.tag;
11
- let prefix = doc.tagPrefixes.find(p => p.handle === handle);
12
-
13
- if (!prefix) {
14
- const dtp = doc.getDefaults().tagPrefixes;
15
- if (dtp) prefix = dtp.find(p => p.handle === handle);
16
- if (!prefix) throw new errors.YAMLSemanticError(node, `The ${handle} tag handle is non-default and was not declared.`);
17
- }
18
-
19
- if (!suffix) throw new errors.YAMLSemanticError(node, `The ${handle} tag has no suffix.`);
20
-
21
- if (handle === '!' && (doc.version || doc.options.version) === '1.0') {
22
- if (suffix[0] === '^') {
23
- doc.warnings.push(new errors.YAMLWarning(node, 'YAML 1.0 ^ tag expansion is not supported'));
24
- return suffix;
25
- }
26
-
27
- if (/[:/]/.test(suffix)) {
28
- // word/foo -> tag:word.yaml.org,2002:foo
29
- const vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i);
30
- return vocab ? `tag:${vocab[1]}.yaml.org,2002:${vocab[2]}` : `tag:${suffix}`;
31
- }
32
- }
33
-
34
- return prefix.prefix + decodeURIComponent(suffix);
35
- }
36
-
37
- function resolveTagName(doc, node) {
38
- const {
39
- tag,
40
- type
41
- } = node;
42
- let nonSpecific = false;
43
-
44
- if (tag) {
45
- const {
46
- handle,
47
- suffix,
48
- verbatim
49
- } = tag;
50
-
51
- if (verbatim) {
52
- if (verbatim !== '!' && verbatim !== '!!') return verbatim;
53
- const msg = `Verbatim tags aren't resolved, so ${verbatim} is invalid.`;
54
- doc.errors.push(new errors.YAMLSemanticError(node, msg));
55
- } else if (handle === '!' && !suffix) {
56
- nonSpecific = true;
57
- } else {
58
- try {
59
- return resolveTagHandle(doc, node);
60
- } catch (error) {
61
- doc.errors.push(error);
62
- }
63
- }
64
- }
65
-
66
- switch (type) {
67
- case constants.Type.BLOCK_FOLDED:
68
- case constants.Type.BLOCK_LITERAL:
69
- case constants.Type.QUOTE_DOUBLE:
70
- case constants.Type.QUOTE_SINGLE:
71
- return constants.defaultTags.STR;
72
-
73
- case constants.Type.FLOW_MAP:
74
- case constants.Type.MAP:
75
- return constants.defaultTags.MAP;
76
-
77
- case constants.Type.FLOW_SEQ:
78
- case constants.Type.SEQ:
79
- return constants.defaultTags.SEQ;
80
-
81
- case constants.Type.PLAIN:
82
- return nonSpecific ? constants.defaultTags.STR : null;
83
-
84
- default:
85
- return null;
86
- }
87
- }
88
-
89
- exports.resolveTagName = resolveTagName;
@@ -1,13 +0,0 @@
1
- 'use strict';
2
-
3
- function addCommentBefore(str, indent, comment) {
4
- if (!comment) return str;
5
- const cc = comment.replace(/[\s\S]^/gm, `$&${indent}#`);
6
- return `#${cc}\n${indent}${str}`;
7
- }
8
- function addComment(str, indent, comment) {
9
- return !comment ? str : comment.indexOf('\n') === -1 ? `${str} #${comment}` : `${str}\n` + comment.replace(/^/gm, `${indent || ''}#`);
10
- }
11
-
12
- exports.addComment = addComment;
13
- exports.addCommentBefore = addCommentBefore;
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- function stringifyTag(doc, tag) {
4
- if ((doc.version || doc.options.version) === '1.0') {
5
- const priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/);
6
- if (priv) return '!' + priv[1];
7
- const vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/);
8
- return vocab ? `!${vocab[1]}/${vocab[2]}` : `!${tag.replace(/^tag:/, '')}`;
9
- }
10
-
11
- let p = doc.tagPrefixes.find(p => tag.indexOf(p.prefix) === 0);
12
-
13
- if (!p) {
14
- const dtp = doc.getDefaults().tagPrefixes;
15
- p = dtp && dtp.find(p => tag.indexOf(p.prefix) === 0);
16
- }
17
-
18
- if (!p) return tag[0] === '!' ? tag : `!<${tag}>`;
19
- const suffix = tag.substr(p.prefix.length).replace(/[!,[\]{}]/g, ch => ({
20
- '!': '%21',
21
- ',': '%2C',
22
- '[': '%5B',
23
- ']': '%5D',
24
- '{': '%7B',
25
- '}': '%7D'
26
- })[ch]);
27
- return p.handle + suffix;
28
- }
29
-
30
- exports.stringifyTag = stringifyTag;
package/dist/tags/core.js DELETED
@@ -1,138 +0,0 @@
1
- 'use strict';
2
-
3
- var Scalar = require('../ast/Scalar.js');
4
- var stringifyNumber = require('../stringify/stringifyNumber.js');
5
- var index = require('./failsafe/index.js');
6
- var options = require('./options.js');
7
-
8
- /* global BigInt */
9
-
10
- const intIdentify = value => typeof value === 'bigint' || Number.isInteger(value);
11
-
12
- const intResolve = (src, offset, radix) => options.intOptions.asBigInt ? BigInt(src) : parseInt(src.substring(offset), radix);
13
-
14
- function intStringify(node, radix, prefix) {
15
- const {
16
- value
17
- } = node;
18
- if (intIdentify(value) && value >= 0) return prefix + value.toString(radix);
19
- return stringifyNumber.stringifyNumber(node);
20
- }
21
-
22
- function stringifyBool(node) {
23
- const {
24
- value,
25
- sourceStr
26
- } = node;
27
-
28
- if (sourceStr) {
29
- const match = boolObj.test.test(sourceStr);
30
- if (match && value === (sourceStr[0] === 't' || sourceStr[0] === 'T')) return sourceStr;
31
- }
32
-
33
- return value ? options.boolOptions.trueStr : options.boolOptions.falseStr;
34
- }
35
-
36
- const nullObj = {
37
- identify: value => value == null,
38
- createNode: (schema, value, ctx) => ctx.wrapScalars ? new Scalar.Scalar(null) : null,
39
- default: true,
40
- tag: 'tag:yaml.org,2002:null',
41
- test: /^(?:~|[Nn]ull|NULL)?$/,
42
- resolve: str => {
43
- const node = new Scalar.Scalar(null);
44
- node.sourceStr = str;
45
- return node;
46
- },
47
- options: options.nullOptions,
48
- stringify: ({
49
- sourceStr
50
- }) => sourceStr !== null && sourceStr !== void 0 ? sourceStr : options.nullOptions.nullStr
51
- };
52
- const boolObj = {
53
- identify: value => typeof value === 'boolean',
54
- default: true,
55
- tag: 'tag:yaml.org,2002:bool',
56
- test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
57
- resolve: str => {
58
- const node = new Scalar.Scalar(str[0] === 't' || str[0] === 'T');
59
- node.sourceStr = str;
60
- return node;
61
- },
62
- options: options.boolOptions,
63
- stringify: stringifyBool
64
- };
65
- const octObj = {
66
- identify: value => intIdentify(value) && value >= 0,
67
- default: true,
68
- tag: 'tag:yaml.org,2002:int',
69
- format: 'OCT',
70
- test: /^0o[0-7]+$/,
71
- resolve: str => intResolve(str, 2, 8),
72
- options: options.intOptions,
73
- stringify: node => intStringify(node, 8, '0o')
74
- };
75
- const intObj = {
76
- identify: intIdentify,
77
- default: true,
78
- tag: 'tag:yaml.org,2002:int',
79
- test: /^[-+]?[0-9]+$/,
80
- resolve: str => intResolve(str, 0, 10),
81
- options: options.intOptions,
82
- stringify: stringifyNumber.stringifyNumber
83
- };
84
- const hexObj = {
85
- identify: value => intIdentify(value) && value >= 0,
86
- default: true,
87
- tag: 'tag:yaml.org,2002:int',
88
- format: 'HEX',
89
- test: /^0x[0-9a-fA-F]+$/,
90
- resolve: str => intResolve(str, 2, 16),
91
- options: options.intOptions,
92
- stringify: node => intStringify(node, 16, '0x')
93
- };
94
- const nanObj = {
95
- identify: value => typeof value === 'number',
96
- default: true,
97
- tag: 'tag:yaml.org,2002:float',
98
- test: /^(?:[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN))$/,
99
- resolve: str => str.slice(-3).toLowerCase() === 'nan' ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
100
- stringify: stringifyNumber.stringifyNumber
101
- };
102
- const expObj = {
103
- identify: value => typeof value === 'number',
104
- default: true,
105
- tag: 'tag:yaml.org,2002:float',
106
- format: 'EXP',
107
- test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
108
- resolve: str => parseFloat(str),
109
- stringify: ({
110
- value
111
- }) => Number(value).toExponential()
112
- };
113
- const floatObj = {
114
- identify: value => typeof value === 'number',
115
- default: true,
116
- tag: 'tag:yaml.org,2002:float',
117
- test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
118
-
119
- resolve(str) {
120
- const node = new Scalar.Scalar(parseFloat(str));
121
- const dot = str.indexOf('.');
122
- if (dot !== -1 && str[str.length - 1] === '0') node.minFractionDigits = str.length - dot - 1;
123
- return node;
124
- },
125
-
126
- stringify: stringifyNumber.stringifyNumber
127
- };
128
- const core = index.failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
129
-
130
- exports.boolObj = boolObj;
131
- exports.core = core;
132
- exports.expObj = expObj;
133
- exports.floatObj = floatObj;
134
- exports.hexObj = hexObj;
135
- exports.intObj = intObj;
136
- exports.nanObj = nanObj;
137
- exports.nullObj = nullObj;
138
- exports.octObj = octObj;
@@ -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,39 +0,0 @@
1
- 'use strict';
2
-
3
- var Pair = require('../../ast/Pair.js');
4
- var YAMLMap = require('../../ast/YAMLMap.js');
5
-
6
- function createMap(schema, obj, ctx) {
7
- const {
8
- keepUndefined,
9
- replacer
10
- } = ctx;
11
- const map = new YAMLMap.YAMLMap(schema);
12
-
13
- const add = (key, value) => {
14
- if (typeof replacer === 'function') value = replacer.call(obj, key, value);else if (Array.isArray(replacer) && !replacer.includes(key)) return;
15
- if (value !== undefined || keepUndefined) map.items.push(Pair.createPair(key, value, ctx));
16
- };
17
-
18
- if (obj instanceof Map) {
19
- for (const [key, value] of obj) add(key, value);
20
- } else if (obj && typeof obj === 'object') {
21
- for (const key of Object.keys(obj)) add(key, obj[key]);
22
- }
23
-
24
- if (typeof schema.sortMapEntries === 'function') {
25
- map.items.sort(schema.sortMapEntries);
26
- }
27
-
28
- return map;
29
- }
30
-
31
- const map = {
32
- createNode: createMap,
33
- default: true,
34
- nodeClass: YAMLMap.YAMLMap,
35
- tag: 'tag:yaml.org,2002:map',
36
- resolve: map => map
37
- };
38
-
39
- exports.map = map;
@@ -1,36 +0,0 @@
1
- 'use strict';
2
-
3
- var YAMLSeq = require('../../ast/YAMLSeq.js');
4
- var createNode = require('../../doc/createNode.js');
5
-
6
- function createSeq(schema, obj, ctx) {
7
- const {
8
- replacer
9
- } = ctx;
10
- const seq = new YAMLSeq.YAMLSeq(schema);
11
-
12
- if (obj && obj[Symbol.iterator]) {
13
- let i = 0;
14
-
15
- for (let it of obj) {
16
- if (typeof replacer === 'function') {
17
- const key = obj instanceof Set ? it : String(i++);
18
- it = replacer.call(obj, key, it);
19
- }
20
-
21
- seq.items.push(createNode.createNode(it, null, ctx));
22
- }
23
- }
24
-
25
- return seq;
26
- }
27
-
28
- const seq = {
29
- createNode: createSeq,
30
- default: true,
31
- nodeClass: YAMLSeq.YAMLSeq,
32
- tag: 'tag:yaml.org,2002:seq',
33
- resolve: seq => seq
34
- };
35
-
36
- exports.seq = seq;
@@ -1,22 +0,0 @@
1
- 'use strict';
2
-
3
- var stringifyString = require('../../stringify/stringifyString.js');
4
- var options = require('../options.js');
5
-
6
- const string = {
7
- identify: value => typeof value === 'string',
8
- default: true,
9
- tag: 'tag:yaml.org,2002:str',
10
- resolve: str => str,
11
-
12
- stringify(item, ctx, onComment, onChompKeep) {
13
- ctx = Object.assign({
14
- actualString: true
15
- }, ctx);
16
- return stringifyString.stringifyString(item, ctx, onComment, onChompKeep);
17
- },
18
-
19
- options: options.strOptions
20
- };
21
-
22
- exports.string = string;
@@ -1,42 +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 = {
16
- core: core.core,
17
- failsafe: index.failsafe,
18
- json: json.json,
19
- yaml11: index$1.yaml11
20
- };
21
- const tags = {
22
- binary: binary.binary,
23
- bool: core.boolObj,
24
- float: core.floatObj,
25
- floatExp: core.expObj,
26
- floatNaN: core.nanObj,
27
- floatTime: timestamp.floatTime,
28
- int: core.intObj,
29
- intHex: core.hexObj,
30
- intOct: core.octObj,
31
- intTime: timestamp.intTime,
32
- map: map.map,
33
- null: core.nullObj,
34
- omap: omap.omap,
35
- pairs: pairs.pairs,
36
- seq: seq.seq,
37
- set: set.set,
38
- timestamp: timestamp.timestamp
39
- };
40
-
41
- exports.schemas = schemas;
42
- exports.tags = tags;
package/dist/tags/json.js DELETED
@@ -1,64 +0,0 @@
1
- 'use strict';
2
-
3
- var Scalar = require('../ast/Scalar.js');
4
- var map = require('./failsafe/map.js');
5
- var seq = require('./failsafe/seq.js');
6
- var options = require('./options.js');
7
-
8
- /* global BigInt */
9
-
10
- const intIdentify = value => typeof value === 'bigint' || Number.isInteger(value);
11
-
12
- const stringifyJSON = ({
13
- value
14
- }) => JSON.stringify(value);
15
-
16
- const json = [map.map, seq.seq, {
17
- identify: value => typeof value === 'string',
18
- default: true,
19
- tag: 'tag:yaml.org,2002:str',
20
- resolve: str => str,
21
- stringify: stringifyJSON
22
- }, {
23
- identify: value => value == null,
24
- createNode: (schema, value, ctx) => ctx.wrapScalars ? new Scalar.Scalar(null) : null,
25
- default: true,
26
- tag: 'tag:yaml.org,2002:null',
27
- test: /^null$/,
28
- resolve: () => null,
29
- stringify: stringifyJSON
30
- }, {
31
- identify: value => typeof value === 'boolean',
32
- default: true,
33
- tag: 'tag:yaml.org,2002:bool',
34
- test: /^true|false$/,
35
- resolve: str => str === 'true',
36
- stringify: stringifyJSON
37
- }, {
38
- identify: intIdentify,
39
- default: true,
40
- tag: 'tag:yaml.org,2002:int',
41
- test: /^-?(?:0|[1-9][0-9]*)$/,
42
- resolve: str => options.intOptions.asBigInt ? BigInt(str) : parseInt(str, 10),
43
- stringify: ({
44
- value
45
- }) => intIdentify(value) ? value.toString() : JSON.stringify(value)
46
- }, {
47
- identify: value => typeof value === 'number',
48
- default: true,
49
- tag: 'tag:yaml.org,2002:float',
50
- test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
51
- resolve: str => parseFloat(str),
52
- stringify: stringifyJSON
53
- }, {
54
- default: true,
55
- test: /^/,
56
-
57
- resolve(str, onError) {
58
- onError(`Unresolved plain scalar ${JSON.stringify(str)}`);
59
- return str;
60
- }
61
-
62
- }];
63
-
64
- exports.json = json;
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- var constants = require('../constants.js');
4
-
5
- const binaryOptions = {
6
- defaultType: constants.Type.BLOCK_LITERAL,
7
- lineWidth: 76
8
- };
9
- const boolOptions = {
10
- trueStr: 'true',
11
- falseStr: 'false'
12
- };
13
- const intOptions = {
14
- asBigInt: false
15
- };
16
- const nullOptions = {
17
- nullStr: 'null'
18
- };
19
- const strOptions = {
20
- defaultType: constants.Type.PLAIN,
21
- defaultKeyType: constants.Type.PLAIN,
22
- defaultQuoteSingle: false,
23
- doubleQuoted: {
24
- jsonEncoding: false,
25
- minMultiLineLength: 40
26
- },
27
- fold: {
28
- lineWidth: 80,
29
- minContentWidth: 20
30
- }
31
- };
32
-
33
- exports.binaryOptions = binaryOptions;
34
- exports.boolOptions = boolOptions;
35
- exports.intOptions = intOptions;
36
- exports.nullOptions = nullOptions;
37
- exports.strOptions = strOptions;