yaml 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +3 -5
  2. package/browser/dist/Anchors.js +1 -3
  3. package/browser/dist/Document.js +94 -37
  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 +7 -7
  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 +5 -4
  25. package/browser/dist/listTagNames.js +1 -3
  26. package/browser/dist/schema/Alias.js +85 -10
  27. package/browser/dist/schema/Map.js +14 -121
  28. package/browser/dist/schema/Merge.js +74 -1
  29. package/browser/dist/schema/Node.js +1 -3
  30. package/browser/dist/schema/Pair.js +36 -22
  31. package/browser/dist/schema/Scalar.js +1 -3
  32. package/browser/dist/schema/Seq.js +1 -3
  33. package/browser/dist/schema/index.js +61 -45
  34. package/browser/dist/schema/parseMap.js +18 -21
  35. package/browser/dist/schema/parseSeq.js +9 -12
  36. package/browser/dist/stringify.js +54 -39
  37. package/browser/dist/{schema → tags}/core.js +32 -20
  38. package/browser/dist/tags/failsafe/index.js +17 -0
  39. package/browser/dist/tags/failsafe/map.js +65 -0
  40. package/browser/dist/tags/failsafe/seq.js +54 -0
  41. package/browser/dist/{schema/_string.js → tags/failsafe/string.js} +11 -11
  42. package/browser/dist/tags/index.js +50 -0
  43. package/browser/dist/{schema → tags}/json.js +8 -8
  44. package/browser/dist/tags/options.js +35 -0
  45. package/browser/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +16 -22
  46. package/browser/dist/{schema/yaml-1.1.js → tags/yaml-1.1/index.js} +43 -29
  47. package/browser/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +8 -11
  48. package/browser/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +8 -12
  49. package/browser/dist/tags/yaml-1.1/set.js +140 -0
  50. package/browser/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +4 -7
  51. package/browser/dist/test-events.js +1 -4
  52. package/browser/dist/toJSON.js +1 -4
  53. package/browser/index.js +1 -0
  54. package/browser/map.js +2 -1
  55. package/browser/pair.js +2 -1
  56. package/browser/parse-cst.js +1 -1
  57. package/browser/scalar.js +2 -1
  58. package/browser/schema.js +7 -4
  59. package/browser/seq.js +2 -1
  60. package/browser/types/binary.js +7 -1
  61. package/browser/types/omap.js +2 -1
  62. package/browser/types/pairs.js +2 -1
  63. package/browser/types/set.js +2 -1
  64. package/browser/types/timestamp.js +10 -1
  65. package/browser/types.js +11 -0
  66. package/browser/util.js +15 -0
  67. package/dist/Anchors.js +1 -3
  68. package/dist/Document.js +38 -25
  69. package/dist/constants.js +34 -0
  70. package/dist/cst/Alias.js +1 -3
  71. package/dist/cst/BlankLine.js +5 -7
  72. package/dist/cst/BlockValue.js +4 -4
  73. package/dist/cst/Collection.js +7 -7
  74. package/dist/cst/CollectionItem.js +6 -8
  75. package/dist/cst/Comment.js +5 -7
  76. package/dist/cst/Directive.js +5 -7
  77. package/dist/cst/Document.js +8 -10
  78. package/dist/cst/FlowCollection.js +5 -7
  79. package/dist/cst/Node.js +12 -40
  80. package/dist/cst/ParseContext.js +32 -34
  81. package/dist/cst/PlainValue.js +1 -3
  82. package/dist/cst/QuoteDouble.js +1 -3
  83. package/dist/cst/QuoteSingle.js +1 -3
  84. package/dist/cst/Range.js +1 -3
  85. package/dist/cst/getLinePos.js +1 -4
  86. package/dist/cst/parse.js +1 -4
  87. package/dist/deprecation.js +34 -0
  88. package/dist/errors.js +29 -35
  89. package/dist/index.js +5 -4
  90. package/dist/listTagNames.js +1 -3
  91. package/dist/schema/Alias.js +66 -12
  92. package/dist/schema/Map.js +9 -77
  93. package/dist/schema/Merge.js +31 -0
  94. package/dist/schema/Node.js +1 -3
  95. package/dist/schema/Pair.js +29 -15
  96. package/dist/schema/Scalar.js +1 -3
  97. package/dist/schema/Seq.js +1 -3
  98. package/dist/schema/index.js +55 -45
  99. package/dist/schema/parseMap.js +18 -21
  100. package/dist/schema/parseSeq.js +9 -12
  101. package/dist/stringify.js +46 -32
  102. package/dist/{schema → tags}/core.js +32 -19
  103. package/dist/tags/failsafe/index.js +17 -0
  104. package/dist/tags/failsafe/map.js +33 -0
  105. package/dist/tags/failsafe/seq.js +34 -0
  106. package/dist/tags/failsafe/string.js +40 -0
  107. package/dist/tags/index.js +50 -0
  108. package/dist/{schema → tags}/json.js +8 -8
  109. package/dist/tags/options.js +35 -0
  110. package/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +15 -21
  111. package/dist/{schema/yaml-1.1.js → tags/yaml-1.1/index.js} +43 -30
  112. package/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +8 -9
  113. package/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +8 -10
  114. package/dist/{schema/_set.js → tags/yaml-1.1/set.js} +9 -42
  115. package/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +4 -7
  116. package/dist/test-events.js +1 -4
  117. package/dist/toJSON.js +1 -4
  118. package/index.js +1 -0
  119. package/map.js +2 -1
  120. package/package.json +17 -15
  121. package/pair.js +2 -1
  122. package/parse-cst.js +1 -1
  123. package/scalar.js +2 -1
  124. package/schema.js +7 -4
  125. package/seq.js +2 -1
  126. package/types/binary.js +7 -1
  127. package/types/omap.js +2 -1
  128. package/types/pairs.js +2 -1
  129. package/types/set.js +2 -1
  130. package/types/timestamp.js +10 -1
  131. package/types.js +11 -0
  132. package/util.js +15 -0
  133. package/browser/dist/schema/_set.js +0 -215
  134. package/browser/dist/schema/failsafe.js +0 -125
  135. package/dist/schema/_string.js +0 -40
  136. package/dist/schema/failsafe.js +0 -74
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
-
5
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
4
 
7
5
  Object.defineProperty(exports, "__esModule", {
@@ -17,68 +15,70 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
17
15
 
18
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
17
 
20
- var _Node = require("../cst/Node");
18
+ var _deprecation = require("../deprecation");
19
+
20
+ var _constants = require("../constants");
21
21
 
22
22
  var _errors = require("../errors");
23
23
 
24
- var _stringify2 = _interopRequireDefault(require("../stringify"));
24
+ var _stringify = require("../stringify");
25
25
 
26
- var _Alias = _interopRequireDefault(require("./Alias"));
26
+ var _tags = require("../tags");
27
27
 
28
- var _Collection = _interopRequireDefault(require("./Collection"));
28
+ var _string = require("../tags/failsafe/string");
29
29
 
30
- var _core = _interopRequireDefault(require("./core"));
31
-
32
- var _failsafe = _interopRequireWildcard(require("./failsafe"));
30
+ var _Alias = _interopRequireDefault(require("./Alias"));
33
31
 
34
- var _json = _interopRequireDefault(require("./json"));
32
+ var _Collection = _interopRequireDefault(require("./Collection"));
35
33
 
36
- var _Node2 = _interopRequireDefault(require("./Node"));
34
+ var _Node = _interopRequireDefault(require("./Node"));
37
35
 
38
36
  var _Pair = _interopRequireDefault(require("./Pair"));
39
37
 
40
38
  var _Scalar = _interopRequireDefault(require("./Scalar"));
41
39
 
42
- var _string = require("./_string");
43
-
44
- var _yaml = _interopRequireDefault(require("./yaml-1.1"));
45
-
46
40
  var isMap = function isMap(_ref) {
47
41
  var type = _ref.type;
48
- return type === _Node.Type.FLOW_MAP || type === _Node.Type.MAP;
42
+ return type === _constants.Type.FLOW_MAP || type === _constants.Type.MAP;
49
43
  };
50
44
 
51
45
  var isSeq = function isSeq(_ref2) {
52
46
  var type = _ref2.type;
53
- return type === _Node.Type.FLOW_SEQ || type === _Node.Type.SEQ;
47
+ return type === _constants.Type.FLOW_SEQ || type === _constants.Type.SEQ;
54
48
  };
55
49
 
56
50
  var Schema =
57
51
  /*#__PURE__*/
58
52
  function () {
59
53
  function Schema(_ref3) {
60
- var merge = _ref3.merge,
54
+ var customTags = _ref3.customTags,
55
+ merge = _ref3.merge,
61
56
  schema = _ref3.schema,
62
- tags = _ref3.tags;
57
+ deprecatedCustomTags = _ref3.tags;
63
58
  (0, _classCallCheck2.default)(this, Schema);
64
59
  this.merge = !!merge;
65
60
  this.name = schema;
66
- this.tags = Schema.tags[schema];
61
+ this.tags = _tags.schemas[schema.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
67
62
 
68
63
  if (!this.tags) {
69
- var keys = Object.keys(Schema.tags).map(function (key) {
64
+ var keys = Object.keys(_tags.schemas).map(function (key) {
70
65
  return JSON.stringify(key);
71
- });
72
- throw new Error("Unknown schema; use one of ".concat(keys.join(', ')));
66
+ }).join(', ');
67
+ throw new Error("Unknown schema \"".concat(schema, "\"; use one of ").concat(keys));
73
68
  }
74
69
 
75
- if (Array.isArray(tags)) {
70
+ if (!customTags && deprecatedCustomTags) {
71
+ customTags = deprecatedCustomTags;
72
+ (0, _deprecation.warnOptionDeprecation)('tags', 'customTags');
73
+ }
74
+
75
+ if (Array.isArray(customTags)) {
76
76
  var _iteratorNormalCompletion = true;
77
77
  var _didIteratorError = false;
78
78
  var _iteratorError = undefined;
79
79
 
80
80
  try {
81
- for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
81
+ for (var _iterator = customTags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
82
82
  var tag = _step.value;
83
83
  this.tags = this.tags.concat(tag);
84
84
  }
@@ -96,8 +96,26 @@ function () {
96
96
  }
97
97
  }
98
98
  }
99
- } else if (typeof tags === 'function') {
100
- this.tags = tags(this.tags.slice());
99
+ } else if (typeof customTags === 'function') {
100
+ this.tags = customTags(this.tags.slice());
101
+ }
102
+
103
+ for (var i = 0; i < this.tags.length; ++i) {
104
+ var _tag = this.tags[i];
105
+
106
+ if (typeof _tag === 'string') {
107
+ var tagObj = _tags.tags[_tag];
108
+
109
+ if (!tagObj) {
110
+ var _keys = Object.keys(_tags.tags).map(function (key) {
111
+ return JSON.stringify(key);
112
+ }).join(', ');
113
+
114
+ throw new Error("Unknown custom tag \"".concat(_tag, "\"; use one of ").concat(_keys));
115
+ }
116
+
117
+ this.tags[i] = tagObj;
118
+ }
101
119
  }
102
120
  }
103
121
 
@@ -124,7 +142,7 @@ function () {
124
142
  if (!tagObj) {
125
143
  if (typeof value.toJSON === 'function') value = value.toJSON();
126
144
  if ((0, _typeof2.default)(value) !== 'object') return wrapScalars ? new _Scalar.default(value) : value;
127
- tagObj = value instanceof Map ? _failsafe.map : value[Symbol.iterator] ? _failsafe.seq : _failsafe.map;
145
+ tagObj = value instanceof Map ? _tags.tags.map : value[Symbol.iterator] ? _tags.tags.seq : _tags.tags.map;
128
146
  }
129
147
  }
130
148
 
@@ -157,6 +175,13 @@ function () {
157
175
 
158
176
  obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new _Scalar.default(value) : value;
159
177
  return obj.node;
178
+ }
179
+ }, {
180
+ key: "createPair",
181
+ value: function createPair(key, value, ctx) {
182
+ var k = this.createNode(key, ctx.wrapScalars, null, ctx);
183
+ var v = this.createNode(value, ctx.wrapScalars, null, ctx);
184
+ return new _Pair.default(k, v);
160
185
  } // falls back to string on no match
161
186
 
162
187
  }, {
@@ -174,7 +199,8 @@ function () {
174
199
  var match = str.match(test);
175
200
 
176
201
  if (match) {
177
- var res = new _Scalar.default(resolve.apply(null, match));
202
+ var res = resolve.apply(null, match);
203
+ if (!(res instanceof _Scalar.default)) res = new _Scalar.default(res);
178
204
  if (format) res.format = format;
179
205
  return res;
180
206
  }
@@ -204,7 +230,7 @@ function () {
204
230
  if (!(res instanceof _Collection.default)) res = new _Scalar.default(res);
205
231
  node.resolved = res;
206
232
  } else {
207
- var str = (0, _string.resolve)(doc, node);
233
+ var str = (0, _string.resolveString)(doc, node);
208
234
 
209
235
  if (typeof str === 'string' && tags.length > 0) {
210
236
  node.resolved = this.resolveScalar(str, tags);
@@ -217,7 +243,7 @@ function () {
217
243
  }
218
244
 
219
245
  if (!node.resolved) return null;
220
- if (tagName) node.resolved.tag = tagName;
246
+ if (tagName && node.tag) node.resolved.tag = tagName;
221
247
  return node.resolved;
222
248
  }
223
249
  }, {
@@ -296,7 +322,7 @@ function () {
296
322
  props.push("&".concat(anchor));
297
323
  }
298
324
 
299
- if (node.tag && node.tag !== tagObj.tag) {
325
+ if (node.tag) {
300
326
  props.push(doc.stringifyTag(node.tag));
301
327
  } else if (!tagObj.default) {
302
328
  props.push(doc.stringifyTag(tagObj.tag));
@@ -309,7 +335,7 @@ function () {
309
335
  value: function stringify(item, ctx, onComment, onChompKeep) {
310
336
  var tagObj;
311
337
 
312
- if (!(item instanceof _Node2.default)) {
338
+ if (!(item instanceof _Node.default)) {
313
339
  var createCtx = {
314
340
  aliasNodes: [],
315
341
  onTagObj: function onTagObj(o) {
@@ -354,9 +380,7 @@ function () {
354
380
  if (item instanceof _Pair.default) return item.toString(ctx, onComment, onChompKeep);
355
381
  if (!tagObj) tagObj = this.getTagObject(item);
356
382
  var props = this.stringifyProps(item, tagObj, ctx);
357
-
358
- var str = (tagObj.stringify || _stringify2.default)(item, ctx, onComment, onChompKeep);
359
-
383
+ var str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof _Collection.default ? item.toString(ctx, onComment, onChompKeep) : (0, _stringify.stringifyString)(item, ctx, onComment, onChompKeep);
360
384
  return props ? item instanceof _Collection.default && str[0] !== '{' && str[0] !== '[' ? "".concat(props, "\n").concat(ctx.indent).concat(str) : "".concat(props, " ").concat(str) : str;
361
385
  }
362
386
  }]);
@@ -369,12 +393,4 @@ exports.default = Schema;
369
393
  MAP: 'tag:yaml.org,2002:map',
370
394
  SEQ: 'tag:yaml.org,2002:seq',
371
395
  STR: 'tag:yaml.org,2002:str'
372
- });
373
- (0, _defineProperty2.default)(Schema, "tags", {
374
- core: _core.default,
375
- failsafe: _failsafe.default,
376
- json: _json.default,
377
- 'yaml-1.1': _yaml.default
378
- });
379
- module.exports = exports.default;
380
- module.exports.default = exports.default;
396
+ });
@@ -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,27 +5,42 @@ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWild
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = stringify;
9
- exports.strOptions = void 0;
8
+ exports.stringifyNumber = stringifyNumber;
9
+ exports.stringifyString = stringifyString;
10
10
 
11
11
  var _addComment = require("./addComment");
12
12
 
13
- var _Node = require("./cst/Node");
13
+ var _constants = require("./constants");
14
14
 
15
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;
41
+
42
+ return n;
43
+ }
29
44
 
30
45
  function lineLengthOverLimit(str, limit) {
31
46
  var strLen = str.length;
@@ -42,10 +57,10 @@ function lineLengthOverLimit(str, limit) {
42
57
  return true;
43
58
  }
44
59
 
45
- function doubleQuotedString(value, _ref) {
46
- var implicitKey = _ref.implicitKey,
47
- indent = _ref.indent;
48
- 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,
49
64
  jsonEncoding = _strOptions$doubleQuo.jsonEncoding,
50
65
  minMultiLineLength = _strOptions$doubleQuo.minMultiLineLength;
51
66
  var json = JSON.stringify(value);
@@ -137,7 +152,7 @@ function doubleQuotedString(value, _ref) {
137
152
  }
138
153
 
139
154
  str = start ? str + json.slice(start) : json;
140
- 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);
141
156
  }
142
157
 
143
158
  function singleQuotedString(value, ctx) {
@@ -152,13 +167,13 @@ function singleQuotedString(value, ctx) {
152
167
  }
153
168
 
154
169
  var res = "'" + value.replace(/'/g, "''").replace(/\n+/g, "$&\n".concat(indent)) + "'";
155
- 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);
156
171
  }
157
172
 
158
- function blockString(_ref2, ctx, onComment, onChompKeep) {
159
- var comment = _ref2.comment,
160
- type = _ref2.type,
161
- value = _ref2.value;
173
+ function blockString(_ref3, ctx, onComment, onChompKeep) {
174
+ var comment = _ref3.comment,
175
+ type = _ref3.type,
176
+ value = _ref3.value;
162
177
 
163
178
  // 1. Block can't end in whitespace unless the last line is non-empty.
164
179
  // 2. Strings consisting of only whitespace are best rendered explicitly.
@@ -169,7 +184,7 @@ function blockString(_ref2, ctx, onComment, onChompKeep) {
169
184
  var indent = ctx.indent || (ctx.forceBlockIndent ? ' ' : '');
170
185
  var indentSize = indent ? '2' : '1'; // root is at -1
171
186
 
172
- 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);
173
188
  var header = literal ? '|' : '>';
174
189
  if (!value) return header + '\n';
175
190
  var wsStart = '';
@@ -217,7 +232,7 @@ function blockString(_ref2, ctx, onComment, onChompKeep) {
217
232
  value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
218
233
  // ^ ind.line ^ empty ^ capture next empty lines only at end of indent
219
234
  .replace(/\n+/g, "$&".concat(indent));
220
- 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);
221
236
  return "".concat(header, "\n").concat(indent).concat(body);
222
237
  }
223
238
 
@@ -245,7 +260,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
245
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);
246
261
  }
247
262
 
248
- if (!implicitKey && !inFlow && type !== _Node.Type.PLAIN && value.indexOf('\n') !== -1) {
263
+ if (!implicitKey && !inFlow && type !== _constants.Type.PLAIN && value.indexOf('\n') !== -1) {
249
264
  // Where allowed & type not set explicitly, prefer block style for multiline strings
250
265
  return blockString(item, ctx, onComment, onChompKeep);
251
266
  }
@@ -257,7 +272,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
257
272
  return doubleQuotedString(value, ctx);
258
273
  }
259
274
 
260
- 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);
261
276
 
262
277
  if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
263
278
  if (onComment) onComment();
@@ -267,8 +282,8 @@ function plainString(item, ctx, onComment, onChompKeep) {
267
282
  return body;
268
283
  }
269
284
 
270
- function stringify(item, ctx, onComment, onChompKeep) {
271
- var defaultType = strOptions.defaultType;
285
+ function stringifyString(item, ctx, onComment, onChompKeep) {
286
+ var defaultType = _options.strOptions.defaultType;
272
287
  var implicitKey = ctx.implicitKey,
273
288
  inFlow = ctx.inFlow;
274
289
  var _item = item,
@@ -284,17 +299,17 @@ function stringify(item, ctx, onComment, onChompKeep) {
284
299
 
285
300
  var _stringify = function _stringify(_type) {
286
301
  switch (_type) {
287
- case _Node.Type.BLOCK_FOLDED:
288
- case _Node.Type.BLOCK_LITERAL:
302
+ case _constants.Type.BLOCK_FOLDED:
303
+ case _constants.Type.BLOCK_LITERAL:
289
304
  return blockString(item, ctx, onComment, onChompKeep);
290
305
 
291
- case _Node.Type.QUOTE_DOUBLE:
306
+ case _constants.Type.QUOTE_DOUBLE:
292
307
  return doubleQuotedString(value, ctx);
293
308
 
294
- case _Node.Type.QUOTE_SINGLE:
309
+ case _constants.Type.QUOTE_SINGLE:
295
310
  return singleQuotedString(value, ctx);
296
311
 
297
- case _Node.Type.PLAIN:
312
+ case _constants.Type.PLAIN:
298
313
  return plainString(item, ctx, onComment, onChompKeep);
299
314
 
300
315
  default:
@@ -302,12 +317,12 @@ function stringify(item, ctx, onComment, onChompKeep) {
302
317
  }
303
318
  };
304
319
 
305
- 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)) {
306
321
  // force double quotes on control characters
307
- type = _Node.Type.QUOTE_DOUBLE;
308
- } 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)) {
309
324
  // should not happen; blocks are not valid inside flow containers
310
- type = _Node.Type.QUOTE_DOUBLE;
325
+ type = _constants.Type.QUOTE_DOUBLE;
311
326
  }
312
327
 
313
328
  var res = _stringify(type);