yaml 1.3.2 → 1.6.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 (144) hide show
  1. package/README.md +4 -6
  2. package/browser/dist/Anchors.js +12 -10
  3. package/browser/dist/Document.js +170 -75
  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 +17 -11
  13. package/browser/dist/cst/FlowCollection.js +14 -8
  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 +1 -4
  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 +37 -7
  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 +37 -23
  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 +89 -45
  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 +17 -11
  79. package/dist/cst/FlowCollection.js +14 -8
  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 +1 -4
  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 +18 -5
  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 +30 -16
  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 +23 -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/polyfill.js +0 -27
  141. package/dist/schema/core.js +0 -79
  142. package/dist/schema/failsafe.js +0 -74
  143. package/dist/schema/json.js +0 -56
  144. package/dist/schema/yaml-1.1.js +0 -115
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = parseMap;
7
7
 
8
- var _Node = require("../cst/Node");
8
+ var _constants = require("../constants");
9
9
 
10
10
  var _PlainValue = _interopRequireDefault(require("../cst/PlainValue"));
11
11
 
@@ -26,7 +26,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
26
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
27
 
28
28
  function parseMap(doc, cst) {
29
- if (cst.type !== _Node.Type.MAP && cst.type !== _Node.Type.FLOW_MAP) {
29
+ if (cst.type !== _constants.Type.MAP && cst.type !== _constants.Type.FLOW_MAP) {
30
30
  const msg = `A ${cst.type} node cannot be resolved as a mapping`;
31
31
  doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
32
32
  return null;
@@ -35,7 +35,7 @@ function parseMap(doc, cst) {
35
35
  const {
36
36
  comments,
37
37
  items
38
- } = cst.type === _Node.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst);
38
+ } = cst.type === _constants.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst);
39
39
  const map = new _Map.default();
40
40
  map.items = items;
41
41
  (0, _parseUtils.resolveComments)(map, comments);
@@ -56,7 +56,7 @@ function parseMap(doc, cst) {
56
56
  const {
57
57
  type
58
58
  } = node.source;
59
- if (type === _Node.Type.MAP || type === _Node.Type.FLOW_MAP) return false;
59
+ if (type === _constants.Type.MAP || type === _constants.Type.FLOW_MAP) return false;
60
60
  return error = 'Merge nodes aliases can only point to maps';
61
61
  }
62
62
 
@@ -95,7 +95,7 @@ const valueHasPairComment = ({
95
95
  start
96
96
  } = props[0];
97
97
  if (node && start > node.valueRange.start) return false;
98
- if (src[start] !== _Node.Char.COMMENT) return false;
98
+ if (src[start] !== _constants.Char.COMMENT) return false;
99
99
 
100
100
  for (let i = lineStart; i < start; ++i) if (src[i] === '\n') return false;
101
101
 
@@ -104,7 +104,7 @@ const valueHasPairComment = ({
104
104
 
105
105
  function resolvePairComment(item, pair) {
106
106
  if (!valueHasPairComment(item)) return;
107
- const comment = item.getPropValue(0, _Node.Char.COMMENT, true);
107
+ const comment = item.getPropValue(0, _constants.Char.COMMENT, true);
108
108
  let found = false;
109
109
  const cb = pair.value.commentBefore;
110
110
 
@@ -133,14 +133,14 @@ function resolveBlockMapItems(doc, cst) {
133
133
  const item = cst.items[i];
134
134
 
135
135
  switch (item.type) {
136
- case _Node.Type.BLANK_LINE:
136
+ case _constants.Type.BLANK_LINE:
137
137
  comments.push({
138
138
  afterKey: !!key,
139
139
  before: items.length
140
140
  });
141
141
  break;
142
142
 
143
- case _Node.Type.COMMENT:
143
+ case _constants.Type.COMMENT:
144
144
  comments.push({
145
145
  afterKey: !!key,
146
146
  before: items.length,
@@ -148,19 +148,19 @@ function resolveBlockMapItems(doc, cst) {
148
148
  });
149
149
  break;
150
150
 
151
- case _Node.Type.MAP_KEY:
151
+ case _constants.Type.MAP_KEY:
152
152
  if (key !== undefined) items.push(new _Pair.default(key));
153
153
  if (item.error) doc.errors.push(item.error);
154
154
  key = doc.resolveNode(item.node);
155
155
  keyStart = null;
156
156
  break;
157
157
 
158
- case _Node.Type.MAP_VALUE:
158
+ case _constants.Type.MAP_VALUE:
159
159
  {
160
160
  if (key === undefined) key = null;
161
161
  if (item.error) doc.errors.push(item.error);
162
162
 
163
- if (!item.context.atLineStart && item.node && item.node.type === _Node.Type.MAP && !item.node.context.atLineStart) {
163
+ if (!item.context.atLineStart && item.node && item.node.type === _constants.Type.MAP && !item.node.context.atLineStart) {
164
164
  const msg = 'Nested mappings are not allowed in compact mappings';
165
165
  doc.errors.push(new _errors.YAMLSemanticError(item.node, msg));
166
166
  }
@@ -171,7 +171,7 @@ function resolveBlockMapItems(doc, cst) {
171
171
  // Comments on an empty mapping value need to be preserved, so we
172
172
  // need to construct a minimal empty node here to use instead of the
173
173
  // missing `item.node`. -- eemeli/yaml#19
174
- valueNode = new _PlainValue.default(_Node.Type.PLAIN, []);
174
+ valueNode = new _PlainValue.default(_constants.Type.PLAIN, []);
175
175
  valueNode.context = {
176
176
  parent: item,
177
177
  src: item.context.src
@@ -212,11 +212,11 @@ function resolveBlockMapItems(doc, cst) {
212
212
  const nextItem = cst.items[j];
213
213
 
214
214
  switch (nextItem && nextItem.type) {
215
- case _Node.Type.BLANK_LINE:
216
- case _Node.Type.COMMENT:
215
+ case _constants.Type.BLANK_LINE:
216
+ case _constants.Type.COMMENT:
217
217
  continue next;
218
218
 
219
- case _Node.Type.MAP_VALUE:
219
+ case _constants.Type.MAP_VALUE:
220
220
  break next;
221
221
 
222
222
  default:
@@ -296,12 +296,12 @@ function resolveFlowMapItems(doc, cst) {
296
296
  }
297
297
 
298
298
  doc.errors.push(new _errors.YAMLSyntaxError(cst, `Flow map contains an unexpected ${char}`));
299
- } else if (item.type === _Node.Type.BLANK_LINE) {
299
+ } else if (item.type === _constants.Type.BLANK_LINE) {
300
300
  comments.push({
301
301
  afterKey: !!key,
302
302
  before: items.length
303
303
  });
304
- } else if (item.type === _Node.Type.COMMENT) {
304
+ } else if (item.type === _constants.Type.COMMENT) {
305
305
  comments.push({
306
306
  afterKey: !!key,
307
307
  before: items.length,
@@ -325,7 +325,4 @@ function resolveFlowMapItems(doc, cst) {
325
325
  comments,
326
326
  items
327
327
  };
328
- }
329
-
330
- module.exports = exports.default;
331
- module.exports.default = exports.default;
328
+ }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = parseSeq;
7
7
 
8
- var _Node = require("../cst/Node");
8
+ var _constants = require("../constants");
9
9
 
10
10
  var _errors = require("../errors");
11
11
 
@@ -18,7 +18,7 @@ var _Seq = _interopRequireDefault(require("./Seq"));
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
20
20
  function parseSeq(doc, cst) {
21
- if (cst.type !== _Node.Type.SEQ && cst.type !== _Node.Type.FLOW_SEQ) {
21
+ if (cst.type !== _constants.Type.SEQ && cst.type !== _constants.Type.FLOW_SEQ) {
22
22
  const msg = `A ${cst.type} node cannot be resolved as a sequence`;
23
23
  doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
24
24
  return null;
@@ -27,7 +27,7 @@ function parseSeq(doc, cst) {
27
27
  const {
28
28
  comments,
29
29
  items
30
- } = cst.type === _Node.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst);
30
+ } = cst.type === _constants.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst);
31
31
  const seq = new _Seq.default();
32
32
  seq.items = items;
33
33
  (0, _parseUtils.resolveComments)(seq, comments);
@@ -43,20 +43,20 @@ function resolveBlockSeqItems(doc, cst) {
43
43
  const item = cst.items[i];
44
44
 
45
45
  switch (item.type) {
46
- case _Node.Type.BLANK_LINE:
46
+ case _constants.Type.BLANK_LINE:
47
47
  comments.push({
48
48
  before: items.length
49
49
  });
50
50
  break;
51
51
 
52
- case _Node.Type.COMMENT:
52
+ case _constants.Type.COMMENT:
53
53
  comments.push({
54
54
  comment: item.comment,
55
55
  before: items.length
56
56
  });
57
57
  break;
58
58
 
59
- case _Node.Type.SEQ_ITEM:
59
+ case _constants.Type.SEQ_ITEM:
60
60
  if (item.error) doc.errors.push(item.error);
61
61
  items.push(doc.resolveNode(item.node));
62
62
 
@@ -129,11 +129,11 @@ function resolveFlowSeqItems(doc, cst) {
129
129
  const msg = `Flow sequence contains an unexpected ${char}`;
130
130
  doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
131
131
  }
132
- } else if (item.type === _Node.Type.BLANK_LINE) {
132
+ } else if (item.type === _constants.Type.BLANK_LINE) {
133
133
  comments.push({
134
134
  before: items.length
135
135
  });
136
- } else if (item.type === _Node.Type.COMMENT) {
136
+ } else if (item.type === _constants.Type.COMMENT) {
137
137
  comments.push({
138
138
  comment: item.comment,
139
139
  before: items.length
@@ -164,7 +164,4 @@ function resolveFlowSeqItems(doc, cst) {
164
164
  comments,
165
165
  items
166
166
  };
167
- }
168
-
169
- module.exports = exports.default;
170
- module.exports.default = exports.default;
167
+ }
@@ -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;