yaml 1.3.0 → 1.5.0

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 (145) hide show
  1. package/README.md +29 -23
  2. package/browser/dist/Anchors.js +12 -10
  3. package/browser/dist/Document.js +122 -60
  4. package/browser/dist/constants.js +34 -0
  5. package/browser/dist/cst/Alias.js +1 -3
  6. package/browser/dist/cst/BlankLine.js +5 -7
  7. package/browser/dist/cst/BlockValue.js +4 -4
  8. package/browser/dist/cst/Collection.js +8 -8
  9. package/browser/dist/cst/CollectionItem.js +6 -8
  10. package/browser/dist/cst/Comment.js +5 -7
  11. package/browser/dist/cst/Directive.js +5 -7
  12. package/browser/dist/cst/Document.js +8 -10
  13. package/browser/dist/cst/FlowCollection.js +5 -7
  14. package/browser/dist/cst/Node.js +12 -40
  15. package/browser/dist/cst/ParseContext.js +32 -34
  16. package/browser/dist/cst/PlainValue.js +1 -3
  17. package/browser/dist/cst/QuoteDouble.js +1 -3
  18. package/browser/dist/cst/QuoteSingle.js +1 -3
  19. package/browser/dist/cst/Range.js +1 -3
  20. package/browser/dist/cst/getLinePos.js +8 -13
  21. package/browser/dist/cst/parse.js +1 -4
  22. package/browser/dist/deprecation.js +34 -0
  23. package/browser/dist/errors.js +50 -59
  24. package/browser/dist/index.js +7 -4
  25. package/browser/dist/listTagNames.js +1 -3
  26. package/browser/dist/schema/Alias.js +90 -10
  27. package/browser/dist/schema/Collection.js +3 -3
  28. package/browser/dist/schema/Map.js +22 -105
  29. package/browser/dist/schema/Merge.js +74 -1
  30. package/browser/dist/schema/Node.js +1 -3
  31. package/browser/dist/schema/Pair.js +52 -26
  32. package/browser/dist/schema/Scalar.js +3 -5
  33. package/browser/dist/schema/Seq.js +30 -7
  34. package/browser/dist/schema/index.js +158 -82
  35. package/browser/dist/schema/parseMap.js +18 -21
  36. package/browser/dist/schema/parseSeq.js +9 -12
  37. package/browser/dist/{schema/_string.js → stringify.js} +65 -73
  38. package/browser/dist/tags/core.js +132 -0
  39. package/browser/dist/tags/failsafe/index.js +17 -0
  40. package/browser/dist/tags/failsafe/map.js +65 -0
  41. package/browser/dist/tags/failsafe/seq.js +54 -0
  42. package/browser/dist/tags/failsafe/string.js +40 -0
  43. package/browser/dist/tags/index.js +50 -0
  44. package/browser/dist/tags/json.js +103 -0
  45. package/browser/dist/tags/options.js +35 -0
  46. package/browser/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +20 -20
  47. package/browser/dist/tags/yaml-1.1/index.js +177 -0
  48. package/browser/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +25 -25
  49. package/browser/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +9 -13
  50. package/browser/dist/tags/yaml-1.1/set.js +140 -0
  51. package/browser/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +13 -10
  52. package/browser/dist/test-events.js +1 -4
  53. package/browser/dist/toJSON.js +20 -8
  54. package/browser/index.js +1 -0
  55. package/browser/map.js +2 -1
  56. package/browser/pair.js +2 -1
  57. package/browser/parse-cst.js +1 -1
  58. package/browser/scalar.js +2 -1
  59. package/browser/schema.js +7 -3
  60. package/browser/seq.js +2 -1
  61. package/browser/types/binary.js +7 -1
  62. package/browser/types/omap.js +2 -1
  63. package/browser/types/pairs.js +2 -1
  64. package/browser/types/set.js +2 -1
  65. package/browser/types/timestamp.js +10 -1
  66. package/browser/types.js +11 -0
  67. package/browser/util.js +15 -0
  68. package/dist/Anchors.js +9 -8
  69. package/dist/Document.js +55 -39
  70. package/dist/constants.js +34 -0
  71. package/dist/cst/Alias.js +1 -3
  72. package/dist/cst/BlankLine.js +5 -7
  73. package/dist/cst/BlockValue.js +4 -4
  74. package/dist/cst/Collection.js +8 -8
  75. package/dist/cst/CollectionItem.js +6 -8
  76. package/dist/cst/Comment.js +5 -7
  77. package/dist/cst/Directive.js +5 -7
  78. package/dist/cst/Document.js +8 -10
  79. package/dist/cst/FlowCollection.js +5 -7
  80. package/dist/cst/Node.js +12 -40
  81. package/dist/cst/ParseContext.js +32 -34
  82. package/dist/cst/PlainValue.js +1 -3
  83. package/dist/cst/QuoteDouble.js +1 -3
  84. package/dist/cst/QuoteSingle.js +1 -3
  85. package/dist/cst/Range.js +1 -3
  86. package/dist/cst/getLinePos.js +8 -12
  87. package/dist/cst/parse.js +1 -4
  88. package/dist/deprecation.js +34 -0
  89. package/dist/errors.js +29 -35
  90. package/dist/index.js +7 -4
  91. package/dist/listTagNames.js +1 -3
  92. package/dist/schema/Alias.js +67 -12
  93. package/dist/schema/Map.js +10 -74
  94. package/dist/schema/Merge.js +31 -0
  95. package/dist/schema/Node.js +1 -3
  96. package/dist/schema/Pair.js +46 -20
  97. package/dist/schema/Scalar.js +3 -5
  98. package/dist/schema/Seq.js +9 -5
  99. package/dist/schema/index.js +109 -74
  100. package/dist/schema/parseMap.js +18 -21
  101. package/dist/schema/parseSeq.js +9 -12
  102. package/dist/{schema/_string.js → stringify.js} +56 -65
  103. package/dist/tags/core.js +96 -0
  104. package/dist/tags/failsafe/index.js +17 -0
  105. package/dist/tags/failsafe/map.js +33 -0
  106. package/dist/tags/failsafe/seq.js +34 -0
  107. package/dist/tags/failsafe/string.js +40 -0
  108. package/dist/tags/index.js +50 -0
  109. package/dist/tags/json.js +67 -0
  110. package/dist/tags/options.js +35 -0
  111. package/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +18 -20
  112. package/dist/tags/yaml-1.1/index.js +131 -0
  113. package/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +16 -16
  114. package/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +9 -11
  115. package/dist/{schema/_set.js → tags/yaml-1.1/set.js} +12 -44
  116. package/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +7 -10
  117. package/dist/test-events.js +1 -4
  118. package/dist/toJSON.js +15 -5
  119. package/index.js +1 -0
  120. package/map.js +2 -1
  121. package/package.json +22 -17
  122. package/pair.js +2 -1
  123. package/parse-cst.js +1 -1
  124. package/scalar.js +2 -1
  125. package/schema.js +7 -3
  126. package/seq.js +2 -1
  127. package/types/binary.js +7 -1
  128. package/types/omap.js +2 -1
  129. package/types/pairs.js +2 -1
  130. package/types/set.js +2 -1
  131. package/types/timestamp.js +10 -1
  132. package/types.js +11 -0
  133. package/util.js +15 -0
  134. package/browser/dist/polyfill.js +0 -251
  135. package/browser/dist/schema/_set.js +0 -212
  136. package/browser/dist/schema/core.js +0 -98
  137. package/browser/dist/schema/failsafe.js +0 -125
  138. package/browser/dist/schema/json.js +0 -66
  139. package/browser/dist/schema/yaml-1.1.js +0 -140
  140. package/dist/linePos.js +0 -58
  141. package/dist/polyfill.js +0 -27
  142. package/dist/schema/core.js +0 -79
  143. package/dist/schema/failsafe.js +0 -74
  144. package/dist/schema/json.js +0 -56
  145. package/dist/schema/yaml-1.1.js +0 -115
@@ -3,31 +3,45 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.stringify = stringify;
7
- exports.str = exports.resolve = exports.strOptions = void 0;
6
+ exports.stringifyNumber = stringifyNumber;
7
+ exports.stringifyString = stringifyString;
8
8
 
9
- var _addComment = require("../addComment");
9
+ var _addComment = require("./addComment");
10
10
 
11
- var _Node = require("../cst/Node");
11
+ var _constants = require("./constants");
12
12
 
13
- var _foldFlowLines = _interopRequireWildcard(require("../foldFlowLines"));
13
+ var _foldFlowLines = _interopRequireWildcard(require("./foldFlowLines"));
14
+
15
+ var _options = require("./tags/options");
14
16
 
15
17
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
16
18
 
17
- const strOptions = {
18
- defaultType: _Node.Type.PLAIN,
19
- doubleQuoted: {
20
- jsonEncoding: false,
21
- minMultiLineLength: 40
22
- },
23
- fold: {
24
- lineWidth: 80,
25
- minContentWidth: 20
19
+ function stringifyNumber({
20
+ format,
21
+ minFractionDigits,
22
+ tag,
23
+ value
24
+ }) {
25
+ if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
26
+ let n = JSON.stringify(value);
27
+
28
+ if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && /^\d/.test(n)) {
29
+ let i = n.indexOf('.');
30
+
31
+ if (i < 0) {
32
+ i = n.length;
33
+ n += '.';
34
+ }
35
+
36
+ let d = minFractionDigits - (n.length - i - 1);
37
+
38
+ while (d-- > 0) n += '0';
26
39
  }
27
- };
28
- exports.strOptions = strOptions;
29
40
 
30
- const lineLengthOverLimit = (str, limit) => {
41
+ return n;
42
+ }
43
+
44
+ function lineLengthOverLimit(str, limit) {
31
45
  const strLen = str.length;
32
46
  if (strLen <= limit) return false;
33
47
 
@@ -40,21 +54,7 @@ const lineLengthOverLimit = (str, limit) => {
40
54
  }
41
55
 
42
56
  return true;
43
- };
44
-
45
- const resolve = (doc, node) => {
46
- // on error, will return { str: string, errors: Error[] }
47
- const res = node.strValue;
48
- if (!res) return '';
49
- if (typeof res === 'string') return res;
50
- res.errors.forEach(error => {
51
- if (!error.source) error.source = node;
52
- doc.errors.push(error);
53
- });
54
- return res.str;
55
- };
56
-
57
- exports.resolve = resolve;
57
+ }
58
58
 
59
59
  function doubleQuotedString(value, {
60
60
  implicitKey,
@@ -63,7 +63,7 @@ function doubleQuotedString(value, {
63
63
  const {
64
64
  jsonEncoding,
65
65
  minMultiLineLength
66
- } = strOptions.doubleQuoted;
66
+ } = _options.strOptions.doubleQuoted;
67
67
  const json = JSON.stringify(value);
68
68
  if (jsonEncoding) return json;
69
69
  let str = '';
@@ -153,7 +153,7 @@ function doubleQuotedString(value, {
153
153
  }
154
154
 
155
155
  str = start ? str + json.slice(start) : json;
156
- return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, strOptions.fold);
156
+ return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, _options.strOptions.fold);
157
157
  }
158
158
 
159
159
  function singleQuotedString(value, ctx) {
@@ -170,7 +170,7 @@ function singleQuotedString(value, ctx) {
170
170
  }
171
171
 
172
172
  const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
173
- return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, strOptions.fold);
173
+ return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold);
174
174
  }
175
175
 
176
176
  function blockString({
@@ -187,7 +187,7 @@ function blockString({
187
187
  const indent = ctx.indent || (ctx.forceBlockIndent ? ' ' : '');
188
188
  const indentSize = indent ? '2' : '1'; // root is at -1
189
189
 
190
- const literal = type === _Node.Type.BLOCK_FOLDED ? false : type === _Node.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth - indent.length);
190
+ const literal = type === _constants.Type.BLOCK_FOLDED ? false : type === _constants.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, _options.strOptions.fold.lineWidth - indent.length);
191
191
  let header = literal ? '|' : '>';
192
192
  if (!value) return header + '\n';
193
193
  let wsStart = '';
@@ -235,7 +235,7 @@ function blockString({
235
235
  value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
236
236
  // ^ ind.line ^ empty ^ capture next empty lines only at end of indent
237
237
  .replace(/\n+/g, `$&${indent}`);
238
- const body = (0, _foldFlowLines.default)(`${wsStart}${value}${wsEnd}`, indent, _foldFlowLines.FOLD_BLOCK, strOptions.fold);
238
+ const body = (0, _foldFlowLines.default)(`${wsStart}${value}${wsEnd}`, indent, _foldFlowLines.FOLD_BLOCK, _options.strOptions.fold);
239
239
  return `${header}\n${indent}${body}`;
240
240
  }
241
241
 
@@ -246,6 +246,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
246
246
  value
247
247
  } = item;
248
248
  const {
249
+ actualString,
249
250
  implicitKey,
250
251
  indent,
251
252
  inFlow,
@@ -266,19 +267,19 @@ function plainString(item, ctx, onComment, onChompKeep) {
266
267
  return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
267
268
  }
268
269
 
269
- if (!implicitKey && !inFlow && type !== _Node.Type.PLAIN && value.indexOf('\n') !== -1) {
270
+ if (!implicitKey && !inFlow && type !== _constants.Type.PLAIN && value.indexOf('\n') !== -1) {
270
271
  // Where allowed & type not set explicitly, prefer block style for multiline strings
271
272
  return blockString(item, ctx, onComment, onChompKeep);
272
- } // Need to verify that output will be parsed as a string
273
-
273
+ }
274
274
 
275
- const str = value.replace(/\n+/g, `$&\n${indent}`);
275
+ const str = value.replace(/\n+/g, `$&\n${indent}`); // May need to verify that output will be parsed as a string, as plain numbers
276
+ // and booleans get parsed with those types, e.g. '42', 'true' & '0.9e-3'.
276
277
 
277
- if (typeof tags.resolveScalar(str).value !== 'string') {
278
+ if (actualString && /^[\w.+-]+$/.test(str) && typeof tags.resolveScalar(str).value !== 'string') {
278
279
  return doubleQuotedString(value, ctx);
279
280
  }
280
281
 
281
- const body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, strOptions.fold);
282
+ const body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold);
282
283
 
283
284
  if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
284
285
  if (onComment) onComment();
@@ -288,10 +289,10 @@ function plainString(item, ctx, onComment, onChompKeep) {
288
289
  return body;
289
290
  }
290
291
 
291
- function stringify(item, ctx, onComment, onChompKeep) {
292
+ function stringifyString(item, ctx, onComment, onChompKeep) {
292
293
  const {
293
294
  defaultType
294
- } = strOptions;
295
+ } = _options.strOptions;
295
296
  const {
296
297
  implicitKey,
297
298
  inFlow
@@ -310,17 +311,17 @@ function stringify(item, ctx, onComment, onChompKeep) {
310
311
 
311
312
  const _stringify = _type => {
312
313
  switch (_type) {
313
- case _Node.Type.BLOCK_FOLDED:
314
- case _Node.Type.BLOCK_LITERAL:
314
+ case _constants.Type.BLOCK_FOLDED:
315
+ case _constants.Type.BLOCK_LITERAL:
315
316
  return blockString(item, ctx, onComment, onChompKeep);
316
317
 
317
- case _Node.Type.QUOTE_DOUBLE:
318
+ case _constants.Type.QUOTE_DOUBLE:
318
319
  return doubleQuotedString(value, ctx);
319
320
 
320
- case _Node.Type.QUOTE_SINGLE:
321
+ case _constants.Type.QUOTE_SINGLE:
321
322
  return singleQuotedString(value, ctx);
322
323
 
323
- case _Node.Type.PLAIN:
324
+ case _constants.Type.PLAIN:
324
325
  return plainString(item, ctx, onComment, onChompKeep);
325
326
 
326
327
  default:
@@ -328,12 +329,12 @@ function stringify(item, ctx, onComment, onChompKeep) {
328
329
  }
329
330
  };
330
331
 
331
- if (type !== _Node.Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
332
+ if (type !== _constants.Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
332
333
  // force double quotes on control characters
333
- type = _Node.Type.QUOTE_DOUBLE;
334
- } else if ((implicitKey || inFlow) && (type === _Node.Type.BLOCK_FOLDED || type === _Node.Type.BLOCK_LITERAL)) {
334
+ type = _constants.Type.QUOTE_DOUBLE;
335
+ } else if ((implicitKey || inFlow) && (type === _constants.Type.BLOCK_FOLDED || type === _constants.Type.BLOCK_LITERAL)) {
335
336
  // should not happen; blocks are not valid inside flow containers
336
- type = _Node.Type.QUOTE_DOUBLE;
337
+ type = _constants.Type.QUOTE_DOUBLE;
337
338
  }
338
339
 
339
340
  let res = _stringify(type);
@@ -344,14 +345,4 @@ function stringify(item, ctx, onComment, onChompKeep) {
344
345
  }
345
346
 
346
347
  return res;
347
- }
348
-
349
- const str = {
350
- class: String,
351
- default: true,
352
- tag: 'tag:yaml.org,2002:str',
353
- resolve,
354
- stringify,
355
- options: strOptions
356
- };
357
- exports.str = str;
348
+ }
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _Scalar = _interopRequireDefault(require("../schema/Scalar"));
9
+
10
+ var _stringify = require("../stringify");
11
+
12
+ var _failsafe = _interopRequireDefault(require("./failsafe"));
13
+
14
+ var _options = require("./options");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ var _default = _failsafe.default.concat([{
19
+ identify: value => value == null,
20
+ createNode: (schema, value, ctx) => ctx.wrapScalars ? new _Scalar.default(null) : null,
21
+ default: true,
22
+ tag: 'tag:yaml.org,2002:null',
23
+ test: /^(?:~|[Nn]ull|NULL)?$/,
24
+ resolve: () => null,
25
+ options: _options.nullOptions,
26
+ stringify: () => _options.nullOptions.nullStr
27
+ }, {
28
+ identify: value => typeof value === 'boolean',
29
+ default: true,
30
+ tag: 'tag:yaml.org,2002:bool',
31
+ test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
32
+ resolve: str => str[0] === 't' || str[0] === 'T',
33
+ options: _options.boolOptions,
34
+ stringify: ({
35
+ value
36
+ }) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr
37
+ }, {
38
+ identify: value => typeof value === 'number',
39
+ default: true,
40
+ tag: 'tag:yaml.org,2002:int',
41
+ format: 'OCT',
42
+ test: /^0o([0-7]+)$/,
43
+ resolve: (str, oct) => parseInt(oct, 8),
44
+ stringify: ({
45
+ value
46
+ }) => '0o' + value.toString(8)
47
+ }, {
48
+ identify: value => typeof value === 'number',
49
+ default: true,
50
+ tag: 'tag:yaml.org,2002:int',
51
+ test: /^[-+]?[0-9]+$/,
52
+ resolve: str => parseInt(str, 10),
53
+ stringify: _stringify.stringifyNumber
54
+ }, {
55
+ identify: value => typeof value === 'number',
56
+ default: true,
57
+ tag: 'tag:yaml.org,2002:int',
58
+ format: 'HEX',
59
+ test: /^0x([0-9a-fA-F]+)$/,
60
+ resolve: (str, hex) => parseInt(hex, 16),
61
+ stringify: ({
62
+ value
63
+ }) => '0x' + value.toString(16)
64
+ }, {
65
+ identify: value => typeof value === 'number',
66
+ default: true,
67
+ tag: 'tag:yaml.org,2002:float',
68
+ test: /^(?:[-+]?\.inf|(\.nan))$/i,
69
+ resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
70
+ stringify: _stringify.stringifyNumber
71
+ }, {
72
+ identify: value => typeof value === 'number',
73
+ default: true,
74
+ tag: 'tag:yaml.org,2002:float',
75
+ format: 'EXP',
76
+ test: /^[-+]?(?:0|[1-9][0-9]*)(\.[0-9]*)?[eE][-+]?[0-9]+$/,
77
+ resolve: str => parseFloat(str),
78
+ stringify: ({
79
+ value
80
+ }) => Number(value).toExponential()
81
+ }, {
82
+ identify: value => typeof value === 'number',
83
+ default: true,
84
+ tag: 'tag:yaml.org,2002:float',
85
+ test: /^[-+]?(?:0|[1-9][0-9]*)\.([0-9]*)$/,
86
+
87
+ resolve(str, frac) {
88
+ const node = new _Scalar.default(parseFloat(str));
89
+ if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
90
+ return node;
91
+ },
92
+
93
+ stringify: _stringify.stringifyNumber
94
+ }]);
95
+
96
+ exports.default = _default;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _map = _interopRequireDefault(require("./map"));
9
+
10
+ var _seq = _interopRequireDefault(require("./seq"));
11
+
12
+ var _string = _interopRequireDefault(require("./string"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ var _default = [_map.default, _seq.default, _string.default];
17
+ exports.default = _default;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _Map = _interopRequireDefault(require("../../schema/Map"));
9
+
10
+ var _parseMap = _interopRequireDefault(require("../../schema/parseMap"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ function createMap(schema, obj, ctx) {
15
+ const map = new _Map.default();
16
+
17
+ if (obj instanceof Map) {
18
+ for (const [key, value] of obj) map.items.push(schema.createPair(key, value, ctx));
19
+ } else if (obj && typeof obj === 'object') {
20
+ for (const key of Object.keys(obj)) map.items.push(schema.createPair(key, obj[key], ctx));
21
+ }
22
+
23
+ return map;
24
+ }
25
+
26
+ var _default = {
27
+ createNode: createMap,
28
+ default: true,
29
+ nodeClass: _Map.default,
30
+ tag: 'tag:yaml.org,2002:map',
31
+ resolve: _parseMap.default
32
+ };
33
+ exports.default = _default;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _parseSeq = _interopRequireDefault(require("../../schema/parseSeq"));
9
+
10
+ var _Seq = _interopRequireDefault(require("../../schema/Seq"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ function createSeq(schema, obj, ctx) {
15
+ const seq = new _Seq.default();
16
+
17
+ if (obj && obj[Symbol.iterator]) {
18
+ for (const it of obj) {
19
+ const v = schema.createNode(it, ctx.wrapScalars, null, ctx);
20
+ seq.items.push(v);
21
+ }
22
+ }
23
+
24
+ return seq;
25
+ }
26
+
27
+ var _default = {
28
+ createNode: createSeq,
29
+ default: true,
30
+ nodeClass: _Seq.default,
31
+ tag: 'tag:yaml.org,2002:seq',
32
+ resolve: _parseSeq.default
33
+ };
34
+ exports.default = _default;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.resolveString = void 0;
7
+
8
+ var _stringify = require("../../stringify");
9
+
10
+ var _options = require("../options");
11
+
12
+ const resolveString = (doc, node) => {
13
+ // on error, will return { str: string, errors: Error[] }
14
+ const res = node.strValue;
15
+ if (!res) return '';
16
+ if (typeof res === 'string') return res;
17
+ res.errors.forEach(error => {
18
+ if (!error.source) error.source = node;
19
+ doc.errors.push(error);
20
+ });
21
+ return res.str;
22
+ };
23
+
24
+ exports.resolveString = resolveString;
25
+ var _default = {
26
+ identify: value => typeof value === 'string',
27
+ default: true,
28
+ tag: 'tag:yaml.org,2002:str',
29
+ resolve: resolveString,
30
+
31
+ stringify(item, ctx, onComment, onChompKeep) {
32
+ ctx = Object.assign({
33
+ actualString: true
34
+ }, ctx);
35
+ return (0, _stringify.stringifyString)(item, ctx, onComment, onChompKeep);
36
+ },
37
+
38
+ options: _options.strOptions
39
+ };
40
+ exports.default = _default;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.tags = exports.schemas = void 0;
7
+
8
+ var _core = _interopRequireDefault(require("./core"));
9
+
10
+ var _failsafe = _interopRequireDefault(require("./failsafe"));
11
+
12
+ var _json = _interopRequireDefault(require("./json"));
13
+
14
+ var _yaml = _interopRequireDefault(require("./yaml-1.1"));
15
+
16
+ var _map = _interopRequireDefault(require("./failsafe/map"));
17
+
18
+ var _seq = _interopRequireDefault(require("./failsafe/seq"));
19
+
20
+ var _binary = _interopRequireDefault(require("./yaml-1.1/binary"));
21
+
22
+ var _omap = _interopRequireDefault(require("./yaml-1.1/omap"));
23
+
24
+ var _pairs = _interopRequireDefault(require("./yaml-1.1/pairs"));
25
+
26
+ var _set = _interopRequireDefault(require("./yaml-1.1/set"));
27
+
28
+ var _timestamp = require("./yaml-1.1/timestamp");
29
+
30
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+
32
+ const schemas = {
33
+ core: _core.default,
34
+ failsafe: _failsafe.default,
35
+ json: _json.default,
36
+ yaml11: _yaml.default
37
+ };
38
+ exports.schemas = schemas;
39
+ const tags = {
40
+ binary: _binary.default,
41
+ floatTime: _timestamp.floatTime,
42
+ intTime: _timestamp.intTime,
43
+ map: _map.default,
44
+ omap: _omap.default,
45
+ pairs: _pairs.default,
46
+ seq: _seq.default,
47
+ set: _set.default,
48
+ timestamp: _timestamp.timestamp
49
+ };
50
+ exports.tags = tags;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _map = _interopRequireDefault(require("./failsafe/map"));
9
+
10
+ var _seq = _interopRequireDefault(require("./failsafe/seq"));
11
+
12
+ var _Scalar = _interopRequireDefault(require("../schema/Scalar"));
13
+
14
+ var _string = require("./failsafe/string");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ const schema = [_map.default, _seq.default, {
19
+ identify: value => typeof value === 'string',
20
+ default: true,
21
+ tag: 'tag:yaml.org,2002:str',
22
+ resolve: _string.resolveString,
23
+ stringify: value => JSON.stringify(value)
24
+ }, {
25
+ identify: value => value == null,
26
+ createNode: (schema, value, ctx) => ctx.wrapScalars ? new _Scalar.default(null) : null,
27
+ default: true,
28
+ tag: 'tag:yaml.org,2002:null',
29
+ test: /^null$/,
30
+ resolve: () => null,
31
+ stringify: value => JSON.stringify(value)
32
+ }, {
33
+ identify: value => typeof value === 'boolean',
34
+ default: true,
35
+ tag: 'tag:yaml.org,2002:bool',
36
+ test: /^true$/,
37
+ resolve: () => true,
38
+ stringify: value => JSON.stringify(value)
39
+ }, {
40
+ identify: value => typeof value === 'boolean',
41
+ default: true,
42
+ tag: 'tag:yaml.org,2002:bool',
43
+ test: /^false$/,
44
+ resolve: () => false,
45
+ stringify: value => JSON.stringify(value)
46
+ }, {
47
+ identify: value => typeof value === 'number',
48
+ default: true,
49
+ tag: 'tag:yaml.org,2002:int',
50
+ test: /^-?(?:0|[1-9][0-9]*)$/,
51
+ resolve: str => parseInt(str, 10),
52
+ stringify: value => JSON.stringify(value)
53
+ }, {
54
+ identify: value => typeof value === 'number',
55
+ default: true,
56
+ tag: 'tag:yaml.org,2002:float',
57
+ test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
58
+ resolve: str => parseFloat(str),
59
+ stringify: value => JSON.stringify(value)
60
+ }];
61
+
62
+ schema.scalarFallback = str => {
63
+ throw new SyntaxError(`Unresolved plain scalar ${JSON.stringify(str)}`);
64
+ };
65
+
66
+ var _default = schema;
67
+ exports.default = _default;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.strOptions = exports.nullOptions = exports.boolOptions = exports.binaryOptions = void 0;
7
+
8
+ var _constants = require("../constants");
9
+
10
+ const binaryOptions = {
11
+ defaultType: _constants.Type.BLOCK_LITERAL,
12
+ lineWidth: 76
13
+ };
14
+ exports.binaryOptions = binaryOptions;
15
+ const boolOptions = {
16
+ trueStr: 'true',
17
+ falseStr: 'false'
18
+ };
19
+ exports.boolOptions = boolOptions;
20
+ const nullOptions = {
21
+ nullStr: 'null'
22
+ };
23
+ exports.nullOptions = nullOptions;
24
+ const strOptions = {
25
+ defaultType: _constants.Type.PLAIN,
26
+ doubleQuoted: {
27
+ jsonEncoding: false,
28
+ minMultiLineLength: 40
29
+ },
30
+ fold: {
31
+ lineWidth: 80,
32
+ minContentWidth: 20
33
+ }
34
+ };
35
+ exports.strOptions = strOptions;