yaml 1.7.2 → 1.8.3

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 (80) hide show
  1. package/browser/dist/Anchors.js +24 -39
  2. package/browser/dist/Document.js +86 -110
  3. package/browser/dist/addComment.js +2 -11
  4. package/browser/dist/constants.js +3 -11
  5. package/browser/dist/cst/Alias.js +19 -36
  6. package/browser/dist/cst/BlankLine.js +25 -38
  7. package/browser/dist/cst/BlockValue.js +29 -51
  8. package/browser/dist/cst/Collection.js +42 -65
  9. package/browser/dist/cst/CollectionItem.js +33 -55
  10. package/browser/dist/cst/Comment.js +19 -35
  11. package/browser/dist/cst/Directive.js +20 -56
  12. package/browser/dist/cst/Document.js +47 -71
  13. package/browser/dist/cst/FlowCollection.js +38 -61
  14. package/browser/dist/cst/Node.js +26 -46
  15. package/browser/dist/cst/ParseContext.js +100 -140
  16. package/browser/dist/cst/PlainValue.js +21 -38
  17. package/browser/dist/cst/QuoteDouble.js +26 -42
  18. package/browser/dist/cst/QuoteSingle.js +25 -41
  19. package/browser/dist/cst/Range.js +9 -19
  20. package/browser/dist/cst/parse.js +5 -16
  21. package/browser/dist/cst/source-utils.js +3 -14
  22. package/browser/dist/errors.js +42 -78
  23. package/browser/dist/foldFlowLines.js +4 -15
  24. package/browser/dist/index.js +24 -44
  25. package/browser/dist/listTagNames.js +10 -24
  26. package/browser/dist/schema/Alias.js +32 -49
  27. package/browser/dist/schema/Collection.js +54 -65
  28. package/browser/dist/schema/Map.js +39 -49
  29. package/browser/dist/schema/Merge.js +32 -52
  30. package/browser/dist/schema/Node.js +3 -12
  31. package/browser/dist/schema/Pair.js +40 -58
  32. package/browser/dist/schema/Scalar.js +18 -33
  33. package/browser/dist/schema/Seq.js +23 -40
  34. package/browser/dist/schema/index.js +66 -81
  35. package/browser/dist/schema/parseMap.js +52 -72
  36. package/browser/dist/schema/parseSeq.js +30 -45
  37. package/browser/dist/schema/parseUtils.js +12 -25
  38. package/browser/dist/stringify.js +39 -45
  39. package/browser/dist/tags/core.js +34 -40
  40. package/browser/dist/tags/failsafe/index.js +4 -17
  41. package/browser/dist/tags/failsafe/map.js +15 -24
  42. package/browser/dist/tags/failsafe/seq.js +7 -18
  43. package/browser/dist/tags/failsafe/string.js +7 -19
  44. package/browser/dist/tags/index.js +35 -49
  45. package/browser/dist/tags/json.js +11 -38
  46. package/browser/dist/tags/options.js +8 -20
  47. package/browser/dist/tags/yaml-1.1/binary.js +22 -33
  48. package/browser/dist/tags/yaml-1.1/index.js +34 -54
  49. package/browser/dist/tags/yaml-1.1/omap.js +39 -58
  50. package/browser/dist/tags/yaml-1.1/pairs.js +15 -34
  51. package/browser/dist/tags/yaml-1.1/set.js +35 -61
  52. package/browser/dist/tags/yaml-1.1/timestamp.js +6 -16
  53. package/browser/dist/test-events.js +7 -19
  54. package/browser/dist/toJSON.js +1 -8
  55. package/browser/dist/warnings.js +3 -15
  56. package/dist/Document.js +1 -1
  57. package/dist/cst/BlankLine.js +4 -0
  58. package/dist/cst/BlockValue.js +1 -1
  59. package/dist/cst/Directive.js +0 -16
  60. package/dist/cst/Node.js +0 -5
  61. package/dist/cst/ParseContext.js +41 -55
  62. package/dist/schema/Alias.js +1 -0
  63. package/dist/schema/Collection.js +22 -5
  64. package/dist/schema/Map.js +12 -5
  65. package/dist/schema/Pair.js +1 -0
  66. package/dist/schema/index.js +10 -5
  67. package/dist/schema/parseMap.js +1 -1
  68. package/dist/stringify.js +15 -8
  69. package/dist/tags/core.js +31 -13
  70. package/dist/tags/failsafe/map.js +5 -1
  71. package/dist/tags/failsafe/seq.js +1 -1
  72. package/dist/tags/index.js +13 -1
  73. package/dist/tags/json.js +2 -9
  74. package/dist/tags/yaml-1.1/binary.js +8 -5
  75. package/dist/tags/yaml-1.1/index.js +6 -6
  76. package/dist/tags/yaml-1.1/pairs.js +1 -1
  77. package/dist/tags/yaml-1.1/set.js +1 -1
  78. package/package.json +43 -17
  79. package/types.mjs +20 -0
  80. package/util.mjs +24 -0
@@ -1,44 +1,29 @@
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 = parseSeq;
9
-
10
- var _constants = require("../constants");
11
-
12
- var _errors = require("../errors");
13
-
14
- var _Pair = _interopRequireDefault(require("./Pair"));
15
-
16
- var _parseUtils = require("./parseUtils");
17
-
18
- var _Seq = _interopRequireDefault(require("./Seq"));
19
-
20
- var _Collection = _interopRequireDefault(require("./Collection"));
21
-
22
- function parseSeq(doc, cst) {
23
- if (cst.type !== _constants.Type.SEQ && cst.type !== _constants.Type.FLOW_SEQ) {
1
+ import { Type } from '../constants';
2
+ import { YAMLSemanticError, YAMLSyntaxError, YAMLWarning } from '../errors';
3
+ import Pair from './Pair';
4
+ import { checkFlowCollectionEnd, checkKeyLength, resolveComments } from './parseUtils';
5
+ import Seq from './Seq';
6
+ import Collection from './Collection';
7
+ export default function parseSeq(doc, cst) {
8
+ if (cst.type !== Type.SEQ && cst.type !== Type.FLOW_SEQ) {
24
9
  var msg = "A ".concat(cst.type, " node cannot be resolved as a sequence");
25
- doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
10
+ doc.errors.push(new YAMLSyntaxError(cst, msg));
26
11
  return null;
27
12
  }
28
13
 
29
- var _ref = cst.type === _constants.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst),
14
+ var _ref = cst.type === Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst),
30
15
  comments = _ref.comments,
31
16
  items = _ref.items;
32
17
 
33
- var seq = new _Seq.default();
18
+ var seq = new Seq();
34
19
  seq.items = items;
35
- (0, _parseUtils.resolveComments)(seq, comments);
20
+ resolveComments(seq, comments);
36
21
 
37
22
  if (!doc.options.mapAsMap && items.some(function (it) {
38
- return it instanceof _Pair.default && it.key instanceof _Collection.default;
23
+ return it instanceof Pair && it.key instanceof Collection;
39
24
  })) {
40
25
  var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
41
- doc.warnings.push(new _errors.YAMLWarning(cst, warn));
26
+ doc.warnings.push(new YAMLWarning(cst, warn));
42
27
  }
43
28
 
44
29
  cst.resolved = seq;
@@ -53,33 +38,33 @@ function resolveBlockSeqItems(doc, cst) {
53
38
  var item = cst.items[i];
54
39
 
55
40
  switch (item.type) {
56
- case _constants.Type.BLANK_LINE:
41
+ case Type.BLANK_LINE:
57
42
  comments.push({
58
43
  before: items.length
59
44
  });
60
45
  break;
61
46
 
62
- case _constants.Type.COMMENT:
47
+ case Type.COMMENT:
63
48
  comments.push({
64
49
  comment: item.comment,
65
50
  before: items.length
66
51
  });
67
52
  break;
68
53
 
69
- case _constants.Type.SEQ_ITEM:
54
+ case Type.SEQ_ITEM:
70
55
  if (item.error) doc.errors.push(item.error);
71
56
  items.push(doc.resolveNode(item.node));
72
57
 
73
58
  if (item.hasProps) {
74
59
  var msg = 'Sequence items cannot have tags or anchors before the - indicator';
75
- doc.errors.push(new _errors.YAMLSemanticError(item, msg));
60
+ doc.errors.push(new YAMLSemanticError(item, msg));
76
61
  }
77
62
 
78
63
  break;
79
64
 
80
65
  default:
81
66
  if (item.error) doc.errors.push(item.error);
82
- doc.errors.push(new _errors.YAMLSyntaxError(item, "Unexpected ".concat(item.type, " node in sequence")));
67
+ doc.errors.push(new YAMLSyntaxError(item, "Unexpected ".concat(item.type, " node in sequence")));
83
68
  }
84
69
  }
85
70
 
@@ -106,7 +91,7 @@ function resolveFlowSeqItems(doc, cst) {
106
91
 
107
92
  if (char !== ':' && (explicitKey || key !== undefined)) {
108
93
  if (explicitKey && key === undefined) key = next ? items.pop() : null;
109
- items.push(new _Pair.default(key));
94
+ items.push(new Pair(key));
110
95
  explicitKey = false;
111
96
  key = undefined;
112
97
  keyStart = null;
@@ -120,14 +105,14 @@ function resolveFlowSeqItems(doc, cst) {
120
105
  if (next === ',') {
121
106
  key = items.pop();
122
107
 
123
- if (key instanceof _Pair.default) {
108
+ if (key instanceof Pair) {
124
109
  var msg = 'Chaining flow sequence pairs is invalid';
125
- var err = new _errors.YAMLSemanticError(cst, msg);
110
+ var err = new YAMLSemanticError(cst, msg);
126
111
  err.offset = offset;
127
112
  doc.errors.push(err);
128
113
  }
129
114
 
130
- if (!explicitKey) (0, _parseUtils.checkKeyLength)(doc.errors, cst, i, key, keyStart);
115
+ if (!explicitKey) checkKeyLength(doc.errors, cst, i, key, keyStart);
131
116
  } else {
132
117
  key = null;
133
118
  }
@@ -139,16 +124,16 @@ function resolveFlowSeqItems(doc, cst) {
139
124
  } else if (next === '[' || char !== ']' || i < cst.items.length - 1) {
140
125
  var _msg = "Flow sequence contains an unexpected ".concat(char);
141
126
 
142
- var _err = new _errors.YAMLSyntaxError(cst, _msg);
127
+ var _err = new YAMLSyntaxError(cst, _msg);
143
128
 
144
129
  _err.offset = offset;
145
130
  doc.errors.push(_err);
146
131
  }
147
- } else if (item.type === _constants.Type.BLANK_LINE) {
132
+ } else if (item.type === Type.BLANK_LINE) {
148
133
  comments.push({
149
134
  before: items.length
150
135
  });
151
- } else if (item.type === _constants.Type.COMMENT) {
136
+ } else if (item.type === Type.COMMENT) {
152
137
  comments.push({
153
138
  comment: item.comment,
154
139
  before: items.length
@@ -157,7 +142,7 @@ function resolveFlowSeqItems(doc, cst) {
157
142
  if (next) {
158
143
  var _msg2 = "Expected a ".concat(next, " in flow sequence");
159
144
 
160
- doc.errors.push(new _errors.YAMLSemanticError(item, _msg2));
145
+ doc.errors.push(new YAMLSemanticError(item, _msg2));
161
146
  }
162
147
 
163
148
  var value = doc.resolveNode(item);
@@ -165,7 +150,7 @@ function resolveFlowSeqItems(doc, cst) {
165
150
  if (key === undefined) {
166
151
  items.push(value);
167
152
  } else {
168
- items.push(new _Pair.default(key, value));
153
+ items.push(new Pair(key, value));
169
154
  key = undefined;
170
155
  }
171
156
 
@@ -174,8 +159,8 @@ function resolveFlowSeqItems(doc, cst) {
174
159
  }
175
160
  }
176
161
 
177
- (0, _parseUtils.checkFlowCollectionEnd)(doc.errors, cst);
178
- if (key !== undefined) items.push(new _Pair.default(key));
162
+ checkFlowCollectionEnd(doc.errors, cst);
163
+ if (key !== undefined) items.push(new Pair(key));
179
164
  return {
180
165
  comments: comments,
181
166
  items: items
@@ -1,32 +1,21 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.checkFlowCollectionEnd = checkFlowCollectionEnd;
7
- exports.checkKeyLength = checkKeyLength;
8
- exports.resolveComments = resolveComments;
9
-
10
- var _errors = require("../errors");
11
-
12
- var _constants = require("../constants");
13
-
14
- function checkFlowCollectionEnd(errors, cst) {
1
+ import { YAMLSemanticError } from '../errors';
2
+ import { Type } from '../constants';
3
+ export function checkFlowCollectionEnd(errors, cst) {
15
4
  var char, name;
16
5
 
17
6
  switch (cst.type) {
18
- case _constants.Type.FLOW_MAP:
7
+ case Type.FLOW_MAP:
19
8
  char = '}';
20
9
  name = 'flow map';
21
10
  break;
22
11
 
23
- case _constants.Type.FLOW_SEQ:
12
+ case Type.FLOW_SEQ:
24
13
  char = ']';
25
14
  name = 'flow sequence';
26
15
  break;
27
16
 
28
17
  default:
29
- errors.push(new _errors.YAMLSemanticError(cst, 'Not a flow collection!?'));
18
+ errors.push(new YAMLSemanticError(cst, 'Not a flow collection!?'));
30
19
  return;
31
20
  }
32
21
 
@@ -35,7 +24,7 @@ function checkFlowCollectionEnd(errors, cst) {
35
24
  for (var i = cst.items.length - 1; i >= 0; --i) {
36
25
  var item = cst.items[i];
37
26
 
38
- if (!item || item.type !== _constants.Type.COMMENT) {
27
+ if (!item || item.type !== Type.COMMENT) {
39
28
  lastItem = item;
40
29
  break;
41
30
  }
@@ -46,18 +35,17 @@ function checkFlowCollectionEnd(errors, cst) {
46
35
  var err;
47
36
 
48
37
  if (typeof lastItem.offset === 'number') {
49
- err = new _errors.YAMLSemanticError(cst, msg);
38
+ err = new YAMLSemanticError(cst, msg);
50
39
  err.offset = lastItem.offset + 1;
51
40
  } else {
52
- err = new _errors.YAMLSemanticError(lastItem, msg);
41
+ err = new YAMLSemanticError(lastItem, msg);
53
42
  if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start;
54
43
  }
55
44
 
56
45
  errors.push(err);
57
46
  }
58
47
  }
59
-
60
- function checkKeyLength(errors, node, itemIdx, key, keyStart) {
48
+ export function checkKeyLength(errors, node, itemIdx, key, keyStart) {
61
49
  if (!key || typeof keyStart !== 'number') return;
62
50
  var item = node.items[itemIdx];
63
51
  var keyEnd = item && item.range && item.range.start;
@@ -75,11 +63,10 @@ function checkKeyLength(errors, node, itemIdx, key, keyStart) {
75
63
 
76
64
  if (keyEnd > keyStart + 1024) {
77
65
  var k = String(key).substr(0, 8) + '...' + String(key).substr(-8);
78
- errors.push(new _errors.YAMLSemanticError(node, "The \"".concat(k, "\" key is too long")));
66
+ errors.push(new YAMLSemanticError(node, "The \"".concat(k, "\" key is too long")));
79
67
  }
80
68
  }
81
-
82
- function resolveComments(collection, comments) {
69
+ export function resolveComments(collection, comments) {
83
70
  var _iteratorNormalCompletion = true;
84
71
  var _didIteratorError = false;
85
72
  var _iteratorError = undefined;
@@ -1,26 +1,20 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.stringifyNumber = stringifyNumber;
9
- exports.stringifyString = stringifyString;
10
-
11
- var _addComment = require("./addComment");
12
-
13
- var _constants = require("./constants");
14
-
15
- var _foldFlowLines = _interopRequireWildcard(require("./foldFlowLines"));
16
-
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;
1
+ import { addCommentBefore } from './addComment';
2
+ import { Type } from './constants';
3
+ import foldFlowLines, { FOLD_BLOCK, FOLD_FLOW, FOLD_QUOTED } from './foldFlowLines';
4
+ import { strOptions } from './tags/options';
5
+
6
+ var getFoldOptions = function getFoldOptions(_ref) {
7
+ var indentAtStart = _ref.indentAtStart;
8
+ return indentAtStart ? Object.assign({
9
+ indentAtStart: indentAtStart
10
+ }, strOptions.fold) : strOptions.fold;
11
+ };
12
+
13
+ export function stringifyNumber(_ref2) {
14
+ var format = _ref2.format,
15
+ minFractionDigits = _ref2.minFractionDigits,
16
+ tag = _ref2.tag,
17
+ value = _ref2.value;
24
18
  if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
25
19
  var n = JSON.stringify(value);
26
20
 
@@ -57,10 +51,10 @@ function lineLengthOverLimit(str, limit) {
57
51
  return true;
58
52
  }
59
53
 
60
- function doubleQuotedString(value, _ref2) {
61
- var implicitKey = _ref2.implicitKey,
62
- indent = _ref2.indent;
63
- var _strOptions$doubleQuo = _options.strOptions.doubleQuoted,
54
+ function doubleQuotedString(value, ctx) {
55
+ var implicitKey = ctx.implicitKey,
56
+ indent = ctx.indent;
57
+ var _strOptions$doubleQuo = strOptions.doubleQuoted,
64
58
  jsonEncoding = _strOptions$doubleQuo.jsonEncoding,
65
59
  minMultiLineLength = _strOptions$doubleQuo.minMultiLineLength;
66
60
  var json = JSON.stringify(value);
@@ -152,7 +146,7 @@ function doubleQuotedString(value, _ref2) {
152
146
  }
153
147
 
154
148
  str = start ? str + json.slice(start) : json;
155
- return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, _options.strOptions.fold);
149
+ return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
156
150
  }
157
151
 
158
152
  function singleQuotedString(value, ctx) {
@@ -167,7 +161,7 @@ function singleQuotedString(value, ctx) {
167
161
  }
168
162
 
169
163
  var res = "'" + value.replace(/'/g, "''").replace(/\n+/g, "$&\n".concat(indent)) + "'";
170
- return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold);
164
+ return implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
171
165
  }
172
166
 
173
167
  function blockString(_ref3, ctx, onComment, onChompKeep) {
@@ -184,7 +178,7 @@ function blockString(_ref3, ctx, onComment, onChompKeep) {
184
178
  var indent = ctx.indent || (ctx.forceBlockIndent ? ' ' : '');
185
179
  var indentSize = indent ? '2' : '1'; // root is at -1
186
180
 
187
- var literal = type === _constants.Type.BLOCK_FOLDED ? false : type === _constants.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, _options.strOptions.fold.lineWidth - indent.length);
181
+ var literal = type === Type.BLOCK_FOLDED ? false : type === Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth - indent.length);
188
182
  var header = literal ? '|' : '>';
189
183
  if (!value) return header + '\n';
190
184
  var wsStart = '';
@@ -232,7 +226,7 @@ function blockString(_ref3, ctx, onComment, onChompKeep) {
232
226
  value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
233
227
  // ^ ind.line ^ empty ^ capture next empty lines only at end of indent
234
228
  .replace(/\n+/g, "$&".concat(indent));
235
- var body = (0, _foldFlowLines.default)("".concat(wsStart).concat(value).concat(wsEnd), indent, _foldFlowLines.FOLD_BLOCK, _options.strOptions.fold);
229
+ var body = foldFlowLines("".concat(wsStart).concat(value).concat(wsEnd), indent, FOLD_BLOCK, strOptions.fold);
236
230
  return "".concat(header, "\n").concat(indent).concat(body);
237
231
  }
238
232
 
@@ -260,7 +254,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
260
254
  return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
261
255
  }
262
256
 
263
- if (!implicitKey && !inFlow && type !== _constants.Type.PLAIN && value.indexOf('\n') !== -1) {
257
+ if (!implicitKey && !inFlow && type !== Type.PLAIN && value.indexOf('\n') !== -1) {
264
258
  // Where allowed & type not set explicitly, prefer block style for multiline strings
265
259
  return blockString(item, ctx, onComment, onChompKeep);
266
260
  }
@@ -273,18 +267,18 @@ function plainString(item, ctx, onComment, onChompKeep) {
273
267
  return doubleQuotedString(value, ctx);
274
268
  }
275
269
 
276
- var body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold);
270
+ var body = implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx));
277
271
 
278
272
  if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
279
273
  if (onComment) onComment();
280
- return (0, _addComment.addCommentBefore)(body, indent, comment);
274
+ return addCommentBefore(body, indent, comment);
281
275
  }
282
276
 
283
277
  return body;
284
278
  }
285
279
 
286
- function stringifyString(item, ctx, onComment, onChompKeep) {
287
- var defaultType = _options.strOptions.defaultType;
280
+ export function stringifyString(item, ctx, onComment, onChompKeep) {
281
+ var defaultType = strOptions.defaultType;
288
282
  var implicitKey = ctx.implicitKey,
289
283
  inFlow = ctx.inFlow;
290
284
  var _item = item,
@@ -300,17 +294,17 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
300
294
 
301
295
  var _stringify = function _stringify(_type) {
302
296
  switch (_type) {
303
- case _constants.Type.BLOCK_FOLDED:
304
- case _constants.Type.BLOCK_LITERAL:
297
+ case Type.BLOCK_FOLDED:
298
+ case Type.BLOCK_LITERAL:
305
299
  return blockString(item, ctx, onComment, onChompKeep);
306
300
 
307
- case _constants.Type.QUOTE_DOUBLE:
301
+ case Type.QUOTE_DOUBLE:
308
302
  return doubleQuotedString(value, ctx);
309
303
 
310
- case _constants.Type.QUOTE_SINGLE:
304
+ case Type.QUOTE_SINGLE:
311
305
  return singleQuotedString(value, ctx);
312
306
 
313
- case _constants.Type.PLAIN:
307
+ case Type.PLAIN:
314
308
  return plainString(item, ctx, onComment, onChompKeep);
315
309
 
316
310
  default:
@@ -318,12 +312,12 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
318
312
  }
319
313
  };
320
314
 
321
- if (type !== _constants.Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
315
+ if (type !== Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
322
316
  // force double quotes on control characters
323
- type = _constants.Type.QUOTE_DOUBLE;
324
- } else if ((implicitKey || inFlow) && (type === _constants.Type.BLOCK_FOLDED || type === _constants.Type.BLOCK_LITERAL)) {
317
+ type = Type.QUOTE_DOUBLE;
318
+ } else if ((implicitKey || inFlow) && (type === Type.BLOCK_FOLDED || type === Type.BLOCK_LITERAL)) {
325
319
  // should not happen; blocks are not valid inside flow containers
326
- type = _constants.Type.QUOTE_DOUBLE;
320
+ type = Type.QUOTE_DOUBLE;
327
321
  }
328
322
 
329
323
  var res = _stringify(type);
@@ -1,26 +1,13 @@
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([{
1
+ import Scalar from '../schema/Scalar';
2
+ import { stringifyNumber } from '../stringify';
3
+ import failsafe from './failsafe';
4
+ import { boolOptions, nullOptions } from './options';
5
+ export var nullObj = {
19
6
  identify: function identify(value) {
20
7
  return value == null;
21
8
  },
22
9
  createNode: function createNode(schema, value, ctx) {
23
- return ctx.wrapScalars ? new _Scalar.default(null) : null;
10
+ return ctx.wrapScalars ? new Scalar(null) : null;
24
11
  },
25
12
  default: true,
26
13
  tag: 'tag:yaml.org,2002:null',
@@ -28,11 +15,12 @@ var _default = _failsafe.default.concat([{
28
15
  resolve: function resolve() {
29
16
  return null;
30
17
  },
31
- options: _options.nullOptions,
18
+ options: nullOptions,
32
19
  stringify: function stringify() {
33
- return _options.nullOptions.nullStr;
20
+ return nullOptions.nullStr;
34
21
  }
35
- }, {
22
+ };
23
+ export var boolObj = {
36
24
  identify: function identify(value) {
37
25
  return typeof value === 'boolean';
38
26
  },
@@ -42,12 +30,13 @@ var _default = _failsafe.default.concat([{
42
30
  resolve: function resolve(str) {
43
31
  return str[0] === 't' || str[0] === 'T';
44
32
  },
45
- options: _options.boolOptions,
33
+ options: boolOptions,
46
34
  stringify: function stringify(_ref) {
47
35
  var value = _ref.value;
48
- return value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr;
36
+ return value ? boolOptions.trueStr : boolOptions.falseStr;
49
37
  }
50
- }, {
38
+ };
39
+ export var octObj = {
51
40
  identify: function identify(value) {
52
41
  return typeof value === 'number';
53
42
  },
@@ -62,7 +51,8 @@ var _default = _failsafe.default.concat([{
62
51
  var value = _ref2.value;
63
52
  return '0o' + value.toString(8);
64
53
  }
65
- }, {
54
+ };
55
+ export var intObj = {
66
56
  identify: function identify(value) {
67
57
  return typeof value === 'number';
68
58
  },
@@ -72,8 +62,9 @@ var _default = _failsafe.default.concat([{
72
62
  resolve: function resolve(str) {
73
63
  return parseInt(str, 10);
74
64
  },
75
- stringify: _stringify.stringifyNumber
76
- }, {
65
+ stringify: stringifyNumber
66
+ };
67
+ export var hexObj = {
77
68
  identify: function identify(value) {
78
69
  return typeof value === 'number';
79
70
  },
@@ -88,7 +79,8 @@ var _default = _failsafe.default.concat([{
88
79
  var value = _ref3.value;
89
80
  return '0x' + value.toString(16);
90
81
  }
91
- }, {
82
+ };
83
+ export var nanObj = {
92
84
  identify: function identify(value) {
93
85
  return typeof value === 'number';
94
86
  },
@@ -98,15 +90,16 @@ var _default = _failsafe.default.concat([{
98
90
  resolve: function resolve(str, nan) {
99
91
  return nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY;
100
92
  },
101
- stringify: _stringify.stringifyNumber
102
- }, {
93
+ stringify: stringifyNumber
94
+ };
95
+ export var expObj = {
103
96
  identify: function identify(value) {
104
97
  return typeof value === 'number';
105
98
  },
106
99
  default: true,
107
100
  tag: 'tag:yaml.org,2002:float',
108
101
  format: 'EXP',
109
- test: /^[-+]?(?:0|[1-9][0-9]*)(\.[0-9]*)?[eE][-+]?[0-9]+$/,
102
+ test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
110
103
  resolve: function resolve(str) {
111
104
  return parseFloat(str);
112
105
  },
@@ -114,19 +107,20 @@ var _default = _failsafe.default.concat([{
114
107
  var value = _ref4.value;
115
108
  return Number(value).toExponential();
116
109
  }
117
- }, {
110
+ };
111
+ export var floatObj = {
118
112
  identify: function identify(value) {
119
113
  return typeof value === 'number';
120
114
  },
121
115
  default: true,
122
116
  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));
117
+ test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/,
118
+ resolve: function resolve(str, frac1, frac2) {
119
+ var frac = frac1 || frac2;
120
+ var node = new Scalar(parseFloat(str));
126
121
  if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
127
122
  return node;
128
123
  },
129
- stringify: _stringify.stringifyNumber
130
- }]);
131
-
132
- exports.default = _default;
124
+ stringify: stringifyNumber
125
+ };
126
+ export default failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
@@ -1,17 +1,4 @@
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;
1
+ import map from './map';
2
+ import seq from './seq';
3
+ import str from './string';
4
+ export default [map, seq, str];
@@ -1,22 +1,10 @@
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"));
1
+ import _typeof from "@babel/runtime/helpers/typeof";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import YAMLMap from '../../schema/Map';
4
+ import parseMap from '../../schema/parseMap';
17
5
 
18
6
  function createMap(schema, obj, ctx) {
19
- var map = new _Map.default();
7
+ var map = new YAMLMap(schema);
20
8
 
21
9
  if (obj instanceof Map) {
22
10
  var _iteratorNormalCompletion = true;
@@ -25,7 +13,7 @@ function createMap(schema, obj, ctx) {
25
13
 
26
14
  try {
27
15
  for (var _iterator = obj[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
28
- var _step$value = (0, _slicedToArray2.default)(_step.value, 2),
16
+ var _step$value = _slicedToArray(_step.value, 2),
29
17
  key = _step$value[0],
30
18
  value = _step$value[1];
31
19
 
@@ -45,21 +33,24 @@ function createMap(schema, obj, ctx) {
45
33
  }
46
34
  }
47
35
  }
48
- } else if (obj && (0, _typeof2.default)(obj) === 'object') {
36
+ } else if (obj && _typeof(obj) === 'object') {
49
37
  for (var _i = 0, _Object$keys = Object.keys(obj); _i < _Object$keys.length; _i++) {
50
38
  var _key = _Object$keys[_i];
51
39
  map.items.push(schema.createPair(_key, obj[_key], ctx));
52
40
  }
53
41
  }
54
42
 
43
+ if (typeof schema.sortMapEntries === 'function') {
44
+ map.items.sort(schema.sortMapEntries);
45
+ }
46
+
55
47
  return map;
56
48
  }
57
49
 
58
- var _default = {
50
+ export default {
59
51
  createNode: createMap,
60
52
  default: true,
61
- nodeClass: _Map.default,
53
+ nodeClass: YAMLMap,
62
54
  tag: 'tag:yaml.org,2002:map',
63
- resolve: _parseMap.default
64
- };
65
- exports.default = _default;
55
+ resolve: parseMap
56
+ };