yaml 1.8.2 → 1.9.2

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 (142) hide show
  1. package/browser/dist/Anchors.js +10 -13
  2. package/browser/dist/Document.js +72 -67
  3. package/browser/dist/addComment.js +1 -1
  4. package/browser/dist/cst/Alias.js +12 -8
  5. package/browser/dist/cst/BlankLine.js +16 -20
  6. package/browser/dist/cst/BlockValue.js +14 -10
  7. package/browser/dist/cst/Collection.js +17 -13
  8. package/browser/dist/cst/CollectionItem.js +15 -11
  9. package/browser/dist/cst/Comment.js +13 -9
  10. package/browser/dist/cst/Directive.js +13 -9
  11. package/browser/dist/cst/Document.js +17 -13
  12. package/browser/dist/cst/FlowCollection.js +17 -13
  13. package/browser/dist/cst/Node.js +3 -5
  14. package/browser/dist/cst/ParseContext.js +12 -14
  15. package/browser/dist/cst/PlainValue.js +12 -8
  16. package/browser/dist/cst/QuoteDouble.js +13 -9
  17. package/browser/dist/cst/QuoteSingle.js +13 -9
  18. package/browser/dist/cst/Range.js +2 -5
  19. package/browser/dist/cst/parse.js +3 -3
  20. package/browser/dist/errors.js +23 -8
  21. package/browser/dist/foldFlowLines.js +1 -1
  22. package/browser/dist/index.js +71 -21
  23. package/browser/dist/listTagNames.js +5 -5
  24. package/browser/dist/schema/Alias.js +30 -34
  25. package/browser/dist/schema/Collection.js +40 -47
  26. package/browser/dist/schema/Map.js +39 -56
  27. package/browser/dist/schema/Merge.js +37 -46
  28. package/browser/dist/schema/Node.js +2 -5
  29. package/browser/dist/schema/Pair.js +36 -13
  30. package/browser/dist/schema/Scalar.js +13 -9
  31. package/browser/dist/schema/Seq.js +27 -25
  32. package/browser/dist/schema/index.js +25 -39
  33. package/browser/dist/schema/parseMap.js +8 -8
  34. package/browser/dist/schema/parseSeq.js +5 -5
  35. package/browser/dist/schema/parseUtils.js +11 -15
  36. package/browser/dist/stringify.js +2 -1
  37. package/browser/dist/tags/core.js +39 -23
  38. package/browser/dist/tags/failsafe/index.js +4 -4
  39. package/browser/dist/tags/failsafe/map.js +15 -18
  40. package/browser/dist/tags/failsafe/seq.js +14 -18
  41. package/browser/dist/tags/failsafe/string.js +1 -1
  42. package/browser/dist/tags/index.js +10 -10
  43. package/browser/dist/tags/json.js +27 -26
  44. package/browser/dist/tags/options.js +3 -0
  45. package/browser/dist/tags/yaml-1.1/binary.js +10 -8
  46. package/browser/dist/tags/yaml-1.1/index.js +75 -43
  47. package/browser/dist/tags/yaml-1.1/omap.js +34 -39
  48. package/browser/dist/tags/yaml-1.1/pairs.js +17 -20
  49. package/browser/dist/tags/yaml-1.1/set.js +27 -23
  50. package/browser/dist/test-events.js +4 -4
  51. package/browser/dist/toJSON.js +3 -4
  52. package/browser/dist/warnings.js +29 -18
  53. package/browser/index.js +1 -1
  54. package/browser/map.js +4 -2
  55. package/browser/pair.js +4 -2
  56. package/browser/parse-cst.js +1 -1
  57. package/browser/scalar.js +4 -2
  58. package/browser/schema.js +11 -6
  59. package/browser/seq.js +4 -2
  60. package/browser/types/binary.js +5 -6
  61. package/browser/types/omap.js +4 -2
  62. package/browser/types/pairs.js +4 -2
  63. package/browser/types/set.js +4 -2
  64. package/browser/types/timestamp.js +5 -9
  65. package/browser/types.js +12 -10
  66. package/browser/util.js +16 -13
  67. package/dist/Anchors.js +13 -18
  68. package/dist/Document.js +52 -48
  69. package/dist/addComment.js +1 -4
  70. package/dist/constants.js +0 -3
  71. package/dist/cst/Alias.js +8 -13
  72. package/dist/cst/BlankLine.js +8 -24
  73. package/dist/cst/BlockValue.js +12 -17
  74. package/dist/cst/Collection.js +22 -27
  75. package/dist/cst/CollectionItem.js +16 -21
  76. package/dist/cst/Comment.js +6 -11
  77. package/dist/cst/Directive.js +7 -12
  78. package/dist/cst/Document.js +23 -28
  79. package/dist/cst/FlowCollection.js +21 -26
  80. package/dist/cst/Node.js +4 -9
  81. package/dist/cst/ParseContext.js +38 -43
  82. package/dist/cst/PlainValue.js +10 -15
  83. package/dist/cst/QuoteDouble.js +9 -14
  84. package/dist/cst/QuoteSingle.js +9 -14
  85. package/dist/cst/Range.js +2 -5
  86. package/dist/cst/parse.js +5 -10
  87. package/dist/cst/source-utils.js +0 -3
  88. package/dist/errors.js +4 -9
  89. package/dist/foldFlowLines.js +1 -4
  90. package/dist/index.js +59 -17
  91. package/dist/listTagNames.js +9 -14
  92. package/dist/schema/Alias.js +12 -17
  93. package/dist/schema/Collection.js +16 -20
  94. package/dist/schema/Map.js +12 -17
  95. package/dist/schema/Merge.js +13 -18
  96. package/dist/schema/Node.js +2 -5
  97. package/dist/schema/Pair.js +44 -31
  98. package/dist/schema/Scalar.js +6 -11
  99. package/dist/schema/Seq.js +9 -14
  100. package/dist/schema/index.js +22 -27
  101. package/dist/schema/parseMap.js +19 -28
  102. package/dist/schema/parseSeq.js +10 -15
  103. package/dist/schema/parseUtils.js +0 -3
  104. package/dist/stringify.js +6 -12
  105. package/dist/tags/core.js +34 -26
  106. package/dist/tags/failsafe/index.js +6 -11
  107. package/dist/tags/failsafe/map.js +8 -13
  108. package/dist/tags/failsafe/seq.js +8 -13
  109. package/dist/tags/failsafe/string.js +3 -6
  110. package/dist/tags/index.js +20 -29
  111. package/dist/tags/json.js +26 -22
  112. package/dist/tags/options.js +5 -4
  113. package/dist/tags/yaml-1.1/binary.js +11 -11
  114. package/dist/tags/yaml-1.1/index.js +69 -38
  115. package/dist/tags/yaml-1.1/omap.js +19 -24
  116. package/dist/tags/yaml-1.1/pairs.js +12 -17
  117. package/dist/tags/yaml-1.1/set.js +12 -21
  118. package/dist/tags/yaml-1.1/timestamp.js +0 -3
  119. package/dist/test-events.js +4 -9
  120. package/dist/toJSON.js +3 -5
  121. package/dist/warnings.js +31 -22
  122. package/index.d.ts +358 -0
  123. package/index.js +1 -1
  124. package/map.js +1 -1
  125. package/package.json +29 -23
  126. package/pair.js +1 -1
  127. package/parse-cst.d.ts +187 -0
  128. package/parse-cst.js +1 -1
  129. package/scalar.js +1 -1
  130. package/schema.js +2 -2
  131. package/seq.js +1 -1
  132. package/types/binary.js +1 -1
  133. package/types/omap.js +1 -1
  134. package/types/pairs.js +1 -1
  135. package/types/set.js +1 -1
  136. package/types/timestamp.js +1 -1
  137. package/types.d.ts +393 -0
  138. package/types.js +7 -6
  139. package/types.mjs +6 -5
  140. package/util.d.ts +86 -0
  141. package/util.js +6 -5
  142. package/util.mjs +4 -3
@@ -1,16 +1,23 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _inherits from "@babel/runtime/helpers/inherits";
3
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
6
7
  import _typeof from "@babel/runtime/helpers/typeof";
8
+
9
+ function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
+
11
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
12
+
7
13
  // Published as 'yaml/pair'
8
- import addComment from '../addComment';
14
+ import { addComment } from '../addComment';
9
15
  import { Type } from '../constants';
10
- import toJSON from '../toJSON';
11
- import Collection from './Collection';
12
- import Node from './Node';
13
- import Scalar from './Scalar';
16
+ import { toJSON } from '../toJSON';
17
+ import { Collection } from './Collection';
18
+ import { Node } from './Node';
19
+ import { Scalar } from './Scalar';
20
+ import { YAMLSeq } from './Seq';
14
21
 
15
22
  var stringifyKey = function stringifyKey(key, jsKey, ctx) {
16
23
  if (jsKey === null) return '';
@@ -19,15 +26,18 @@ var stringifyKey = function stringifyKey(key, jsKey, ctx) {
19
26
  anchors: {},
20
27
  doc: ctx.doc,
21
28
  indent: '',
29
+ indentStep: ctx.indentStep,
22
30
  inFlow: true,
23
31
  inStringifyKey: true
24
32
  });
25
33
  return JSON.stringify(jsKey);
26
34
  };
27
35
 
28
- var Pair = /*#__PURE__*/function (_Node) {
36
+ export var Pair = /*#__PURE__*/function (_Node) {
29
37
  _inherits(Pair, _Node);
30
38
 
39
+ var _super = _createSuper(Pair);
40
+
31
41
  function Pair(key) {
32
42
  var _this;
33
43
 
@@ -35,10 +45,10 @@ var Pair = /*#__PURE__*/function (_Node) {
35
45
 
36
46
  _classCallCheck(this, Pair);
37
47
 
38
- _this = _possibleConstructorReturn(this, _getPrototypeOf(Pair).call(this));
48
+ _this = _super.call(this);
39
49
  _this.key = key;
40
50
  _this.value = value;
41
- _this.type = 'PAIR';
51
+ _this.type = Pair.Type.PAIR;
42
52
  return _this;
43
53
  }
44
54
 
@@ -69,7 +79,10 @@ var Pair = /*#__PURE__*/function (_Node) {
69
79
  key: "toString",
70
80
  value: function toString(ctx, onComment, onChompKeep) {
71
81
  if (!ctx || !ctx.doc) return JSON.stringify(this);
72
- var simpleKeys = ctx.doc.options.simpleKeys;
82
+ var _ctx$doc$options = ctx.doc.options,
83
+ indentSize = _ctx$doc$options.indent,
84
+ indentSeq = _ctx$doc$options.indentSeq,
85
+ simpleKeys = _ctx$doc$options.simpleKeys;
73
86
  var key = this.key,
74
87
  value = this.value;
75
88
  var keyComment = key instanceof Node && key.comment;
@@ -88,10 +101,11 @@ var Pair = /*#__PURE__*/function (_Node) {
88
101
  var explicitKey = !simpleKeys && (!key || keyComment || key instanceof Collection || key.type === Type.BLOCK_FOLDED || key.type === Type.BLOCK_LITERAL);
89
102
  var _ctx = ctx,
90
103
  doc = _ctx.doc,
91
- indent = _ctx.indent;
104
+ indent = _ctx.indent,
105
+ indentStep = _ctx.indentStep;
92
106
  ctx = Object.assign({}, ctx, {
93
107
  implicitKey: !explicitKey,
94
- indent: indent + ' '
108
+ indent: indent + indentStep
95
109
  });
96
110
  var chompKeep = false;
97
111
  var str = doc.schema.stringify(key, ctx, function () {
@@ -137,6 +151,12 @@ var Pair = /*#__PURE__*/function (_Node) {
137
151
  ctx.implicitKey = false;
138
152
  if (!explicitKey && !this.comment && value instanceof Scalar) ctx.indentAtStart = str.length + 1;
139
153
  chompKeep = false;
154
+
155
+ if (!indentSeq && indentSize >= 2 && !ctx.inFlow && !explicitKey && value instanceof YAMLSeq && value.type !== Type.FLOW_SEQ && !value.tag && !doc.anchors.getName(value)) {
156
+ // If indentSeq === false, consider '- ' as part of indentation where possible
157
+ ctx.indent = ctx.indent.substr(2);
158
+ }
159
+
140
160
  var valueStr = doc.schema.stringify(value, ctx, function () {
141
161
  return valueComment = null;
142
162
  }, function () {
@@ -168,4 +188,7 @@ var Pair = /*#__PURE__*/function (_Node) {
168
188
  return Pair;
169
189
  }(Node);
170
190
 
171
- export { Pair as default };
191
+ _defineProperty(Pair, "Type", {
192
+ PAIR: 'PAIR',
193
+ MERGE_PAIR: 'MERGE_PAIR'
194
+ });
@@ -1,21 +1,27 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _inherits from "@babel/runtime/helpers/inherits";
3
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
- // Published as 'yaml/scalar'
7
- import _toJSON from '../toJSON';
8
- import Node from './Node';
9
6
 
10
- var Scalar = /*#__PURE__*/function (_Node) {
7
+ function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
+
9
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
10
+
11
+ // Published as 'yaml/scalar'
12
+ import { toJSON as _toJSON } from '../toJSON';
13
+ import { Node } from './Node';
14
+ export var Scalar = /*#__PURE__*/function (_Node) {
11
15
  _inherits(Scalar, _Node);
12
16
 
17
+ var _super = _createSuper(Scalar);
18
+
13
19
  function Scalar(value) {
14
20
  var _this;
15
21
 
16
22
  _classCallCheck(this, Scalar);
17
23
 
18
- _this = _possibleConstructorReturn(this, _getPrototypeOf(Scalar).call(this));
24
+ _this = _super.call(this);
19
25
  _this.value = value;
20
26
  return _this;
21
27
  }
@@ -33,6 +39,4 @@ var Scalar = /*#__PURE__*/function (_Node) {
33
39
  }]);
34
40
 
35
41
  return Scalar;
36
- }(Node);
37
-
38
- export { Scalar as default };
42
+ }(Node);
@@ -1,13 +1,24 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
3
  import _get from "@babel/runtime/helpers/get";
6
4
  import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
+
8
+ function _createForOfIteratorHelper(o) { if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
9
+
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+
12
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
13
+
14
+ function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
15
+
16
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
17
+
7
18
  // Published as 'yaml/seq'
8
- import _toJSON from '../toJSON';
9
- import Collection from './Collection';
10
- import Scalar from './Scalar';
19
+ import { toJSON as _toJSON } from '../toJSON';
20
+ import { Collection } from './Collection';
21
+ import { Scalar } from './Scalar';
11
22
 
12
23
  function asItemIndex(key) {
13
24
  var idx = key instanceof Scalar ? key.value : key;
@@ -15,13 +26,15 @@ function asItemIndex(key) {
15
26
  return Number.isInteger(idx) && idx >= 0 ? idx : null;
16
27
  }
17
28
 
18
- var YAMLSeq = /*#__PURE__*/function (_Collection) {
29
+ export var YAMLSeq = /*#__PURE__*/function (_Collection) {
19
30
  _inherits(YAMLSeq, _Collection);
20
31
 
32
+ var _super = _createSuper(YAMLSeq);
33
+
21
34
  function YAMLSeq() {
22
35
  _classCallCheck(this, YAMLSeq);
23
36
 
24
- return _possibleConstructorReturn(this, _getPrototypeOf(YAMLSeq).apply(this, arguments));
37
+ return _super.apply(this, arguments);
25
38
  }
26
39
 
27
40
  _createClass(YAMLSeq, [{
@@ -64,28 +77,19 @@ var YAMLSeq = /*#__PURE__*/function (_Collection) {
64
77
  var seq = [];
65
78
  if (ctx && ctx.onCreate) ctx.onCreate(seq);
66
79
  var i = 0;
67
- var _iteratorNormalCompletion = true;
68
- var _didIteratorError = false;
69
- var _iteratorError = undefined;
80
+
81
+ var _iterator = _createForOfIteratorHelper(this.items),
82
+ _step;
70
83
 
71
84
  try {
72
- for (var _iterator = this.items[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
85
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
73
86
  var item = _step.value;
74
87
  seq.push(_toJSON(item, String(i++), ctx));
75
88
  }
76
89
  } catch (err) {
77
- _didIteratorError = true;
78
- _iteratorError = err;
90
+ _iterator.e(err);
79
91
  } finally {
80
- try {
81
- if (!_iteratorNormalCompletion && _iterator.return != null) {
82
- _iterator.return();
83
- }
84
- } finally {
85
- if (_didIteratorError) {
86
- throw _iteratorError;
87
- }
88
- }
92
+ _iterator.f();
89
93
  }
90
94
 
91
95
  return seq;
@@ -109,6 +113,4 @@ var YAMLSeq = /*#__PURE__*/function (_Collection) {
109
113
  }]);
110
114
 
111
115
  return YAMLSeq;
112
- }(Collection);
113
-
114
- export { YAMLSeq as default };
116
+ }(Collection);
@@ -2,17 +2,24 @@ import _typeof from "@babel/runtime/helpers/typeof";
2
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
4
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
+
6
+ function _createForOfIteratorHelper(o) { if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
7
+
8
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9
+
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
11
+
5
12
  import { warnOptionDeprecation } from '../warnings';
6
13
  import { Type } from '../constants';
7
14
  import { YAMLReferenceError, YAMLWarning } from '../errors';
8
15
  import { stringifyString } from '../stringify';
9
16
  import { schemas, tags } from '../tags';
10
17
  import { resolveString } from '../tags/failsafe/string';
11
- import Alias from './Alias';
12
- import Collection from './Collection';
13
- import Node from './Node';
14
- import Pair from './Pair';
15
- import Scalar from './Scalar';
18
+ import { Alias } from './Alias';
19
+ import { Collection } from './Collection';
20
+ import { Node } from './Node';
21
+ import { Pair } from './Pair';
22
+ import { Scalar } from './Scalar';
16
23
 
17
24
  var isMap = function isMap(_ref) {
18
25
  var type = _ref.type;
@@ -24,7 +31,7 @@ var isSeq = function isSeq(_ref2) {
24
31
  return type === Type.FLOW_SEQ || type === Type.SEQ;
25
32
  };
26
33
 
27
- var Schema = /*#__PURE__*/function () {
34
+ export var Schema = /*#__PURE__*/function () {
28
35
  function Schema(_ref3) {
29
36
  var customTags = _ref3.customTags,
30
37
  merge = _ref3.merge,
@@ -54,28 +61,18 @@ var Schema = /*#__PURE__*/function () {
54
61
  }
55
62
 
56
63
  if (Array.isArray(customTags)) {
57
- var _iteratorNormalCompletion = true;
58
- var _didIteratorError = false;
59
- var _iteratorError = undefined;
64
+ var _iterator = _createForOfIteratorHelper(customTags),
65
+ _step;
60
66
 
61
67
  try {
62
- for (var _iterator = customTags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
68
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
63
69
  var tag = _step.value;
64
70
  this.tags = this.tags.concat(tag);
65
71
  }
66
72
  } catch (err) {
67
- _didIteratorError = true;
68
- _iteratorError = err;
73
+ _iterator.e(err);
69
74
  } finally {
70
- try {
71
- if (!_iteratorNormalCompletion && _iterator.return != null) {
72
- _iterator.return();
73
- }
74
- } finally {
75
- if (_didIteratorError) {
76
- throw _iteratorError;
77
- }
78
- }
75
+ _iterator.f();
79
76
  }
80
77
  } else if (typeof customTags === 'function') {
81
78
  this.tags = customTags(this.tags.slice());
@@ -327,12 +324,12 @@ var Schema = /*#__PURE__*/function () {
327
324
  };
328
325
  item = this.createNode(item, true, null, createCtx);
329
326
  var anchors = ctx.doc.anchors;
330
- var _iteratorNormalCompletion2 = true;
331
- var _didIteratorError2 = false;
332
- var _iteratorError2 = undefined;
327
+
328
+ var _iterator2 = _createForOfIteratorHelper(createCtx.aliasNodes),
329
+ _step2;
333
330
 
334
331
  try {
335
- for (var _iterator2 = createCtx.aliasNodes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
332
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
336
333
  var alias = _step2.value;
337
334
  alias.source = alias.source.node;
338
335
  var name = anchors.getName(alias.source);
@@ -343,18 +340,9 @@ var Schema = /*#__PURE__*/function () {
343
340
  }
344
341
  }
345
342
  } catch (err) {
346
- _didIteratorError2 = true;
347
- _iteratorError2 = err;
343
+ _iterator2.e(err);
348
344
  } finally {
349
- try {
350
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
351
- _iterator2.return();
352
- }
353
- } finally {
354
- if (_didIteratorError2) {
355
- throw _iteratorError2;
356
- }
357
- }
345
+ _iterator2.f();
358
346
  }
359
347
  }
360
348
 
@@ -377,6 +365,4 @@ _defineProperty(Schema, "defaultTags", {
377
365
  MAP: 'tag:yaml.org,2002:map',
378
366
  SEQ: 'tag:yaml.org,2002:seq',
379
367
  STR: 'tag:yaml.org,2002:str'
380
- });
381
-
382
- export { Schema as default };
368
+ });
@@ -1,13 +1,13 @@
1
1
  import { Char, Type } from '../constants';
2
- import PlainValue from '../cst/PlainValue';
2
+ import { PlainValue } from '../cst/PlainValue';
3
3
  import { YAMLSemanticError, YAMLSyntaxError, YAMLWarning } from '../errors';
4
- import Map from './Map';
5
- import Merge, { MERGE_KEY } from './Merge';
6
- import Pair from './Pair';
4
+ import { YAMLMap } from './Map';
5
+ import { Merge, MERGE_KEY } from './Merge';
6
+ import { Pair } from './Pair';
7
7
  import { checkFlowCollectionEnd, checkKeyLength, resolveComments } from './parseUtils';
8
- import Alias from './Alias';
9
- import Collection from './Collection';
10
- export default function parseMap(doc, cst) {
8
+ import { Alias } from './Alias';
9
+ import { Collection } from './Collection';
10
+ export function parseMap(doc, cst) {
11
11
  if (cst.type !== Type.MAP && cst.type !== Type.FLOW_MAP) {
12
12
  var msg = "A ".concat(cst.type, " node cannot be resolved as a mapping");
13
13
  doc.errors.push(new YAMLSyntaxError(cst, msg));
@@ -18,7 +18,7 @@ export default function parseMap(doc, cst) {
18
18
  comments = _ref.comments,
19
19
  items = _ref.items;
20
20
 
21
- var map = new Map();
21
+ var map = new YAMLMap();
22
22
  map.items = items;
23
23
  resolveComments(map, comments);
24
24
  var hasCollectionKey = false;
@@ -1,10 +1,10 @@
1
1
  import { Type } from '../constants';
2
2
  import { YAMLSemanticError, YAMLSyntaxError, YAMLWarning } from '../errors';
3
- import Pair from './Pair';
3
+ import { Pair } from './Pair';
4
4
  import { checkFlowCollectionEnd, checkKeyLength, resolveComments } from './parseUtils';
5
- import Seq from './Seq';
6
- import Collection from './Collection';
7
- export default function parseSeq(doc, cst) {
5
+ import { YAMLSeq } from './Seq';
6
+ import { Collection } from './Collection';
7
+ export function parseSeq(doc, cst) {
8
8
  if (cst.type !== Type.SEQ && cst.type !== Type.FLOW_SEQ) {
9
9
  var msg = "A ".concat(cst.type, " node cannot be resolved as a sequence");
10
10
  doc.errors.push(new YAMLSyntaxError(cst, msg));
@@ -15,7 +15,7 @@ export default function parseSeq(doc, cst) {
15
15
  comments = _ref.comments,
16
16
  items = _ref.items;
17
17
 
18
- var seq = new Seq();
18
+ var seq = new YAMLSeq();
19
19
  seq.items = items;
20
20
  resolveComments(seq, comments);
21
21
 
@@ -1,3 +1,9 @@
1
+ function _createForOfIteratorHelper(o) { if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+
5
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6
+
1
7
  import { YAMLSemanticError } from '../errors';
2
8
  import { Type } from '../constants';
3
9
  export function checkFlowCollectionEnd(errors, cst) {
@@ -67,12 +73,11 @@ export function checkKeyLength(errors, node, itemIdx, key, keyStart) {
67
73
  }
68
74
  }
69
75
  export function resolveComments(collection, comments) {
70
- var _iteratorNormalCompletion = true;
71
- var _didIteratorError = false;
72
- var _iteratorError = undefined;
76
+ var _iterator = _createForOfIteratorHelper(comments),
77
+ _step;
73
78
 
74
79
  try {
75
- for (var _iterator = comments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
80
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
76
81
  var _step$value = _step.value,
77
82
  afterKey = _step$value.afterKey,
78
83
  before = _step$value.before,
@@ -94,17 +99,8 @@ export function resolveComments(collection, comments) {
94
99
  }
95
100
  }
96
101
  } catch (err) {
97
- _didIteratorError = true;
98
- _iteratorError = err;
102
+ _iterator.e(err);
99
103
  } finally {
100
- try {
101
- if (!_iteratorNormalCompletion && _iterator.return != null) {
102
- _iterator.return();
103
- }
104
- } finally {
105
- if (_didIteratorError) {
106
- throw _iteratorError;
107
- }
108
- }
104
+ _iterator.f();
109
105
  }
110
106
  }
@@ -1,6 +1,6 @@
1
1
  import { addCommentBefore } from './addComment';
2
2
  import { Type } from './constants';
3
- import foldFlowLines, { FOLD_BLOCK, FOLD_FLOW, FOLD_QUOTED } from './foldFlowLines';
3
+ import { foldFlowLines, FOLD_BLOCK, FOLD_FLOW, FOLD_QUOTED } from './foldFlowLines';
4
4
  import { strOptions } from './tags/options';
5
5
 
6
6
  var getFoldOptions = function getFoldOptions(_ref) {
@@ -15,6 +15,7 @@ export function stringifyNumber(_ref2) {
15
15
  minFractionDigits = _ref2.minFractionDigits,
16
16
  tag = _ref2.tag,
17
17
  value = _ref2.value;
18
+ if (typeof value === 'bigint') return String(value);
18
19
  if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
19
20
  var n = JSON.stringify(value);
20
21
 
@@ -1,7 +1,23 @@
1
- import Scalar from '../schema/Scalar';
1
+ /* global BigInt */
2
+ import { Scalar } from '../schema/Scalar';
2
3
  import { stringifyNumber } from '../stringify';
3
- import failsafe from './failsafe';
4
- import { boolOptions, nullOptions } from './options';
4
+ import { failsafe } from './failsafe';
5
+ import { boolOptions, intOptions, nullOptions } from './options';
6
+
7
+ var intIdentify = function intIdentify(value) {
8
+ return typeof value === 'bigint' || Number.isInteger(value);
9
+ };
10
+
11
+ var intResolve = function intResolve(src, part, radix) {
12
+ return intOptions.asBigInt ? BigInt(src) : parseInt(part, radix);
13
+ };
14
+
15
+ function intStringify(node, radix, prefix) {
16
+ var value = node.value;
17
+ if (intIdentify(value) && value >= 0) return prefix + value.toString(radix);
18
+ return stringifyNumber(node);
19
+ }
20
+
5
21
  export var nullObj = {
6
22
  identify: function identify(value) {
7
23
  return value == null;
@@ -38,46 +54,45 @@ export var boolObj = {
38
54
  };
39
55
  export var octObj = {
40
56
  identify: function identify(value) {
41
- return typeof value === 'number';
57
+ return intIdentify(value) && value >= 0;
42
58
  },
43
59
  default: true,
44
60
  tag: 'tag:yaml.org,2002:int',
45
61
  format: 'OCT',
46
62
  test: /^0o([0-7]+)$/,
47
63
  resolve: function resolve(str, oct) {
48
- return parseInt(oct, 8);
64
+ return intResolve(str, oct, 8);
49
65
  },
50
- stringify: function stringify(_ref2) {
51
- var value = _ref2.value;
52
- return '0o' + value.toString(8);
66
+ options: intOptions,
67
+ stringify: function stringify(node) {
68
+ return intStringify(node, 8, '0o');
53
69
  }
54
70
  };
55
71
  export var intObj = {
56
- identify: function identify(value) {
57
- return typeof value === 'number';
58
- },
72
+ identify: intIdentify,
59
73
  default: true,
60
74
  tag: 'tag:yaml.org,2002:int',
61
75
  test: /^[-+]?[0-9]+$/,
62
76
  resolve: function resolve(str) {
63
- return parseInt(str, 10);
77
+ return intResolve(str, str, 10);
64
78
  },
79
+ options: intOptions,
65
80
  stringify: stringifyNumber
66
81
  };
67
82
  export var hexObj = {
68
83
  identify: function identify(value) {
69
- return typeof value === 'number';
84
+ return intIdentify(value) && value >= 0;
70
85
  },
71
86
  default: true,
72
87
  tag: 'tag:yaml.org,2002:int',
73
88
  format: 'HEX',
74
89
  test: /^0x([0-9a-fA-F]+)$/,
75
90
  resolve: function resolve(str, hex) {
76
- return parseInt(hex, 16);
91
+ return intResolve(str, hex, 16);
77
92
  },
78
- stringify: function stringify(_ref3) {
79
- var value = _ref3.value;
80
- return '0x' + value.toString(16);
93
+ options: intOptions,
94
+ stringify: function stringify(node) {
95
+ return intStringify(node, 16, '0x');
81
96
  }
82
97
  };
83
98
  export var nanObj = {
@@ -99,12 +114,12 @@ export var expObj = {
99
114
  default: true,
100
115
  tag: 'tag:yaml.org,2002:float',
101
116
  format: 'EXP',
102
- test: /^[-+]?(?:0|[1-9][0-9]*)(\.[0-9]*)?[eE][-+]?[0-9]+$/,
117
+ test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
103
118
  resolve: function resolve(str) {
104
119
  return parseFloat(str);
105
120
  },
106
- stringify: function stringify(_ref4) {
107
- var value = _ref4.value;
121
+ stringify: function stringify(_ref2) {
122
+ var value = _ref2.value;
108
123
  return Number(value).toExponential();
109
124
  }
110
125
  };
@@ -114,12 +129,13 @@ export var floatObj = {
114
129
  },
115
130
  default: true,
116
131
  tag: 'tag:yaml.org,2002:float',
117
- test: /^[-+]?(?:0|[1-9][0-9]*)\.([0-9]*)$/,
118
- resolve: function resolve(str, frac) {
132
+ test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/,
133
+ resolve: function resolve(str, frac1, frac2) {
134
+ var frac = frac1 || frac2;
119
135
  var node = new Scalar(parseFloat(str));
120
136
  if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
121
137
  return node;
122
138
  },
123
139
  stringify: stringifyNumber
124
140
  };
125
- export default failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
141
+ export var core = failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
@@ -1,4 +1,4 @@
1
- import map from './map';
2
- import seq from './seq';
3
- import str from './string';
4
- export default [map, seq, str];
1
+ import { map } from './map';
2
+ import { seq } from './seq';
3
+ import { string } from './string';
4
+ export var failsafe = [map, seq, string];