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,345 +1,318 @@
1
1
  'use strict';
2
2
 
3
- var addComment = require('./addComment.js');
4
- var constants = require('../constants.js');
5
- var resolveScalar = require('../resolve/resolveScalar.js');
3
+ var Scalar = require('../nodes/Scalar.js');
6
4
  var foldFlowLines = require('./foldFlowLines.js');
7
- var options = require('../tags/options.js');
8
5
 
9
- const getFoldOptions = ({
10
- indentAtStart
11
- }) => indentAtStart ? Object.assign({
12
- indentAtStart
13
- }, options.strOptions.fold) : options.strOptions.fold; // Also checks for lines starting with %, as parsing the output as YAML 1.1 will
6
+ const getFoldOptions = (ctx) => ({
7
+ indentAtStart: ctx.indentAtStart,
8
+ lineWidth: ctx.options.lineWidth,
9
+ minContentWidth: ctx.options.minContentWidth
10
+ });
11
+ // Also checks for lines starting with %, as parsing the output as YAML 1.1 will
14
12
  // presume that's starting a new document.
15
-
16
-
17
- const containsDocumentMarker = str => /^(%|---|\.\.\.)/m.test(str);
18
-
19
- function lineLengthOverLimit(str, limit) {
20
- const strLen = str.length;
21
- if (strLen <= limit) return false;
22
-
23
- for (let i = 0, start = 0; i < strLen; ++i) {
24
- if (str[i] === '\n') {
25
- if (i - start > limit) return true;
26
- start = i + 1;
27
- if (strLen - start <= limit) return false;
13
+ const containsDocumentMarker = (str) => /^(%|---|\.\.\.)/m.test(str);
14
+ function lineLengthOverLimit(str, lineWidth, indentLength) {
15
+ if (!lineWidth || lineWidth < 0)
16
+ return false;
17
+ const limit = lineWidth - indentLength;
18
+ const strLen = str.length;
19
+ if (strLen <= limit)
20
+ return false;
21
+ for (let i = 0, start = 0; i < strLen; ++i) {
22
+ if (str[i] === '\n') {
23
+ if (i - start > limit)
24
+ return true;
25
+ start = i + 1;
26
+ if (strLen - start <= limit)
27
+ return false;
28
+ }
28
29
  }
29
- }
30
-
31
- return true;
30
+ return true;
32
31
  }
33
-
34
32
  function doubleQuotedString(value, ctx) {
35
- const {
36
- implicitKey
37
- } = ctx;
38
- const {
39
- jsonEncoding,
40
- minMultiLineLength
41
- } = options.strOptions.doubleQuoted;
42
- const json = JSON.stringify(value);
43
- if (jsonEncoding) return json;
44
- const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
45
- let str = '';
46
- let start = 0;
47
-
48
- for (let i = 0, ch = json[i]; ch; ch = json[++i]) {
49
- if (ch === ' ' && json[i + 1] === '\\' && json[i + 2] === 'n') {
50
- // space before newline needs to be escaped to not be folded
51
- str += json.slice(start, i) + '\\ ';
52
- i += 1;
53
- start = i;
54
- ch = '\\';
55
- }
56
-
57
- if (ch === '\\') switch (json[i + 1]) {
58
- case 'u':
59
- {
60
- str += json.slice(start, i);
61
- const code = json.substr(i + 2, 4);
62
-
63
- switch (code) {
64
- case '0000':
65
- str += '\\0';
66
- break;
67
-
68
- case '0007':
69
- str += '\\a';
70
- break;
71
-
72
- case '000b':
73
- str += '\\v';
74
- break;
75
-
76
- case '001b':
77
- str += '\\e';
78
- break;
79
-
80
- case '0085':
81
- str += '\\N';
82
- break;
83
-
84
- case '00a0':
85
- str += '\\_';
86
- break;
87
-
88
- case '2028':
89
- str += '\\L';
90
- break;
91
-
92
- case '2029':
93
- str += '\\P';
94
- break;
95
-
96
- default:
97
- if (code.substr(0, 2) === '00') str += '\\x' + code.substr(2);else str += json.substr(i, 6);
98
- }
99
-
100
- i += 5;
101
- start = i + 1;
102
- }
103
- break;
104
-
105
- case 'n':
106
- if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) {
107
- i += 1;
108
- } else {
109
- // folding will eat first newline
110
- str += json.slice(start, i) + '\n\n';
111
-
112
- while (json[i + 2] === '\\' && json[i + 3] === 'n' && json[i + 4] !== '"') {
113
- str += '\n';
114
- i += 2;
115
- }
116
-
117
- str += indent; // space after newline needs to be escaped to not be folded
118
-
119
- if (json[i + 2] === ' ') str += '\\';
120
- i += 1;
121
- start = i + 1;
33
+ const json = JSON.stringify(value);
34
+ if (ctx.options.doubleQuotedAsJSON)
35
+ return json;
36
+ const { implicitKey } = ctx;
37
+ const minMultiLineLength = ctx.options.doubleQuotedMinMultiLineLength;
38
+ const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
39
+ let str = '';
40
+ let start = 0;
41
+ for (let i = 0, ch = json[i]; ch; ch = json[++i]) {
42
+ if (ch === ' ' && json[i + 1] === '\\' && json[i + 2] === 'n') {
43
+ // space before newline needs to be escaped to not be folded
44
+ str += json.slice(start, i) + '\\ ';
45
+ i += 1;
46
+ start = i;
47
+ ch = '\\';
122
48
  }
123
-
124
- break;
125
-
126
- default:
127
- i += 1;
49
+ if (ch === '\\')
50
+ switch (json[i + 1]) {
51
+ case 'u':
52
+ {
53
+ str += json.slice(start, i);
54
+ const code = json.substr(i + 2, 4);
55
+ switch (code) {
56
+ case '0000':
57
+ str += '\\0';
58
+ break;
59
+ case '0007':
60
+ str += '\\a';
61
+ break;
62
+ case '000b':
63
+ str += '\\v';
64
+ break;
65
+ case '001b':
66
+ str += '\\e';
67
+ break;
68
+ case '0085':
69
+ str += '\\N';
70
+ break;
71
+ case '00a0':
72
+ str += '\\_';
73
+ break;
74
+ case '2028':
75
+ str += '\\L';
76
+ break;
77
+ case '2029':
78
+ str += '\\P';
79
+ break;
80
+ default:
81
+ if (code.substr(0, 2) === '00')
82
+ str += '\\x' + code.substr(2);
83
+ else
84
+ str += json.substr(i, 6);
85
+ }
86
+ i += 5;
87
+ start = i + 1;
88
+ }
89
+ break;
90
+ case 'n':
91
+ if (implicitKey ||
92
+ json[i + 2] === '"' ||
93
+ json.length < minMultiLineLength) {
94
+ i += 1;
95
+ }
96
+ else {
97
+ // folding will eat first newline
98
+ str += json.slice(start, i) + '\n\n';
99
+ while (json[i + 2] === '\\' &&
100
+ json[i + 3] === 'n' &&
101
+ json[i + 4] !== '"') {
102
+ str += '\n';
103
+ i += 2;
104
+ }
105
+ str += indent;
106
+ // space after newline needs to be escaped to not be folded
107
+ if (json[i + 2] === ' ')
108
+ str += '\\';
109
+ i += 1;
110
+ start = i + 1;
111
+ }
112
+ break;
113
+ default:
114
+ i += 1;
115
+ }
128
116
  }
129
- }
130
-
131
- str = start ? str + json.slice(start) : json;
132
- return implicitKey ? str : foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx));
117
+ str = start ? str + json.slice(start) : json;
118
+ return implicitKey
119
+ ? str
120
+ : foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx));
133
121
  }
134
-
135
122
  function singleQuotedString(value, ctx) {
136
- if (ctx.implicitKey) {
137
- if (/\n/.test(value)) return doubleQuotedString(value, ctx);
138
- } else {
139
- // single quoted string can't have leading or trailing whitespace around newline
140
- if (/[ \t]\n|\n[ \t]/.test(value)) return doubleQuotedString(value, ctx);
141
- }
142
-
143
- const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
144
- const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
145
- return ctx.implicitKey ? res : foldFlowLines.foldFlowLines(res, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
123
+ if (ctx.implicitKey) {
124
+ if (/\n/.test(value))
125
+ return doubleQuotedString(value, ctx);
126
+ }
127
+ else {
128
+ // single quoted string can't have leading or trailing whitespace around newline
129
+ if (/[ \t]\n|\n[ \t]/.test(value))
130
+ return doubleQuotedString(value, ctx);
131
+ }
132
+ const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
133
+ const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
134
+ return ctx.implicitKey
135
+ ? res
136
+ : foldFlowLines.foldFlowLines(res, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
146
137
  }
147
-
148
- function blockString({
149
- comment,
150
- type,
151
- value
152
- }, ctx, onComment, onChompKeep) {
153
- // 1. Block can't end in whitespace unless the last line is non-empty.
154
- // 2. Strings consisting of only whitespace are best rendered explicitly.
155
- if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
156
- return doubleQuotedString(value, ctx);
157
- }
158
-
159
- const indent = ctx.indent || (ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : '');
160
- const indentSize = indent ? '2' : '1'; // root is at -1
161
-
162
- const literal = type === constants.Type.BLOCK_FOLDED ? false : type === constants.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, options.strOptions.fold.lineWidth - indent.length);
163
- let header = literal ? '|' : '>';
164
- if (!value) return header + '\n';
165
- let wsStart = '';
166
- let wsEnd = '';
167
- value = value.replace(/[\n\t ]*$/, ws => {
168
- const n = ws.indexOf('\n');
169
-
170
- if (n === -1) {
171
- header += '-'; // strip
172
- } else if (value === ws || n !== ws.length - 1) {
173
- header += '+'; // keep
174
-
175
- if (onChompKeep) onChompKeep();
138
+ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
139
+ // 1. Block can't end in whitespace unless the last line is non-empty.
140
+ // 2. Strings consisting of only whitespace are best rendered explicitly.
141
+ if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
142
+ return doubleQuotedString(value, ctx);
176
143
  }
177
-
178
- wsEnd = ws.replace(/\n$/, '');
179
- return '';
180
- }).replace(/^[\n ]*/, ws => {
181
- if (ws.indexOf(' ') !== -1) header += indentSize;
182
- const m = ws.match(/ +$/);
183
-
184
- if (m) {
185
- wsStart = ws.slice(0, -m[0].length);
186
- return m[0];
187
- } else {
188
- wsStart = ws;
189
- return '';
144
+ const indent = ctx.indent ||
145
+ (ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : '');
146
+ const literal = type === Scalar.Scalar.BLOCK_FOLDED
147
+ ? false
148
+ : type === Scalar.Scalar.BLOCK_LITERAL
149
+ ? true
150
+ : !lineLengthOverLimit(value, ctx.options.lineWidth, indent.length);
151
+ if (!value)
152
+ return literal ? '|\n' : '>\n';
153
+ // determine chomping from whitespace at value end
154
+ let chomp;
155
+ let endStart;
156
+ for (endStart = value.length; endStart > 0; --endStart) {
157
+ const ch = value[endStart - 1];
158
+ if (ch !== '\n' && ch !== '\t' && ch !== ' ')
159
+ break;
190
160
  }
191
- });
192
- if (wsEnd) wsEnd = wsEnd.replace(/\n+(?!\n|$)/g, `$&${indent}`);
193
- if (wsStart) wsStart = wsStart.replace(/\n+/g, `$&${indent}`);
194
-
195
- if (comment) {
196
- header += ' #' + comment.replace(/ ?[\r\n]+/g, ' ');
197
- if (onComment) onComment();
198
- }
199
-
200
- if (!value) return `${header}${indentSize}\n${indent}${wsEnd}`;
201
-
202
- if (literal) {
203
- value = value.replace(/\n+/g, `$&${indent}`);
204
- return `${header}\n${indent}${wsStart}${value}${wsEnd}`;
205
- }
206
-
207
- value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
208
- // ^ ind.line ^ empty ^ capture next empty lines only at end of indent
209
- .replace(/\n+/g, `$&${indent}`);
210
- const body = foldFlowLines.foldFlowLines(`${wsStart}${value}${wsEnd}`, indent, foldFlowLines.FOLD_BLOCK, options.strOptions.fold);
211
- return `${header}\n${indent}${body}`;
161
+ let end = value.substring(endStart);
162
+ const endNlPos = end.indexOf('\n');
163
+ if (endNlPos === -1) {
164
+ chomp = '-'; // strip
165
+ }
166
+ else if (value === end || endNlPos !== end.length - 1) {
167
+ chomp = '+'; // keep
168
+ if (onChompKeep)
169
+ onChompKeep();
170
+ }
171
+ else {
172
+ chomp = ''; // clip
173
+ }
174
+ if (end) {
175
+ value = value.slice(0, -end.length);
176
+ if (end[end.length - 1] === '\n')
177
+ end = end.slice(0, -1);
178
+ end = end.replace(/\n+(?!\n|$)/g, `$&${indent}`);
179
+ }
180
+ // determine indent indicator from whitespace at value start
181
+ let startWithSpace = false;
182
+ let startEnd;
183
+ let startNlPos = -1;
184
+ for (startEnd = 0; startEnd < value.length; ++startEnd) {
185
+ const ch = value[startEnd];
186
+ if (ch === ' ')
187
+ startWithSpace = true;
188
+ else if (ch === '\n')
189
+ startNlPos = startEnd;
190
+ else
191
+ break;
192
+ }
193
+ let start = value.substring(0, startNlPos < startEnd ? startNlPos + 1 : startEnd);
194
+ if (start) {
195
+ value = value.substring(start.length);
196
+ start = start.replace(/\n+/g, `$&${indent}`);
197
+ }
198
+ const indentSize = indent ? '2' : '1'; // root is at -1
199
+ let header = (literal ? '|' : '>') + (startWithSpace ? indentSize : '') + chomp;
200
+ if (comment) {
201
+ header += ' #' + comment.replace(/ ?[\r\n]+/g, ' ');
202
+ if (onComment)
203
+ onComment();
204
+ }
205
+ if (literal) {
206
+ value = value.replace(/\n+/g, `$&${indent}`);
207
+ return `${header}\n${indent}${start}${value}${end}`;
208
+ }
209
+ value = value
210
+ .replace(/\n+/g, '\n$&')
211
+ .replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
212
+ // ^ more-ind. ^ empty ^ capture next empty lines only at end of indent
213
+ .replace(/\n+/g, `$&${indent}`);
214
+ const body = foldFlowLines.foldFlowLines(`${start}${value}${end}`, indent, foldFlowLines.FOLD_BLOCK, getFoldOptions(ctx));
215
+ return `${header}\n${indent}${body}`;
212
216
  }
213
-
214
217
  function plainString(item, ctx, onComment, onChompKeep) {
215
- const {
216
- comment,
217
- type,
218
- value
219
- } = item;
220
- const {
221
- actualString,
222
- implicitKey,
223
- indent,
224
- inFlow
225
- } = ctx;
226
-
227
- if (implicitKey && /[\n[\]{},]/.test(value) || inFlow && /[[\]{},]/.test(value)) {
228
- return doubleQuotedString(value, ctx);
229
- }
230
-
231
- if (!value || /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
232
- const hasDouble = value.indexOf('"') !== -1;
233
- const hasSingle = value.indexOf("'") !== -1;
234
- let quotedString;
235
-
236
- if (hasDouble && !hasSingle) {
237
- quotedString = singleQuotedString;
238
- } else if (hasSingle && !hasDouble) {
239
- quotedString = doubleQuotedString;
240
- } else if (options.strOptions.defaultQuoteSingle) {
241
- quotedString = singleQuotedString;
242
- } else {
243
- quotedString = doubleQuotedString;
244
- } // not allowed:
245
- // - empty string, '-' or '?'
246
- // - start with an indicator character (except [?:-]) or /[?-] /
247
- // - '\n ', ': ' or ' \n' anywhere
248
- // - '#' not preceded by a non-space char
249
- // - end with ' ' or ':'
250
-
251
-
252
- return implicitKey || inFlow || value.indexOf('\n') === -1 ? quotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
253
- }
254
-
255
- if (!implicitKey && !inFlow && type !== constants.Type.PLAIN && value.indexOf('\n') !== -1) {
256
- // Where allowed & type not set explicitly, prefer block style for multiline strings
257
- return blockString(item, ctx, onComment, onChompKeep);
258
- }
259
-
260
- if (indent === '' && containsDocumentMarker(value)) {
261
- ctx.forceBlockIndent = true;
262
- return blockString(item, ctx, onComment, onChompKeep);
263
- }
264
-
265
- const str = value.replace(/\n+/g, `$&\n${indent}`); // Verify that output will be parsed as a string, as e.g. plain numbers and
266
- // booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
267
- // and others in v1.1.
268
-
269
- if (actualString) {
270
- const {
271
- tags
272
- } = ctx.doc.schema;
273
- const resolved = resolveScalar.resolveScalar(str, tags).value;
274
- if (typeof resolved !== 'string') return doubleQuotedString(value, ctx);
275
- }
276
-
277
- const body = implicitKey ? str : foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
278
-
279
- if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
280
- if (onComment) onComment();
281
- return addComment.addCommentBefore(body, indent, comment);
282
- }
283
-
284
- return body;
218
+ var _a;
219
+ const { type, value } = item;
220
+ const { actualString, implicitKey, indent, inFlow } = ctx;
221
+ if ((implicitKey && /[\n[\]{},]/.test(value)) ||
222
+ (inFlow && /[[\]{},]/.test(value))) {
223
+ return doubleQuotedString(value, ctx);
224
+ }
225
+ if (!value ||
226
+ /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
227
+ const hasDouble = value.indexOf('"') !== -1;
228
+ const hasSingle = value.indexOf("'") !== -1;
229
+ let quotedString;
230
+ if (hasDouble && !hasSingle) {
231
+ quotedString = singleQuotedString;
232
+ }
233
+ else if (hasSingle && !hasDouble) {
234
+ quotedString = doubleQuotedString;
235
+ }
236
+ else if (ctx.options.singleQuote) {
237
+ quotedString = singleQuotedString;
238
+ }
239
+ else {
240
+ quotedString = doubleQuotedString;
241
+ }
242
+ // not allowed:
243
+ // - empty string, '-' or '?'
244
+ // - start with an indicator character (except [?:-]) or /[?-] /
245
+ // - '\n ', ': ' or ' \n' anywhere
246
+ // - '#' not preceded by a non-space char
247
+ // - end with ' ' or ':'
248
+ return implicitKey || inFlow || value.indexOf('\n') === -1
249
+ ? quotedString(value, ctx)
250
+ : blockString(item, ctx, onComment, onChompKeep);
251
+ }
252
+ if (!implicitKey &&
253
+ !inFlow &&
254
+ type !== Scalar.Scalar.PLAIN &&
255
+ value.indexOf('\n') !== -1) {
256
+ // Where allowed & type not set explicitly, prefer block style for multiline strings
257
+ return blockString(item, ctx, onComment, onChompKeep);
258
+ }
259
+ if (indent === '' && containsDocumentMarker(value)) {
260
+ ctx.forceBlockIndent = true;
261
+ return blockString(item, ctx, onComment, onChompKeep);
262
+ }
263
+ const str = value.replace(/\n+/g, `$&\n${indent}`);
264
+ // Verify that output will be parsed as a string, as e.g. plain numbers and
265
+ // booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
266
+ // and others in v1.1.
267
+ if (actualString) {
268
+ for (const tag of ctx.doc.schema.tags) {
269
+ if (tag.default &&
270
+ tag.tag !== 'tag:yaml.org,2002:str' &&
271
+ ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(str)))
272
+ return doubleQuotedString(value, ctx);
273
+ }
274
+ }
275
+ return implicitKey
276
+ ? str
277
+ : foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
285
278
  }
286
-
287
279
  function stringifyString(item, ctx, onComment, onChompKeep) {
288
- const {
289
- defaultKeyType,
290
- defaultType
291
- } = options.strOptions;
292
- const {
293
- implicitKey,
294
- inFlow
295
- } = ctx;
296
- let {
297
- type,
298
- value
299
- } = item;
300
-
301
- if (typeof value !== 'string') {
302
- value = String(value);
303
- item = Object.assign({}, item, {
304
- value
305
- });
306
- }
307
-
308
- if (type !== constants.Type.QUOTE_DOUBLE) {
309
- // force double quotes on control characters & unpaired surrogates
310
- if (/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(value)) type = constants.Type.QUOTE_DOUBLE;
311
- }
312
-
313
- const _stringify = _type => {
314
- switch (_type) {
315
- case constants.Type.BLOCK_FOLDED:
316
- case constants.Type.BLOCK_LITERAL:
317
- return implicitKey || inFlow ? doubleQuotedString(value, ctx) // blocks are not valid inside flow containers
318
- : blockString(item, ctx, onComment, onChompKeep);
319
-
320
- case constants.Type.QUOTE_DOUBLE:
321
- return doubleQuotedString(value, ctx);
322
-
323
- case constants.Type.QUOTE_SINGLE:
324
- return singleQuotedString(value, ctx);
325
-
326
- case constants.Type.PLAIN:
327
- return plainString(item, ctx, onComment, onChompKeep);
328
-
329
- default:
330
- return null;
280
+ const { implicitKey, inFlow } = ctx;
281
+ const ss = typeof item.value === 'string'
282
+ ? item
283
+ : Object.assign({}, item, { value: String(item.value) });
284
+ let { type } = item;
285
+ if (type !== Scalar.Scalar.QUOTE_DOUBLE) {
286
+ // force double quotes on control characters & unpaired surrogates
287
+ if (/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(ss.value))
288
+ type = Scalar.Scalar.QUOTE_DOUBLE;
331
289
  }
332
- };
333
-
334
- let res = _stringify(type);
335
-
336
- if (res === null) {
337
- const t = implicitKey ? defaultKeyType : defaultType;
338
- res = _stringify(t);
339
- if (res === null) throw new Error(`Unsupported default string type ${t}`);
340
- }
341
-
342
- return res;
290
+ const _stringify = (_type) => {
291
+ switch (_type) {
292
+ case Scalar.Scalar.BLOCK_FOLDED:
293
+ case Scalar.Scalar.BLOCK_LITERAL:
294
+ return implicitKey || inFlow
295
+ ? doubleQuotedString(ss.value, ctx) // blocks are not valid inside flow containers
296
+ : blockString(ss, ctx, onComment, onChompKeep);
297
+ case Scalar.Scalar.QUOTE_DOUBLE:
298
+ return doubleQuotedString(ss.value, ctx);
299
+ case Scalar.Scalar.QUOTE_SINGLE:
300
+ return singleQuotedString(ss.value, ctx);
301
+ case Scalar.Scalar.PLAIN:
302
+ return plainString(ss, ctx, onComment, onChompKeep);
303
+ default:
304
+ return null;
305
+ }
306
+ };
307
+ let res = _stringify(type);
308
+ if (res === null) {
309
+ const { defaultKeyType, defaultStringType } = ctx.options;
310
+ const t = (implicitKey && defaultKeyType) || defaultStringType;
311
+ res = _stringify(t);
312
+ if (res === null)
313
+ throw new Error(`Unsupported default string type ${t}`);
314
+ }
315
+ return res;
343
316
  }
344
317
 
345
318
  exports.stringifyString = stringifyString;
@@ -0,0 +1,4 @@
1
+ export declare function testEvents(src: string): {
2
+ events: string[];
3
+ error: any;
4
+ };