yaml 1.3.1 → 1.5.1

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 +28 -22
  2. package/browser/dist/Anchors.js +12 -10
  3. package/browser/dist/Document.js +167 -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 +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 +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 +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 +86 -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 +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 +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 +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
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", {
9
9
  });
10
10
  exports.default = parseMap;
11
11
 
12
- var _Node = require("../cst/Node");
12
+ var _constants = require("../constants");
13
13
 
14
14
  var _PlainValue = _interopRequireDefault(require("../cst/PlainValue"));
15
15
 
@@ -26,13 +26,13 @@ var _parseUtils = require("./parseUtils");
26
26
  var _Alias = _interopRequireDefault(require("./Alias"));
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
  var msg = "A ".concat(cst.type, " node cannot be resolved as a mapping");
31
31
  doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
32
32
  return null;
33
33
  }
34
34
 
35
- var _ref = cst.type === _Node.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst),
35
+ var _ref = cst.type === _constants.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst),
36
36
  comments = _ref.comments,
37
37
  items = _ref.items;
38
38
 
@@ -52,7 +52,7 @@ function parseMap(doc, cst) {
52
52
  // During parsing, alias sources are CST nodes; to account for
53
53
  // circular references their resolved values can't be used here.
54
54
  var type = node.source.type;
55
- if (type === _Node.Type.MAP || type === _Node.Type.FLOW_MAP) return false;
55
+ if (type === _constants.Type.MAP || type === _constants.Type.FLOW_MAP) return false;
56
56
  return error = 'Merge nodes aliases can only point to maps';
57
57
  }
58
58
 
@@ -86,7 +86,7 @@ var valueHasPairComment = function valueHasPairComment(_ref2) {
86
86
  if (props.length === 0) return false;
87
87
  var start = props[0].start;
88
88
  if (node && start > node.valueRange.start) return false;
89
- if (src[start] !== _Node.Char.COMMENT) return false;
89
+ if (src[start] !== _constants.Char.COMMENT) return false;
90
90
 
91
91
  for (var i = lineStart; i < start; ++i) {
92
92
  if (src[i] === '\n') return false;
@@ -97,7 +97,7 @@ var valueHasPairComment = function valueHasPairComment(_ref2) {
97
97
 
98
98
  function resolvePairComment(item, pair) {
99
99
  if (!valueHasPairComment(item)) return;
100
- var comment = item.getPropValue(0, _Node.Char.COMMENT, true);
100
+ var comment = item.getPropValue(0, _constants.Char.COMMENT, true);
101
101
  var found = false;
102
102
  var cb = pair.value.commentBefore;
103
103
 
@@ -126,14 +126,14 @@ function resolveBlockMapItems(doc, cst) {
126
126
  var item = cst.items[i];
127
127
 
128
128
  switch (item.type) {
129
- case _Node.Type.BLANK_LINE:
129
+ case _constants.Type.BLANK_LINE:
130
130
  comments.push({
131
131
  afterKey: !!key,
132
132
  before: items.length
133
133
  });
134
134
  break;
135
135
 
136
- case _Node.Type.COMMENT:
136
+ case _constants.Type.COMMENT:
137
137
  comments.push({
138
138
  afterKey: !!key,
139
139
  before: items.length,
@@ -141,19 +141,19 @@ function resolveBlockMapItems(doc, cst) {
141
141
  });
142
142
  break;
143
143
 
144
- case _Node.Type.MAP_KEY:
144
+ case _constants.Type.MAP_KEY:
145
145
  if (key !== undefined) items.push(new _Pair.default(key));
146
146
  if (item.error) doc.errors.push(item.error);
147
147
  key = doc.resolveNode(item.node);
148
148
  keyStart = null;
149
149
  break;
150
150
 
151
- case _Node.Type.MAP_VALUE:
151
+ case _constants.Type.MAP_VALUE:
152
152
  {
153
153
  if (key === undefined) key = null;
154
154
  if (item.error) doc.errors.push(item.error);
155
155
 
156
- if (!item.context.atLineStart && item.node && item.node.type === _Node.Type.MAP && !item.node.context.atLineStart) {
156
+ if (!item.context.atLineStart && item.node && item.node.type === _constants.Type.MAP && !item.node.context.atLineStart) {
157
157
  var msg = 'Nested mappings are not allowed in compact mappings';
158
158
  doc.errors.push(new _errors.YAMLSemanticError(item.node, msg));
159
159
  }
@@ -164,7 +164,7 @@ function resolveBlockMapItems(doc, cst) {
164
164
  // Comments on an empty mapping value need to be preserved, so we
165
165
  // need to construct a minimal empty node here to use instead of the
166
166
  // missing `item.node`. -- eemeli/yaml#19
167
- valueNode = new _PlainValue.default(_Node.Type.PLAIN, []);
167
+ valueNode = new _PlainValue.default(_constants.Type.PLAIN, []);
168
168
  valueNode.context = {
169
169
  parent: item,
170
170
  src: item.context.src
@@ -205,11 +205,11 @@ function resolveBlockMapItems(doc, cst) {
205
205
  var nextItem = cst.items[j];
206
206
 
207
207
  switch (nextItem && nextItem.type) {
208
- case _Node.Type.BLANK_LINE:
209
- case _Node.Type.COMMENT:
208
+ case _constants.Type.BLANK_LINE:
209
+ case _constants.Type.COMMENT:
210
210
  continue next;
211
211
 
212
- case _Node.Type.MAP_VALUE:
212
+ case _constants.Type.MAP_VALUE:
213
213
  break next;
214
214
 
215
215
  default:
@@ -287,12 +287,12 @@ function resolveFlowMapItems(doc, cst) {
287
287
  }
288
288
 
289
289
  doc.errors.push(new _errors.YAMLSyntaxError(cst, "Flow map contains an unexpected ".concat(char)));
290
- } else if (item.type === _Node.Type.BLANK_LINE) {
290
+ } else if (item.type === _constants.Type.BLANK_LINE) {
291
291
  comments.push({
292
292
  afterKey: !!key,
293
293
  before: items.length
294
294
  });
295
- } else if (item.type === _Node.Type.COMMENT) {
295
+ } else if (item.type === _constants.Type.COMMENT) {
296
296
  comments.push({
297
297
  afterKey: !!key,
298
298
  before: items.length,
@@ -316,7 +316,4 @@ function resolveFlowMapItems(doc, cst) {
316
316
  comments: comments,
317
317
  items: items
318
318
  };
319
- }
320
-
321
- module.exports = exports.default;
322
- module.exports.default = exports.default;
319
+ }
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = parseSeq;
9
9
 
10
- var _Node = require("../cst/Node");
10
+ var _constants = require("../constants");
11
11
 
12
12
  var _errors = require("../errors");
13
13
 
@@ -18,13 +18,13 @@ var _parseUtils = require("./parseUtils");
18
18
  var _Seq = _interopRequireDefault(require("./Seq"));
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
  var msg = "A ".concat(cst.type, " node cannot be resolved as a sequence");
23
23
  doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
24
24
  return null;
25
25
  }
26
26
 
27
- var _ref = cst.type === _Node.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst),
27
+ var _ref = cst.type === _constants.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst),
28
28
  comments = _ref.comments,
29
29
  items = _ref.items;
30
30
 
@@ -43,20 +43,20 @@ function resolveBlockSeqItems(doc, cst) {
43
43
  var 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
 
@@ -128,11 +128,11 @@ function resolveFlowSeqItems(doc, cst) {
128
128
 
129
129
  doc.errors.push(new _errors.YAMLSyntaxError(cst, _msg));
130
130
  }
131
- } else if (item.type === _Node.Type.BLANK_LINE) {
131
+ } else if (item.type === _constants.Type.BLANK_LINE) {
132
132
  comments.push({
133
133
  before: items.length
134
134
  });
135
- } else if (item.type === _Node.Type.COMMENT) {
135
+ } else if (item.type === _constants.Type.COMMENT) {
136
136
  comments.push({
137
137
  comment: item.comment,
138
138
  before: items.length
@@ -164,7 +164,4 @@ function resolveFlowSeqItems(doc, cst) {
164
164
  comments: comments,
165
165
  items: items
166
166
  };
167
- }
168
-
169
- module.exports = exports.default;
170
- module.exports.default = exports.default;
167
+ }
@@ -5,29 +5,44 @@ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWild
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.stringify = stringify;
9
- exports.str = exports.resolve = exports.strOptions = void 0;
8
+ exports.stringifyNumber = stringifyNumber;
9
+ exports.stringifyString = stringifyString;
10
10
 
11
- var _addComment = require("../addComment");
11
+ var _addComment = require("./addComment");
12
12
 
13
- var _Node = require("../cst/Node");
13
+ var _constants = require("./constants");
14
14
 
15
- var _foldFlowLines = _interopRequireWildcard(require("../foldFlowLines"));
15
+ var _foldFlowLines = _interopRequireWildcard(require("./foldFlowLines"));
16
16
 
17
- var strOptions = {
18
- defaultType: _Node.Type.PLAIN,
19
- doubleQuoted: {
20
- jsonEncoding: false,
21
- minMultiLineLength: 40
22
- },
23
- fold: {
24
- lineWidth: 80,
25
- minContentWidth: 20
17
+ var _options = require("./tags/options");
18
+
19
+ function stringifyNumber(_ref) {
20
+ var format = _ref.format,
21
+ minFractionDigits = _ref.minFractionDigits,
22
+ tag = _ref.tag,
23
+ value = _ref.value;
24
+ if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
25
+ var n = JSON.stringify(value);
26
+
27
+ if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && /^\d/.test(n)) {
28
+ var i = n.indexOf('.');
29
+
30
+ if (i < 0) {
31
+ i = n.length;
32
+ n += '.';
33
+ }
34
+
35
+ var d = minFractionDigits - (n.length - i - 1);
36
+
37
+ while (d-- > 0) {
38
+ n += '0';
39
+ }
26
40
  }
27
- };
28
- exports.strOptions = strOptions;
29
41
 
30
- var lineLengthOverLimit = function lineLengthOverLimit(str, limit) {
42
+ return n;
43
+ }
44
+
45
+ function lineLengthOverLimit(str, limit) {
31
46
  var strLen = str.length;
32
47
  if (strLen <= limit) return false;
33
48
 
@@ -40,26 +55,12 @@ var lineLengthOverLimit = function lineLengthOverLimit(str, limit) {
40
55
  }
41
56
 
42
57
  return true;
43
- };
44
-
45
- var resolve = function resolve(doc, node) {
46
- // on error, will return { str: string, errors: Error[] }
47
- var res = node.strValue;
48
- if (!res) return '';
49
- if (typeof res === 'string') return res;
50
- res.errors.forEach(function (error) {
51
- if (!error.source) error.source = node;
52
- doc.errors.push(error);
53
- });
54
- return res.str;
55
- };
56
-
57
- exports.resolve = resolve;
58
+ }
58
59
 
59
- function doubleQuotedString(value, _ref) {
60
- var implicitKey = _ref.implicitKey,
61
- indent = _ref.indent;
62
- var _strOptions$doubleQuo = strOptions.doubleQuoted,
60
+ function doubleQuotedString(value, _ref2) {
61
+ var implicitKey = _ref2.implicitKey,
62
+ indent = _ref2.indent;
63
+ var _strOptions$doubleQuo = _options.strOptions.doubleQuoted,
63
64
  jsonEncoding = _strOptions$doubleQuo.jsonEncoding,
64
65
  minMultiLineLength = _strOptions$doubleQuo.minMultiLineLength;
65
66
  var json = JSON.stringify(value);
@@ -151,7 +152,7 @@ function doubleQuotedString(value, _ref) {
151
152
  }
152
153
 
153
154
  str = start ? str + json.slice(start) : json;
154
- return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, strOptions.fold);
155
+ return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, _options.strOptions.fold);
155
156
  }
156
157
 
157
158
  function singleQuotedString(value, ctx) {
@@ -166,13 +167,13 @@ function singleQuotedString(value, ctx) {
166
167
  }
167
168
 
168
169
  var res = "'" + value.replace(/'/g, "''").replace(/\n+/g, "$&\n".concat(indent)) + "'";
169
- return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, strOptions.fold);
170
+ return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold);
170
171
  }
171
172
 
172
- function blockString(_ref2, ctx, onComment, onChompKeep) {
173
- var comment = _ref2.comment,
174
- type = _ref2.type,
175
- value = _ref2.value;
173
+ function blockString(_ref3, ctx, onComment, onChompKeep) {
174
+ var comment = _ref3.comment,
175
+ type = _ref3.type,
176
+ value = _ref3.value;
176
177
 
177
178
  // 1. Block can't end in whitespace unless the last line is non-empty.
178
179
  // 2. Strings consisting of only whitespace are best rendered explicitly.
@@ -183,7 +184,7 @@ function blockString(_ref2, ctx, onComment, onChompKeep) {
183
184
  var indent = ctx.indent || (ctx.forceBlockIndent ? ' ' : '');
184
185
  var indentSize = indent ? '2' : '1'; // root is at -1
185
186
 
186
- var literal = type === _Node.Type.BLOCK_FOLDED ? false : type === _Node.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth - indent.length);
187
+ var literal = type === _constants.Type.BLOCK_FOLDED ? false : type === _constants.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, _options.strOptions.fold.lineWidth - indent.length);
187
188
  var header = literal ? '|' : '>';
188
189
  if (!value) return header + '\n';
189
190
  var wsStart = '';
@@ -231,7 +232,7 @@ function blockString(_ref2, ctx, onComment, onChompKeep) {
231
232
  value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
232
233
  // ^ ind.line ^ empty ^ capture next empty lines only at end of indent
233
234
  .replace(/\n+/g, "$&".concat(indent));
234
- var body = (0, _foldFlowLines.default)("".concat(wsStart).concat(value).concat(wsEnd), indent, _foldFlowLines.FOLD_BLOCK, strOptions.fold);
235
+ var body = (0, _foldFlowLines.default)("".concat(wsStart).concat(value).concat(wsEnd), indent, _foldFlowLines.FOLD_BLOCK, _options.strOptions.fold);
235
236
  return "".concat(header, "\n").concat(indent).concat(body);
236
237
  }
237
238
 
@@ -239,7 +240,8 @@ function plainString(item, ctx, onComment, onChompKeep) {
239
240
  var comment = item.comment,
240
241
  type = item.type,
241
242
  value = item.value;
242
- var implicitKey = ctx.implicitKey,
243
+ var actualString = ctx.actualString,
244
+ implicitKey = ctx.implicitKey,
243
245
  indent = ctx.indent,
244
246
  inFlow = ctx.inFlow,
245
247
  tags = ctx.tags;
@@ -258,19 +260,19 @@ function plainString(item, ctx, onComment, onChompKeep) {
258
260
  return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
259
261
  }
260
262
 
261
- if (!implicitKey && !inFlow && type !== _Node.Type.PLAIN && value.indexOf('\n') !== -1) {
263
+ if (!implicitKey && !inFlow && type !== _constants.Type.PLAIN && value.indexOf('\n') !== -1) {
262
264
  // Where allowed & type not set explicitly, prefer block style for multiline strings
263
265
  return blockString(item, ctx, onComment, onChompKeep);
264
- } // Need to verify that output will be parsed as a string
265
-
266
+ }
266
267
 
267
- var str = value.replace(/\n+/g, "$&\n".concat(indent));
268
+ var str = value.replace(/\n+/g, "$&\n".concat(indent)); // May need to verify that output will be parsed as a string, as plain numbers
269
+ // and booleans get parsed with those types, e.g. '42', 'true' & '0.9e-3'.
268
270
 
269
- if (typeof tags.resolveScalar(str).value !== 'string') {
271
+ if (actualString && /^[\w.+-]+$/.test(str) && typeof tags.resolveScalar(str).value !== 'string') {
270
272
  return doubleQuotedString(value, ctx);
271
273
  }
272
274
 
273
- var body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, strOptions.fold);
275
+ var body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold);
274
276
 
275
277
  if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
276
278
  if (onComment) onComment();
@@ -280,8 +282,8 @@ function plainString(item, ctx, onComment, onChompKeep) {
280
282
  return body;
281
283
  }
282
284
 
283
- function stringify(item, ctx, onComment, onChompKeep) {
284
- var defaultType = strOptions.defaultType;
285
+ function stringifyString(item, ctx, onComment, onChompKeep) {
286
+ var defaultType = _options.strOptions.defaultType;
285
287
  var implicitKey = ctx.implicitKey,
286
288
  inFlow = ctx.inFlow;
287
289
  var _item = item,
@@ -297,17 +299,17 @@ function stringify(item, ctx, onComment, onChompKeep) {
297
299
 
298
300
  var _stringify = function _stringify(_type) {
299
301
  switch (_type) {
300
- case _Node.Type.BLOCK_FOLDED:
301
- case _Node.Type.BLOCK_LITERAL:
302
+ case _constants.Type.BLOCK_FOLDED:
303
+ case _constants.Type.BLOCK_LITERAL:
302
304
  return blockString(item, ctx, onComment, onChompKeep);
303
305
 
304
- case _Node.Type.QUOTE_DOUBLE:
306
+ case _constants.Type.QUOTE_DOUBLE:
305
307
  return doubleQuotedString(value, ctx);
306
308
 
307
- case _Node.Type.QUOTE_SINGLE:
309
+ case _constants.Type.QUOTE_SINGLE:
308
310
  return singleQuotedString(value, ctx);
309
311
 
310
- case _Node.Type.PLAIN:
312
+ case _constants.Type.PLAIN:
311
313
  return plainString(item, ctx, onComment, onChompKeep);
312
314
 
313
315
  default:
@@ -315,12 +317,12 @@ function stringify(item, ctx, onComment, onChompKeep) {
315
317
  }
316
318
  };
317
319
 
318
- if (type !== _Node.Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
320
+ if (type !== _constants.Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
319
321
  // force double quotes on control characters
320
- type = _Node.Type.QUOTE_DOUBLE;
321
- } else if ((implicitKey || inFlow) && (type === _Node.Type.BLOCK_FOLDED || type === _Node.Type.BLOCK_LITERAL)) {
322
+ type = _constants.Type.QUOTE_DOUBLE;
323
+ } else if ((implicitKey || inFlow) && (type === _constants.Type.BLOCK_FOLDED || type === _constants.Type.BLOCK_LITERAL)) {
322
324
  // should not happen; blocks are not valid inside flow containers
323
- type = _Node.Type.QUOTE_DOUBLE;
325
+ type = _constants.Type.QUOTE_DOUBLE;
324
326
  }
325
327
 
326
328
  var res = _stringify(type);
@@ -331,14 +333,4 @@ function stringify(item, ctx, onComment, onChompKeep) {
331
333
  }
332
334
 
333
335
  return res;
334
- }
335
-
336
- var str = {
337
- class: String,
338
- default: true,
339
- tag: 'tag:yaml.org,2002:str',
340
- resolve: resolve,
341
- stringify: stringify,
342
- options: strOptions
343
- };
344
- exports.str = str;
336
+ }
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _Scalar = _interopRequireDefault(require("../schema/Scalar"));
11
+
12
+ var _stringify = require("../stringify");
13
+
14
+ var _failsafe = _interopRequireDefault(require("./failsafe"));
15
+
16
+ var _options = require("./options");
17
+
18
+ var _default = _failsafe.default.concat([{
19
+ identify: function identify(value) {
20
+ return value == null;
21
+ },
22
+ createNode: function createNode(schema, value, ctx) {
23
+ return ctx.wrapScalars ? new _Scalar.default(null) : null;
24
+ },
25
+ default: true,
26
+ tag: 'tag:yaml.org,2002:null',
27
+ test: /^(?:~|[Nn]ull|NULL)?$/,
28
+ resolve: function resolve() {
29
+ return null;
30
+ },
31
+ options: _options.nullOptions,
32
+ stringify: function stringify() {
33
+ return _options.nullOptions.nullStr;
34
+ }
35
+ }, {
36
+ identify: function identify(value) {
37
+ return typeof value === 'boolean';
38
+ },
39
+ default: true,
40
+ tag: 'tag:yaml.org,2002:bool',
41
+ test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
42
+ resolve: function resolve(str) {
43
+ return str[0] === 't' || str[0] === 'T';
44
+ },
45
+ options: _options.boolOptions,
46
+ stringify: function stringify(_ref) {
47
+ var value = _ref.value;
48
+ return value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr;
49
+ }
50
+ }, {
51
+ identify: function identify(value) {
52
+ return typeof value === 'number';
53
+ },
54
+ default: true,
55
+ tag: 'tag:yaml.org,2002:int',
56
+ format: 'OCT',
57
+ test: /^0o([0-7]+)$/,
58
+ resolve: function resolve(str, oct) {
59
+ return parseInt(oct, 8);
60
+ },
61
+ stringify: function stringify(_ref2) {
62
+ var value = _ref2.value;
63
+ return '0o' + value.toString(8);
64
+ }
65
+ }, {
66
+ identify: function identify(value) {
67
+ return typeof value === 'number';
68
+ },
69
+ default: true,
70
+ tag: 'tag:yaml.org,2002:int',
71
+ test: /^[-+]?[0-9]+$/,
72
+ resolve: function resolve(str) {
73
+ return parseInt(str, 10);
74
+ },
75
+ stringify: _stringify.stringifyNumber
76
+ }, {
77
+ identify: function identify(value) {
78
+ return typeof value === 'number';
79
+ },
80
+ default: true,
81
+ tag: 'tag:yaml.org,2002:int',
82
+ format: 'HEX',
83
+ test: /^0x([0-9a-fA-F]+)$/,
84
+ resolve: function resolve(str, hex) {
85
+ return parseInt(hex, 16);
86
+ },
87
+ stringify: function stringify(_ref3) {
88
+ var value = _ref3.value;
89
+ return '0x' + value.toString(16);
90
+ }
91
+ }, {
92
+ identify: function identify(value) {
93
+ return typeof value === 'number';
94
+ },
95
+ default: true,
96
+ tag: 'tag:yaml.org,2002:float',
97
+ test: /^(?:[-+]?\.inf|(\.nan))$/i,
98
+ resolve: function resolve(str, nan) {
99
+ return nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY;
100
+ },
101
+ stringify: _stringify.stringifyNumber
102
+ }, {
103
+ identify: function identify(value) {
104
+ return typeof value === 'number';
105
+ },
106
+ default: true,
107
+ tag: 'tag:yaml.org,2002:float',
108
+ format: 'EXP',
109
+ test: /^[-+]?(?:0|[1-9][0-9]*)(\.[0-9]*)?[eE][-+]?[0-9]+$/,
110
+ resolve: function resolve(str) {
111
+ return parseFloat(str);
112
+ },
113
+ stringify: function stringify(_ref4) {
114
+ var value = _ref4.value;
115
+ return Number(value).toExponential();
116
+ }
117
+ }, {
118
+ identify: function identify(value) {
119
+ return typeof value === 'number';
120
+ },
121
+ default: true,
122
+ tag: 'tag:yaml.org,2002:float',
123
+ test: /^[-+]?(?:0|[1-9][0-9]*)\.([0-9]*)$/,
124
+ resolve: function resolve(str, frac) {
125
+ var node = new _Scalar.default(parseFloat(str));
126
+ if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
127
+ return node;
128
+ },
129
+ stringify: _stringify.stringifyNumber
130
+ }]);
131
+
132
+ exports.default = _default;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _map = _interopRequireDefault(require("./map"));
11
+
12
+ var _seq = _interopRequireDefault(require("./seq"));
13
+
14
+ var _string = _interopRequireDefault(require("./string"));
15
+
16
+ var _default = [_map.default, _seq.default, _string.default];
17
+ exports.default = _default;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
+
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
+
14
+ var _Map = _interopRequireDefault(require("../../schema/Map"));
15
+
16
+ var _parseMap = _interopRequireDefault(require("../../schema/parseMap"));
17
+
18
+ function createMap(schema, obj, ctx) {
19
+ var map = new _Map.default();
20
+
21
+ if (obj instanceof Map) {
22
+ var _iteratorNormalCompletion = true;
23
+ var _didIteratorError = false;
24
+ var _iteratorError = undefined;
25
+
26
+ try {
27
+ for (var _iterator = obj[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
28
+ var _step$value = (0, _slicedToArray2.default)(_step.value, 2),
29
+ key = _step$value[0],
30
+ value = _step$value[1];
31
+
32
+ map.items.push(schema.createPair(key, value, ctx));
33
+ }
34
+ } catch (err) {
35
+ _didIteratorError = true;
36
+ _iteratorError = err;
37
+ } finally {
38
+ try {
39
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
40
+ _iterator.return();
41
+ }
42
+ } finally {
43
+ if (_didIteratorError) {
44
+ throw _iteratorError;
45
+ }
46
+ }
47
+ }
48
+ } else if (obj && (0, _typeof2.default)(obj) === 'object') {
49
+ for (var _i = 0, _Object$keys = Object.keys(obj); _i < _Object$keys.length; _i++) {
50
+ var key = _Object$keys[_i];
51
+ map.items.push(schema.createPair(key, obj[key], ctx));
52
+ }
53
+ }
54
+
55
+ return map;
56
+ }
57
+
58
+ var _default = {
59
+ createNode: createMap,
60
+ default: true,
61
+ nodeClass: _Map.default,
62
+ tag: 'tag:yaml.org,2002:map',
63
+ resolve: _parseMap.default
64
+ };
65
+ exports.default = _default;