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
@@ -0,0 +1,278 @@
1
+ import type { Reviver } from './doc/applyReviver.js';
2
+ import type { Directives } from './doc/directives.js';
3
+ import type { LogLevelId } from './log.js';
4
+ import type { ParsedNode } from './nodes/Node.js';
5
+ import type { Pair } from './nodes/Pair.js';
6
+ import type { Scalar } from './nodes/Scalar.js';
7
+ import type { LineCounter } from './parse/line-counter.js';
8
+ import type { SchemaName } from './schema/Schema.js';
9
+ import type { Tags } from './schema/tags.js';
10
+ import type { CollectionTag, ScalarTag } from './schema/types.js';
11
+ export declare type ParseOptions = {
12
+ /**
13
+ * Whether integers should be parsed into BigInt rather than number values.
14
+ *
15
+ * Default: `false`
16
+ *
17
+ * https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/BigInt
18
+ */
19
+ intAsBigInt?: boolean;
20
+ /**
21
+ * If set, newlines will be tracked, to allow for `lineCounter.linePos(offset)`
22
+ * to provide the `{ line, col }` positions within the input.
23
+ */
24
+ lineCounter?: LineCounter;
25
+ /**
26
+ * Include line/col position & node type directly in parse errors.
27
+ *
28
+ * Default: `true`
29
+ */
30
+ prettyErrors?: boolean;
31
+ /**
32
+ * Detect and report errors that are required by the YAML 1.2 spec,
33
+ * but are caused by unambiguous content.
34
+ *
35
+ * Default: `true`
36
+ */
37
+ strict?: boolean;
38
+ /**
39
+ * YAML requires map keys to be unique. By default, this is checked by
40
+ * comparing scalar values with `===`; deep equality is not checked for
41
+ * aliases or collections. If merge keys are enabled by the schema,
42
+ * multiple `<<` keys are allowed.
43
+ *
44
+ * Set `false` to disable, or provide your own comparator function to
45
+ * customise. The comparator will be passed two `ParsedNode` values, and
46
+ * is expected to return a `boolean` indicating their equality.
47
+ *
48
+ * Default: `true`
49
+ */
50
+ uniqueKeys?: boolean | ((a: ParsedNode, b: ParsedNode) => boolean);
51
+ };
52
+ export declare type DocumentOptions = {
53
+ /**
54
+ * Used internally by Composer. If set and includes an explicit version,
55
+ * that overrides the `version` option.
56
+ */
57
+ directives?: Directives;
58
+ /**
59
+ * Control the logging level during parsing
60
+ *
61
+ * Default: `'warn'`
62
+ */
63
+ logLevel?: LogLevelId;
64
+ /**
65
+ * The YAML version used by documents without a `%YAML` directive.
66
+ *
67
+ * Default: `"1.2"`
68
+ */
69
+ version?: '1.1' | '1.2';
70
+ };
71
+ export declare type SchemaOptions = {
72
+ /**
73
+ * Array of additional tags to include in the schema, or a function that may
74
+ * modify the schema's base tag array.
75
+ */
76
+ customTags?: Tags | ((tags: Tags) => Tags) | null;
77
+ /**
78
+ * Enable support for `<<` merge keys.
79
+ *
80
+ * Default: `false` for YAML 1.2, `true` for earlier versions
81
+ */
82
+ merge?: boolean;
83
+ /**
84
+ * When using the `'core'` schema, support parsing values with these
85
+ * explicit YAML 1.1 tags:
86
+ *
87
+ * `!!binary`, `!!omap`, `!!pairs`, `!!set`, `!!timestamp`.
88
+ *
89
+ * Default `true`
90
+ */
91
+ resolveKnownTags?: boolean;
92
+ /**
93
+ * The base schema to use.
94
+ *
95
+ * Default: `"core"` for YAML 1.2, `"yaml-1.1"` for earlier versions
96
+ */
97
+ schema?: SchemaName;
98
+ /**
99
+ * When adding to or stringifying a map, sort the entries.
100
+ * If `true`, sort by comparing key values with `<`.
101
+ * Does not affect item order when parsing.
102
+ *
103
+ * Default: `false`
104
+ */
105
+ sortMapEntries?: boolean | ((a: Pair, b: Pair) => number);
106
+ };
107
+ export declare type CreateNodeOptions = {
108
+ /**
109
+ * Default prefix for anchors.
110
+ *
111
+ * Default: `'a'`, resulting in anchors `a1`, `a2`, etc.
112
+ */
113
+ anchorPrefix?: string;
114
+ /** Force the top-level collection node to use flow style. */
115
+ flow?: boolean;
116
+ /**
117
+ * Keep `undefined` object values when creating mappings, rather than
118
+ * discarding them.
119
+ *
120
+ * Default: `false`
121
+ */
122
+ keepUndefined?: boolean | null;
123
+ onTagObj?: (tagObj: ScalarTag | CollectionTag) => void;
124
+ /**
125
+ * Specify the top-level collection type, e.g. `"!!omap"`. Note that this
126
+ * requires the corresponding tag to be available in this document's schema.
127
+ */
128
+ tag?: string;
129
+ };
130
+ export declare type ToJSOptions = {
131
+ /**
132
+ * Use Map rather than Object to represent mappings.
133
+ *
134
+ * Default: `false`
135
+ */
136
+ mapAsMap?: boolean;
137
+ /**
138
+ * Prevent exponential entity expansion attacks by limiting data aliasing count;
139
+ * set to `-1` to disable checks; `0` disallows all alias nodes.
140
+ *
141
+ * Default: `100`
142
+ */
143
+ maxAliasCount?: number;
144
+ /**
145
+ * If defined, called with the resolved `value` and reference `count` for
146
+ * each anchor in the document.
147
+ */
148
+ onAnchor?: (value: unknown, count: number) => void;
149
+ /**
150
+ * Optional function that may filter or modify the output JS value
151
+ *
152
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#using_the_reviver_parameter
153
+ */
154
+ reviver?: Reviver;
155
+ };
156
+ export declare type ToStringOptions = {
157
+ /**
158
+ * The default type of string literal used to stringify implicit key values.
159
+ * Output may use other types if required to fully represent the value.
160
+ *
161
+ * If `null`, the value of `defaultStringType` is used.
162
+ *
163
+ * Default: `null`
164
+ */
165
+ defaultKeyType?: Scalar.Type | null;
166
+ /**
167
+ * The default type of string literal used to stringify values in general.
168
+ * Output may use other types if required to fully represent the value.
169
+ *
170
+ * Default: `'PLAIN'`
171
+ */
172
+ defaultStringType?: Scalar.Type;
173
+ /**
174
+ * Include directives in the output.
175
+ *
176
+ * - If `true`, at least the document-start marker `---` is always included.
177
+ * This does not force the `%YAML` directive to be included. To do that,
178
+ * set `doc.directives.yaml.explicit = true`.
179
+ * - If `false`, no directives or marker is ever included. If using the `%TAG`
180
+ * directive, you are expected to include it manually in the stream before
181
+ * its use.
182
+ * - If `null`, directives and marker may be included if required.
183
+ *
184
+ * Default: `null`
185
+ */
186
+ directives?: boolean | null;
187
+ /**
188
+ * Restrict double-quoted strings to use JSON-compatible syntax.
189
+ *
190
+ * Default: `false`
191
+ */
192
+ doubleQuotedAsJSON?: boolean;
193
+ /**
194
+ * Minimum length for double-quoted strings to use multiple lines to
195
+ * represent the value. Ignored if `doubleQuotedAsJSON` is set.
196
+ *
197
+ * Default: `40`
198
+ */
199
+ doubleQuotedMinMultiLineLength?: number;
200
+ /**
201
+ * String representation for `false`.
202
+ * With the core schema, use `'false'`, `'False'`, or `'FALSE'`.
203
+ *
204
+ * Default: `'false'`
205
+ */
206
+ falseStr?: string;
207
+ /**
208
+ * The number of spaces to use when indenting code.
209
+ *
210
+ * Default: `2`
211
+ */
212
+ indent?: number;
213
+ /**
214
+ * Whether block sequences should be indented.
215
+ *
216
+ * Default: `true`
217
+ */
218
+ indentSeq?: boolean;
219
+ /**
220
+ * Maximum line width (set to `0` to disable folding).
221
+ *
222
+ * This is a soft limit, as only double-quoted semantics allow for inserting
223
+ * a line break in the middle of a word, as well as being influenced by the
224
+ * `minContentWidth` option.
225
+ *
226
+ * Default: `80`
227
+ */
228
+ lineWidth?: number;
229
+ /**
230
+ * Minimum line width for highly-indented content (set to `0` to disable).
231
+ *
232
+ * Default: `20`
233
+ */
234
+ minContentWidth?: number;
235
+ /**
236
+ * String representation for `null`.
237
+ * With the core schema, use `'null'`, `'Null'`, `'NULL'`, `'~'`, or an empty
238
+ * string `''`.
239
+ *
240
+ * Default: `'null'`
241
+ */
242
+ nullStr?: string;
243
+ /**
244
+ * Require keys to be scalars and to use implicit rather than explicit notation.
245
+ *
246
+ * Default: `false`
247
+ */
248
+ simpleKeys?: boolean;
249
+ /**
250
+ * Prefer 'single quote' rather than "double quote" where applicable.
251
+ *
252
+ * Default: `false`
253
+ */
254
+ singleQuote?: boolean;
255
+ /**
256
+ * String representation for `true`.
257
+ * With the core schema, use `'true'`, `'True'`, or `'TRUE'`.
258
+ *
259
+ * Default: `'true'`
260
+ */
261
+ trueStr?: string;
262
+ /**
263
+ * The anchor used by an alias must be defined before the alias node. As it's
264
+ * possible for the document to be modified manually, the order may be
265
+ * verified during stringification.
266
+ *
267
+ * Default: `'true'`
268
+ */
269
+ verifyAliasOrder?: boolean;
270
+ };
271
+ /**
272
+ * `yaml` defines document-specific options in three places: as an argument of
273
+ * parse, create and stringify calls, in the values of `YAML.defaultOptions`,
274
+ * and in the version-dependent `YAML.Document.defaults` object. Values set in
275
+ * `YAML.defaultOptions` override version-dependent defaults, and argument
276
+ * options override both.
277
+ */
278
+ export declare const defaultOptions: Required<Omit<ParseOptions, 'lineCounter'> & Omit<DocumentOptions, 'directives'>>;
package/dist/options.js CHANGED
@@ -1,102 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var constants = require('./constants.js');
4
- var options = require('./tags/options.js');
5
-
3
+ /**
4
+ * `yaml` defines document-specific options in three places: as an argument of
5
+ * parse, create and stringify calls, in the values of `YAML.defaultOptions`,
6
+ * and in the version-dependent `YAML.Document.defaults` object. Values set in
7
+ * `YAML.defaultOptions` override version-dependent defaults, and argument
8
+ * options override both.
9
+ */
6
10
  const defaultOptions = {
7
- anchorPrefix: 'a',
8
- customTags: null,
9
- indent: 2,
10
- indentSeq: true,
11
- keepCstNodes: false,
12
- keepNodeTypes: true,
13
- keepUndefined: false,
14
- logLevel: 'warn',
15
- mapAsMap: false,
16
- maxAliasCount: 100,
17
- prettyErrors: true,
18
- simpleKeys: false,
19
- version: '1.2'
20
- };
21
- const scalarOptions = {
22
- get binary() {
23
- return options.binaryOptions;
24
- },
25
-
26
- set binary(opt) {
27
- Object.assign(options.binaryOptions, opt);
28
- },
29
-
30
- get bool() {
31
- return options.boolOptions;
32
- },
33
-
34
- set bool(opt) {
35
- Object.assign(options.boolOptions, opt);
36
- },
37
-
38
- get int() {
39
- return options.intOptions;
40
- },
41
-
42
- set int(opt) {
43
- Object.assign(options.intOptions, opt);
44
- },
45
-
46
- get null() {
47
- return options.nullOptions;
48
- },
49
-
50
- set null(opt) {
51
- Object.assign(options.nullOptions, opt);
52
- },
53
-
54
- get str() {
55
- return options.strOptions;
56
- },
57
-
58
- set str(opt) {
59
- Object.assign(options.strOptions, opt);
60
- }
61
-
62
- };
63
- const documentOptions = {
64
- '1.0': {
65
- schema: 'yaml-1.1',
66
- merge: true,
67
- tagPrefixes: [{
68
- handle: '!',
69
- prefix: constants.defaultTagPrefix
70
- }, {
71
- handle: '!!',
72
- prefix: 'tag:private.yaml.org,2002:'
73
- }]
74
- },
75
- 1.1: {
76
- schema: 'yaml-1.1',
77
- merge: true,
78
- tagPrefixes: [{
79
- handle: '!',
80
- prefix: '!'
81
- }, {
82
- handle: '!!',
83
- prefix: constants.defaultTagPrefix
84
- }]
85
- },
86
- 1.2: {
87
- schema: 'core',
88
- merge: false,
89
- resolveKnownTags: true,
90
- tagPrefixes: [{
91
- handle: '!',
92
- prefix: '!'
93
- }, {
94
- handle: '!!',
95
- prefix: constants.defaultTagPrefix
96
- }]
97
- }
11
+ intAsBigInt: false,
12
+ logLevel: 'warn',
13
+ prettyErrors: true,
14
+ strict: true,
15
+ uniqueKeys: true,
16
+ version: '1.2'
98
17
  };
99
18
 
100
19
  exports.defaultOptions = defaultOptions;
101
- exports.documentOptions = documentOptions;
102
- exports.scalarOptions = scalarOptions;
@@ -0,0 +1,58 @@
1
+ import { ErrorCode } from '../errors.js';
2
+ import { Range } from '../nodes/Node.js';
3
+ import type { Scalar } from '../nodes/Scalar.js';
4
+ import type { BlockScalar, FlowScalar, SourceToken, Token } from './cst.js';
5
+ /**
6
+ * If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
7
+ * Otherwise, return `null`.
8
+ */
9
+ export declare function resolveAsScalar(token: Token | null | undefined, strict?: boolean, onError?: (offset: number, code: ErrorCode, message: string) => void): {
10
+ value: string;
11
+ type: Scalar.Type | null;
12
+ comment: string;
13
+ range: Range;
14
+ } | null;
15
+ /**
16
+ * Create a new scalar token with `value`
17
+ *
18
+ * Values that represent an actual string but may be parsed as a different type should use a `type` other than `'PLAIN'`,
19
+ * as this function does not support any schema operations and won't check for such conflicts.
20
+ *
21
+ * @param value The string representation of the value, which will have its content properly indented.
22
+ * @param context.end Comments and whitespace after the end of the value, or after the block scalar header. If undefined, a newline will be added.
23
+ * @param context.implicitKey Being within an implicit key may affect the resolved type of the token's value.
24
+ * @param context.indent The indent level of the token.
25
+ * @param context.inFlow Is this scalar within a flow collection? This may affect the resolved type of the token's value.
26
+ * @param context.offset The offset position of the token.
27
+ * @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
28
+ */
29
+ export declare function createScalarToken(value: string, context: {
30
+ end?: SourceToken[];
31
+ implicitKey?: boolean;
32
+ indent: number;
33
+ inFlow?: boolean;
34
+ offset?: number;
35
+ type?: Scalar.Type;
36
+ }): BlockScalar | FlowScalar;
37
+ /**
38
+ * Set the value of `token` to the given string `value`, overwriting any previous contents and type that it may have.
39
+ *
40
+ * Best efforts are made to retain any comments previously associated with the `token`,
41
+ * though all contents within a collection's `items` will be overwritten.
42
+ *
43
+ * Values that represent an actual string but may be parsed as a different type should use a `type` other than `'PLAIN'`,
44
+ * as this function does not support any schema operations and won't check for such conflicts.
45
+ *
46
+ * @param token Any token. If it does not include an `indent` value, the value will be stringified as if it were an implicit key.
47
+ * @param value The string representation of the value, which will have its content properly indented.
48
+ * @param context.afterKey In most cases, values after a key should have an additional level of indentation.
49
+ * @param context.implicitKey Being within an implicit key may affect the resolved type of the token's value.
50
+ * @param context.inFlow Being within a flow collection may affect the resolved type of the token's value.
51
+ * @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
52
+ */
53
+ export declare function setScalarValue(token: Token, value: string, context?: {
54
+ afterKey?: boolean;
55
+ implicitKey?: boolean;
56
+ inFlow?: boolean;
57
+ type?: Scalar.Type;
58
+ }): void;
@@ -0,0 +1,223 @@
1
+ 'use strict';
2
+
3
+ var resolveBlockScalar = require('../compose/resolve-block-scalar.js');
4
+ var resolveFlowScalar = require('../compose/resolve-flow-scalar.js');
5
+ var errors = require('../errors.js');
6
+ var stringifyString = require('../stringify/stringifyString.js');
7
+
8
+ /**
9
+ * If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
10
+ * Otherwise, return `null`.
11
+ */
12
+ function resolveAsScalar(token, strict = true, onError) {
13
+ if (token) {
14
+ const _onError = (pos, code, message) => {
15
+ const offset = typeof pos === 'number' ? pos : Array.isArray(pos) ? pos[0] : pos.offset;
16
+ if (onError)
17
+ onError(offset, code, message);
18
+ else
19
+ throw new errors.YAMLParseError([offset, offset + 1], code, message);
20
+ };
21
+ switch (token.type) {
22
+ case 'scalar':
23
+ case 'single-quoted-scalar':
24
+ case 'double-quoted-scalar':
25
+ return resolveFlowScalar.resolveFlowScalar(token, strict, _onError);
26
+ case 'block-scalar':
27
+ return resolveBlockScalar.resolveBlockScalar(token, strict, _onError);
28
+ }
29
+ }
30
+ return null;
31
+ }
32
+ /**
33
+ * Create a new scalar token with `value`
34
+ *
35
+ * Values that represent an actual string but may be parsed as a different type should use a `type` other than `'PLAIN'`,
36
+ * as this function does not support any schema operations and won't check for such conflicts.
37
+ *
38
+ * @param value The string representation of the value, which will have its content properly indented.
39
+ * @param context.end Comments and whitespace after the end of the value, or after the block scalar header. If undefined, a newline will be added.
40
+ * @param context.implicitKey Being within an implicit key may affect the resolved type of the token's value.
41
+ * @param context.indent The indent level of the token.
42
+ * @param context.inFlow Is this scalar within a flow collection? This may affect the resolved type of the token's value.
43
+ * @param context.offset The offset position of the token.
44
+ * @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
45
+ */
46
+ function createScalarToken(value, context) {
47
+ var _a;
48
+ const { implicitKey = false, indent, inFlow = false, offset = -1, type = 'PLAIN' } = context;
49
+ const source = stringifyString.stringifyString({ type, value }, {
50
+ implicitKey,
51
+ indent: indent > 0 ? ' '.repeat(indent) : '',
52
+ inFlow,
53
+ options: { lineWidth: -1 }
54
+ });
55
+ const end = (_a = context.end) !== null && _a !== void 0 ? _a : [
56
+ { type: 'newline', offset: -1, indent, source: '\n' }
57
+ ];
58
+ switch (source[0]) {
59
+ case '|':
60
+ case '>': {
61
+ const he = source.indexOf('\n');
62
+ const head = source.substring(0, he);
63
+ const body = source.substring(he + 1) + '\n';
64
+ const props = [
65
+ { type: 'block-scalar-header', offset, indent, source: head }
66
+ ];
67
+ if (!addEndtoBlockProps(props, end))
68
+ props.push({ type: 'newline', offset: -1, indent, source: '\n' });
69
+ return { type: 'block-scalar', offset, indent, props, source: body };
70
+ }
71
+ case '"':
72
+ return { type: 'double-quoted-scalar', offset, indent, source, end };
73
+ case "'":
74
+ return { type: 'single-quoted-scalar', offset, indent, source, end };
75
+ default:
76
+ return { type: 'scalar', offset, indent, source, end };
77
+ }
78
+ }
79
+ /**
80
+ * Set the value of `token` to the given string `value`, overwriting any previous contents and type that it may have.
81
+ *
82
+ * Best efforts are made to retain any comments previously associated with the `token`,
83
+ * though all contents within a collection's `items` will be overwritten.
84
+ *
85
+ * Values that represent an actual string but may be parsed as a different type should use a `type` other than `'PLAIN'`,
86
+ * as this function does not support any schema operations and won't check for such conflicts.
87
+ *
88
+ * @param token Any token. If it does not include an `indent` value, the value will be stringified as if it were an implicit key.
89
+ * @param value The string representation of the value, which will have its content properly indented.
90
+ * @param context.afterKey In most cases, values after a key should have an additional level of indentation.
91
+ * @param context.implicitKey Being within an implicit key may affect the resolved type of the token's value.
92
+ * @param context.inFlow Being within a flow collection may affect the resolved type of the token's value.
93
+ * @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
94
+ */
95
+ function setScalarValue(token, value, context = {}) {
96
+ let { afterKey = false, implicitKey = false, inFlow = false, type } = context;
97
+ let indent = 'indent' in token ? token.indent : null;
98
+ if (afterKey && typeof indent === 'number')
99
+ indent += 2;
100
+ if (!type)
101
+ switch (token.type) {
102
+ case 'single-quoted-scalar':
103
+ type = 'QUOTE_SINGLE';
104
+ break;
105
+ case 'double-quoted-scalar':
106
+ type = 'QUOTE_DOUBLE';
107
+ break;
108
+ case 'block-scalar': {
109
+ const header = token.props[0];
110
+ if (header.type !== 'block-scalar-header')
111
+ throw new Error('Invalid block scalar header');
112
+ type = header.source[0] === '>' ? 'BLOCK_FOLDED' : 'BLOCK_LITERAL';
113
+ break;
114
+ }
115
+ default:
116
+ type = 'PLAIN';
117
+ }
118
+ const source = stringifyString.stringifyString({ type, value }, {
119
+ implicitKey: implicitKey || indent === null,
120
+ indent: indent !== null && indent > 0 ? ' '.repeat(indent) : '',
121
+ inFlow,
122
+ options: { lineWidth: -1 }
123
+ });
124
+ switch (source[0]) {
125
+ case '|':
126
+ case '>':
127
+ setBlockScalarValue(token, source);
128
+ break;
129
+ case '"':
130
+ setFlowScalarValue(token, source, 'double-quoted-scalar');
131
+ break;
132
+ case "'":
133
+ setFlowScalarValue(token, source, 'single-quoted-scalar');
134
+ break;
135
+ default:
136
+ setFlowScalarValue(token, source, 'scalar');
137
+ }
138
+ }
139
+ function setBlockScalarValue(token, source) {
140
+ const he = source.indexOf('\n');
141
+ const head = source.substring(0, he);
142
+ const body = source.substring(he + 1) + '\n';
143
+ if (token.type === 'block-scalar') {
144
+ const header = token.props[0];
145
+ if (header.type !== 'block-scalar-header')
146
+ throw new Error('Invalid block scalar header');
147
+ header.source = head;
148
+ token.source = body;
149
+ }
150
+ else {
151
+ const { offset } = token;
152
+ const indent = 'indent' in token ? token.indent : -1;
153
+ const props = [
154
+ { type: 'block-scalar-header', offset, indent, source: head }
155
+ ];
156
+ if (!addEndtoBlockProps(props, 'end' in token ? token.end : undefined))
157
+ props.push({ type: 'newline', offset: -1, indent, source: '\n' });
158
+ for (const key of Object.keys(token))
159
+ if (key !== 'type' && key !== 'offset')
160
+ delete token[key];
161
+ Object.assign(token, { type: 'block-scalar', indent, props, source: body });
162
+ }
163
+ }
164
+ /** @returns `true` if last token is a newline */
165
+ function addEndtoBlockProps(props, end) {
166
+ if (end)
167
+ for (const st of end)
168
+ switch (st.type) {
169
+ case 'space':
170
+ case 'comment':
171
+ props.push(st);
172
+ break;
173
+ case 'newline':
174
+ props.push(st);
175
+ return true;
176
+ }
177
+ return false;
178
+ }
179
+ function setFlowScalarValue(token, source, type) {
180
+ switch (token.type) {
181
+ case 'scalar':
182
+ case 'double-quoted-scalar':
183
+ case 'single-quoted-scalar':
184
+ token.type = type;
185
+ token.source = source;
186
+ break;
187
+ case 'block-scalar': {
188
+ const end = token.props.slice(1);
189
+ let oa = source.length;
190
+ if (token.props[0].type === 'block-scalar-header')
191
+ oa -= token.props[0].source.length;
192
+ for (const tok of end)
193
+ tok.offset += oa;
194
+ delete token.props;
195
+ Object.assign(token, { type, source, end });
196
+ break;
197
+ }
198
+ case 'block-map':
199
+ case 'block-seq': {
200
+ const offset = token.offset + source.length;
201
+ const nl = { type: 'newline', offset, indent: token.indent, source: '\n' };
202
+ delete token.items;
203
+ Object.assign(token, { type, source, end: [nl] });
204
+ break;
205
+ }
206
+ default: {
207
+ const indent = 'indent' in token ? token.indent : -1;
208
+ const end = 'end' in token && Array.isArray(token.end)
209
+ ? token.end.filter(st => st.type === 'space' ||
210
+ st.type === 'comment' ||
211
+ st.type === 'newline')
212
+ : [];
213
+ for (const key of Object.keys(token))
214
+ if (key !== 'type' && key !== 'offset')
215
+ delete token[key];
216
+ Object.assign(token, { type, indent, source, end });
217
+ }
218
+ }
219
+ }
220
+
221
+ exports.createScalarToken = createScalarToken;
222
+ exports.resolveAsScalar = resolveAsScalar;
223
+ exports.setScalarValue = setScalarValue;
@@ -0,0 +1,8 @@
1
+ import type { CollectionItem, Token } from './cst.js';
2
+ /**
3
+ * Stringify a CST document, token, or collection item
4
+ *
5
+ * Fair warning: This applies no validation whatsoever, and
6
+ * simply concatenates the sources in their logical order.
7
+ */
8
+ export declare const stringify: (cst: Token | CollectionItem) => string;