yaml 1.9.1 → 1.10.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 (162) hide show
  1. package/README.md +25 -25
  2. package/browser/dist/PlainValue-b8036b75.js +1275 -0
  3. package/browser/dist/Schema-e94716c8.js +682 -0
  4. package/browser/dist/index.js +860 -27
  5. package/browser/dist/legacy-exports.js +3 -0
  6. package/browser/dist/package.json +1 -0
  7. package/browser/dist/parse-cst.js +1904 -0
  8. package/browser/dist/resolveSeq-492ab440.js +2419 -0
  9. package/browser/dist/types.js +4 -0
  10. package/browser/dist/util.js +2 -0
  11. package/browser/dist/warnings-df54cb69.js +499 -0
  12. package/browser/index.js +1 -1
  13. package/browser/map.js +2 -4
  14. package/browser/pair.js +2 -4
  15. package/browser/parse-cst.js +1 -1
  16. package/browser/scalar.js +2 -4
  17. package/browser/schema.js +7 -10
  18. package/browser/seq.js +2 -4
  19. package/browser/types/binary.js +7 -5
  20. package/browser/types/omap.js +3 -4
  21. package/browser/types/pairs.js +3 -4
  22. package/browser/types/set.js +3 -4
  23. package/browser/types/timestamp.js +9 -5
  24. package/browser/types.js +1 -13
  25. package/browser/util.js +1 -18
  26. package/dist/Document-9b4560a1.js +757 -0
  27. package/dist/PlainValue-ec8e588e.js +876 -0
  28. package/dist/Schema-88e323a7.js +525 -0
  29. package/dist/index.js +20 -84
  30. package/dist/legacy-exports.js +16 -0
  31. package/dist/parse-cst.js +1753 -0
  32. package/dist/resolveSeq-d03cb037.js +2161 -0
  33. package/dist/test-events.js +11 -9
  34. package/dist/types.js +23 -0
  35. package/dist/util.js +19 -0
  36. package/dist/warnings-1000a372.js +416 -0
  37. package/index.d.ts +23 -9
  38. package/map.js +2 -2
  39. package/package.json +27 -42
  40. package/pair.js +2 -2
  41. package/parse-cst.d.ts +4 -0
  42. package/parse-cst.js +1 -1
  43. package/scalar.js +2 -2
  44. package/schema.js +8 -6
  45. package/seq.js +2 -2
  46. package/types/binary.js +3 -2
  47. package/types/omap.js +3 -2
  48. package/types/pairs.js +3 -2
  49. package/types/set.js +3 -2
  50. package/types/timestamp.js +6 -6
  51. package/types.d.ts +113 -98
  52. package/types.js +16 -11
  53. package/types.mjs +15 -19
  54. package/util.js +14 -14
  55. package/util.mjs +13 -20
  56. package/browser/dist/Anchors.js +0 -130
  57. package/browser/dist/Document.js +0 -824
  58. package/browser/dist/addComment.js +0 -8
  59. package/browser/dist/constants.js +0 -26
  60. package/browser/dist/cst/Alias.js +0 -46
  61. package/browser/dist/cst/BlankLine.js +0 -52
  62. package/browser/dist/cst/BlockValue.js +0 -251
  63. package/browser/dist/cst/Collection.js +0 -278
  64. package/browser/dist/cst/CollectionItem.js +0 -140
  65. package/browser/dist/cst/Comment.js +0 -44
  66. package/browser/dist/cst/Directive.js +0 -76
  67. package/browser/dist/cst/Document.js +0 -286
  68. package/browser/dist/cst/FlowCollection.js +0 -220
  69. package/browser/dist/cst/Node.js +0 -386
  70. package/browser/dist/cst/ParseContext.js +0 -246
  71. package/browser/dist/cst/PlainValue.js +0 -170
  72. package/browser/dist/cst/QuoteDouble.js +0 -245
  73. package/browser/dist/cst/QuoteSingle.js +0 -120
  74. package/browser/dist/cst/Range.js +0 -64
  75. package/browser/dist/cst/parse.js +0 -48
  76. package/browser/dist/cst/source-utils.js +0 -168
  77. package/browser/dist/errors.js +0 -127
  78. package/browser/dist/foldFlowLines.js +0 -138
  79. package/browser/dist/listTagNames.js +0 -28
  80. package/browser/dist/schema/Alias.js +0 -135
  81. package/browser/dist/schema/Collection.js +0 -260
  82. package/browser/dist/schema/Map.js +0 -161
  83. package/browser/dist/schema/Merge.js +0 -118
  84. package/browser/dist/schema/Node.js +0 -4
  85. package/browser/dist/schema/Pair.js +0 -194
  86. package/browser/dist/schema/Scalar.js +0 -42
  87. package/browser/dist/schema/Seq.js +0 -116
  88. package/browser/dist/schema/index.js +0 -368
  89. package/browser/dist/schema/parseMap.js +0 -312
  90. package/browser/dist/schema/parseSeq.js +0 -168
  91. package/browser/dist/schema/parseUtils.js +0 -106
  92. package/browser/dist/stringify.js +0 -332
  93. package/browser/dist/tags/core.js +0 -141
  94. package/browser/dist/tags/failsafe/index.js +0 -4
  95. package/browser/dist/tags/failsafe/map.js +0 -53
  96. package/browser/dist/tags/failsafe/seq.js +0 -39
  97. package/browser/dist/tags/failsafe/string.js +0 -28
  98. package/browser/dist/tags/index.js +0 -36
  99. package/browser/dist/tags/json.js +0 -77
  100. package/browser/dist/tags/options.js +0 -26
  101. package/browser/dist/tags/yaml-1.1/binary.js +0 -87
  102. package/browser/dist/tags/yaml-1.1/index.js +0 -189
  103. package/browser/dist/tags/yaml-1.1/omap.js +0 -137
  104. package/browser/dist/tags/yaml-1.1/pairs.js +0 -78
  105. package/browser/dist/tags/yaml-1.1/set.js +0 -118
  106. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -97
  107. package/browser/dist/test-events.js +0 -163
  108. package/browser/dist/toJSON.js +0 -19
  109. package/browser/dist/warnings.js +0 -39
  110. package/dist/Anchors.js +0 -120
  111. package/dist/Document.js +0 -714
  112. package/dist/addComment.js +0 -14
  113. package/dist/constants.js +0 -31
  114. package/dist/cst/Alias.js +0 -33
  115. package/dist/cst/BlankLine.js +0 -40
  116. package/dist/cst/BlockValue.js +0 -243
  117. package/dist/cst/Collection.js +0 -266
  118. package/dist/cst/CollectionItem.js +0 -135
  119. package/dist/cst/Comment.js +0 -33
  120. package/dist/cst/Directive.js +0 -59
  121. package/dist/cst/Document.js +0 -276
  122. package/dist/cst/FlowCollection.js +0 -213
  123. package/dist/cst/Node.js +0 -360
  124. package/dist/cst/ParseContext.js +0 -253
  125. package/dist/cst/PlainValue.js +0 -156
  126. package/dist/cst/QuoteDouble.js +0 -232
  127. package/dist/cst/QuoteSingle.js +0 -108
  128. package/dist/cst/Range.js +0 -60
  129. package/dist/cst/parse.js +0 -50
  130. package/dist/cst/source-utils.js +0 -175
  131. package/dist/errors.js +0 -97
  132. package/dist/foldFlowLines.js +0 -143
  133. package/dist/listTagNames.js +0 -33
  134. package/dist/schema/Alias.js +0 -105
  135. package/dist/schema/Collection.js +0 -184
  136. package/dist/schema/Map.js +0 -98
  137. package/dist/schema/Merge.js +0 -75
  138. package/dist/schema/Node.js +0 -7
  139. package/dist/schema/Pair.js +0 -174
  140. package/dist/schema/Scalar.js +0 -26
  141. package/dist/schema/Seq.js +0 -73
  142. package/dist/schema/index.js +0 -310
  143. package/dist/schema/parseMap.js +0 -334
  144. package/dist/schema/parseSeq.js +0 -175
  145. package/dist/schema/parseUtils.js +0 -101
  146. package/dist/stringify.js +0 -352
  147. package/dist/tags/core.js +0 -121
  148. package/dist/tags/failsafe/index.js +0 -12
  149. package/dist/tags/failsafe/map.js +0 -32
  150. package/dist/tags/failsafe/seq.js +0 -29
  151. package/dist/tags/failsafe/string.js +0 -37
  152. package/dist/tags/index.js +0 -53
  153. package/dist/tags/json.js +0 -64
  154. package/dist/tags/options.js +0 -36
  155. package/dist/tags/yaml-1.1/binary.js +0 -94
  156. package/dist/tags/yaml-1.1/index.js +0 -162
  157. package/dist/tags/yaml-1.1/omap.js +0 -100
  158. package/dist/tags/yaml-1.1/pairs.js +0 -75
  159. package/dist/tags/yaml-1.1/set.js +0 -82
  160. package/dist/tags/yaml-1.1/timestamp.js +0 -90
  161. package/dist/toJSON.js +0 -21
  162. package/dist/warnings.js +0 -48
@@ -1,137 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
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
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
-
9
- 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; } } }; }
10
-
11
- 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); }
12
-
13
- 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; }
14
-
15
- 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); }; }
16
-
17
- 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; } }
18
-
19
- import { YAMLSemanticError } from '../../errors';
20
- import { toJSON as _toJSON } from '../../toJSON';
21
- import { YAMLMap } from '../../schema/Map';
22
- import { Pair } from '../../schema/Pair';
23
- import { Scalar } from '../../schema/Scalar';
24
- import { YAMLSeq } from '../../schema/Seq';
25
- import { createPairs, parsePairs } from './pairs';
26
- export var YAMLOMap = /*#__PURE__*/function (_YAMLSeq) {
27
- _inherits(YAMLOMap, _YAMLSeq);
28
-
29
- var _super = _createSuper(YAMLOMap);
30
-
31
- function YAMLOMap() {
32
- var _this;
33
-
34
- _classCallCheck(this, YAMLOMap);
35
-
36
- _this = _super.call(this);
37
-
38
- _defineProperty(_assertThisInitialized(_this), "add", YAMLMap.prototype.add.bind(_assertThisInitialized(_this)));
39
-
40
- _defineProperty(_assertThisInitialized(_this), "delete", YAMLMap.prototype.delete.bind(_assertThisInitialized(_this)));
41
-
42
- _defineProperty(_assertThisInitialized(_this), "get", YAMLMap.prototype.get.bind(_assertThisInitialized(_this)));
43
-
44
- _defineProperty(_assertThisInitialized(_this), "has", YAMLMap.prototype.has.bind(_assertThisInitialized(_this)));
45
-
46
- _defineProperty(_assertThisInitialized(_this), "set", YAMLMap.prototype.set.bind(_assertThisInitialized(_this)));
47
-
48
- _this.tag = YAMLOMap.tag;
49
- return _this;
50
- }
51
-
52
- _createClass(YAMLOMap, [{
53
- key: "toJSON",
54
- value: function toJSON(_, ctx) {
55
- var map = new Map();
56
- if (ctx && ctx.onCreate) ctx.onCreate(map);
57
-
58
- var _iterator = _createForOfIteratorHelper(this.items),
59
- _step;
60
-
61
- try {
62
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
63
- var pair = _step.value;
64
- var key = void 0,
65
- value = void 0;
66
-
67
- if (pair instanceof Pair) {
68
- key = _toJSON(pair.key, '', ctx);
69
- value = _toJSON(pair.value, key, ctx);
70
- } else {
71
- key = _toJSON(pair, '', ctx);
72
- }
73
-
74
- if (map.has(key)) throw new Error('Ordered maps must not include duplicate keys');
75
- map.set(key, value);
76
- }
77
- } catch (err) {
78
- _iterator.e(err);
79
- } finally {
80
- _iterator.f();
81
- }
82
-
83
- return map;
84
- }
85
- }]);
86
-
87
- return YAMLOMap;
88
- }(YAMLSeq);
89
-
90
- _defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap');
91
-
92
- function parseOMap(doc, cst) {
93
- var pairs = parsePairs(doc, cst);
94
- var seenKeys = [];
95
-
96
- var _iterator2 = _createForOfIteratorHelper(pairs.items),
97
- _step2;
98
-
99
- try {
100
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
101
- var key = _step2.value.key;
102
-
103
- if (key instanceof Scalar) {
104
- if (seenKeys.includes(key.value)) {
105
- var msg = 'Ordered maps must not include duplicate keys';
106
- throw new YAMLSemanticError(cst, msg);
107
- } else {
108
- seenKeys.push(key.value);
109
- }
110
- }
111
- }
112
- } catch (err) {
113
- _iterator2.e(err);
114
- } finally {
115
- _iterator2.f();
116
- }
117
-
118
- return Object.assign(new YAMLOMap(), pairs);
119
- }
120
-
121
- function createOMap(schema, iterable, ctx) {
122
- var pairs = createPairs(schema, iterable, ctx);
123
- var omap = new YAMLOMap();
124
- omap.items = pairs.items;
125
- return omap;
126
- }
127
-
128
- export var omap = {
129
- identify: function identify(value) {
130
- return value instanceof Map;
131
- },
132
- nodeClass: YAMLOMap,
133
- default: false,
134
- tag: 'tag:yaml.org,2002:omap',
135
- resolve: parseOMap,
136
- createNode: createOMap
137
- };
@@ -1,78 +0,0 @@
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
-
7
- import { YAMLSemanticError } from '../../errors';
8
- import { YAMLMap } from '../../schema/Map';
9
- import { Pair } from '../../schema/Pair';
10
- import { parseSeq } from '../../schema/parseSeq';
11
- import { YAMLSeq } from '../../schema/Seq';
12
- export function parsePairs(doc, cst) {
13
- var seq = parseSeq(doc, cst);
14
-
15
- for (var i = 0; i < seq.items.length; ++i) {
16
- var item = seq.items[i];
17
- if (item instanceof Pair) continue;else if (item instanceof YAMLMap) {
18
- if (item.items.length > 1) {
19
- var msg = 'Each pair must have its own sequence indicator';
20
- throw new YAMLSemanticError(cst, msg);
21
- }
22
-
23
- var pair = item.items[0] || new Pair();
24
- if (item.commentBefore) pair.commentBefore = pair.commentBefore ? "".concat(item.commentBefore, "\n").concat(pair.commentBefore) : item.commentBefore;
25
- if (item.comment) pair.comment = pair.comment ? "".concat(item.comment, "\n").concat(pair.comment) : item.comment;
26
- item = pair;
27
- }
28
- seq.items[i] = item instanceof Pair ? item : new Pair(item);
29
- }
30
-
31
- return seq;
32
- }
33
- export function createPairs(schema, iterable, ctx) {
34
- var pairs = new YAMLSeq(schema);
35
- pairs.tag = 'tag:yaml.org,2002:pairs';
36
-
37
- var _iterator = _createForOfIteratorHelper(iterable),
38
- _step;
39
-
40
- try {
41
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
42
- var it = _step.value;
43
- var key = void 0,
44
- value = void 0;
45
-
46
- if (Array.isArray(it)) {
47
- if (it.length === 2) {
48
- key = it[0];
49
- value = it[1];
50
- } else throw new TypeError("Expected [key, value] tuple: ".concat(it));
51
- } else if (it && it instanceof Object) {
52
- var keys = Object.keys(it);
53
-
54
- if (keys.length === 1) {
55
- key = keys[0];
56
- value = it[key];
57
- } else throw new TypeError("Expected { key: value } tuple: ".concat(it));
58
- } else {
59
- key = it;
60
- }
61
-
62
- var pair = schema.createPair(key, value, ctx);
63
- pairs.items.push(pair);
64
- }
65
- } catch (err) {
66
- _iterator.e(err);
67
- } finally {
68
- _iterator.f();
69
- }
70
-
71
- return pairs;
72
- }
73
- export var pairs = {
74
- default: false,
75
- tag: 'tag:yaml.org,2002:pairs',
76
- resolve: parsePairs,
77
- createNode: createPairs
78
- };
@@ -1,118 +0,0 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _get from "@babel/runtime/helpers/get";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
-
10
- 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; } } }; }
11
-
12
- 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); }
13
-
14
- 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; }
15
-
16
- 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); }; }
17
-
18
- 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; } }
19
-
20
- import { YAMLSemanticError } from '../../errors';
21
- import { YAMLMap, findPair } from '../../schema/Map';
22
- import { Pair } from '../../schema/Pair';
23
- import { parseMap } from '../../schema/parseMap';
24
- import { Scalar } from '../../schema/Scalar';
25
- export var YAMLSet = /*#__PURE__*/function (_YAMLMap) {
26
- _inherits(YAMLSet, _YAMLMap);
27
-
28
- var _super = _createSuper(YAMLSet);
29
-
30
- function YAMLSet() {
31
- var _this;
32
-
33
- _classCallCheck(this, YAMLSet);
34
-
35
- _this = _super.call(this);
36
- _this.tag = YAMLSet.tag;
37
- return _this;
38
- }
39
-
40
- _createClass(YAMLSet, [{
41
- key: "add",
42
- value: function add(key) {
43
- var pair = key instanceof Pair ? key : new Pair(key);
44
- var prev = findPair(this.items, pair.key);
45
- if (!prev) this.items.push(pair);
46
- }
47
- }, {
48
- key: "get",
49
- value: function get(key, keepPair) {
50
- var pair = findPair(this.items, key);
51
- return !keepPair && pair instanceof Pair ? pair.key instanceof Scalar ? pair.key.value : pair.key : pair;
52
- }
53
- }, {
54
- key: "set",
55
- value: function set(key, value) {
56
- if (typeof value !== 'boolean') throw new Error("Expected boolean value for set(key, value) in a YAML set, not ".concat(_typeof(value)));
57
- var prev = findPair(this.items, key);
58
-
59
- if (prev && !value) {
60
- this.items.splice(this.items.indexOf(prev), 1);
61
- } else if (!prev && value) {
62
- this.items.push(new Pair(key));
63
- }
64
- }
65
- }, {
66
- key: "toJSON",
67
- value: function toJSON(_, ctx) {
68
- return _get(_getPrototypeOf(YAMLSet.prototype), "toJSON", this).call(this, _, ctx, Set);
69
- }
70
- }, {
71
- key: "toString",
72
- value: function toString(ctx, onComment, onChompKeep) {
73
- if (!ctx) return JSON.stringify(this);
74
- if (this.hasAllNullValues()) return _get(_getPrototypeOf(YAMLSet.prototype), "toString", this).call(this, ctx, onComment, onChompKeep);else throw new Error('Set items must all have null values');
75
- }
76
- }]);
77
-
78
- return YAMLSet;
79
- }(YAMLMap);
80
-
81
- _defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set');
82
-
83
- function parseSet(doc, cst) {
84
- var map = parseMap(doc, cst);
85
- if (!map.hasAllNullValues()) throw new YAMLSemanticError(cst, 'Set items must all have null values');
86
- return Object.assign(new YAMLSet(), map);
87
- }
88
-
89
- function createSet(schema, iterable, ctx) {
90
- var set = new YAMLSet();
91
-
92
- var _iterator = _createForOfIteratorHelper(iterable),
93
- _step;
94
-
95
- try {
96
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
97
- var value = _step.value;
98
- set.items.push(schema.createPair(value, null, ctx));
99
- }
100
- } catch (err) {
101
- _iterator.e(err);
102
- } finally {
103
- _iterator.f();
104
- }
105
-
106
- return set;
107
- }
108
-
109
- export var set = {
110
- identify: function identify(value) {
111
- return value instanceof Set;
112
- },
113
- nodeClass: YAMLSet,
114
- default: false,
115
- tag: 'tag:yaml.org,2002:set',
116
- resolve: parseSet,
117
- createNode: createSet
118
- };
@@ -1,97 +0,0 @@
1
- import { stringifyNumber } from '../../stringify';
2
-
3
- var parseSexagesimal = function parseSexagesimal(sign, parts) {
4
- var n = parts.split(':').reduce(function (n, p) {
5
- return n * 60 + Number(p);
6
- }, 0);
7
- return sign === '-' ? -n : n;
8
- }; // hhhh:mm:ss.sss
9
-
10
-
11
- var stringifySexagesimal = function stringifySexagesimal(_ref) {
12
- var value = _ref.value;
13
- if (isNaN(value) || !isFinite(value)) return stringifyNumber(value);
14
- var sign = '';
15
-
16
- if (value < 0) {
17
- sign = '-';
18
- value = Math.abs(value);
19
- }
20
-
21
- var parts = [value % 60]; // seconds, including ms
22
-
23
- if (value < 60) {
24
- parts.unshift(0); // at least one : is required
25
- } else {
26
- value = Math.round((value - parts[0]) / 60);
27
- parts.unshift(value % 60); // minutes
28
-
29
- if (value >= 60) {
30
- value = Math.round((value - parts[0]) / 60);
31
- parts.unshift(value); // hours
32
- }
33
- }
34
-
35
- return sign + parts.map(function (n) {
36
- return n < 10 ? '0' + String(n) : String(n);
37
- }).join(':').replace(/000000\d*$/, '') // % 60 may introduce error
38
- ;
39
- };
40
-
41
- export var intTime = {
42
- identify: function identify(value) {
43
- return typeof value === 'number';
44
- },
45
- default: true,
46
- tag: 'tag:yaml.org,2002:int',
47
- format: 'TIME',
48
- test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+)$/,
49
- resolve: function resolve(str, sign, parts) {
50
- return parseSexagesimal(sign, parts.replace(/_/g, ''));
51
- },
52
- stringify: stringifySexagesimal
53
- };
54
- export var floatTime = {
55
- identify: function identify(value) {
56
- return typeof value === 'number';
57
- },
58
- default: true,
59
- tag: 'tag:yaml.org,2002:float',
60
- format: 'TIME',
61
- test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*)$/,
62
- resolve: function resolve(str, sign, parts) {
63
- return parseSexagesimal(sign, parts.replace(/_/g, ''));
64
- },
65
- stringify: stringifySexagesimal
66
- };
67
- export var timestamp = {
68
- identify: function identify(value) {
69
- return value instanceof Date;
70
- },
71
- default: true,
72
- tag: 'tag:yaml.org,2002:timestamp',
73
- // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
74
- // may be omitted altogether, resulting in a date format. In such a case, the time part is
75
- // assumed to be 00:00:00Z (start of day, UTC).
76
- test: RegExp('^(?:' + '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd
77
- '(?:(?:t|T|[ \\t]+)' + // t | T | whitespace
78
- '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)?
79
- '(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30
80
- ')?' + ')$'),
81
- resolve: function resolve(str, year, month, day, hour, minute, second, millisec, tz) {
82
- if (millisec) millisec = (millisec + '00').substr(1, 3);
83
- var date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0);
84
-
85
- if (tz && tz !== 'Z') {
86
- var d = parseSexagesimal(tz[0], tz.slice(1));
87
- if (Math.abs(d) < 30) d *= 60;
88
- date -= 60000 * d;
89
- }
90
-
91
- return new Date(date);
92
- },
93
- stringify: function stringify(_ref2) {
94
- var value = _ref2.value;
95
- return value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '');
96
- }
97
- };
@@ -1,163 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import { parse } from './cst/parse';
3
- import { Document } from './Document'; // test harness for yaml-test-suite event tests
4
-
5
- export function testEvents(src, options) {
6
- var opt = Object.assign({
7
- keepCstNodes: true,
8
- keepNodeTypes: true,
9
- version: '1.2'
10
- }, options);
11
- var docs = parse(src).map(function (cstDoc) {
12
- return new Document(opt).parse(cstDoc);
13
- });
14
- var errDoc = docs.find(function (doc) {
15
- return doc.errors.length > 0;
16
- });
17
- var error = errDoc ? errDoc.errors[0].message : null;
18
- var events = ['+STR'];
19
-
20
- try {
21
- for (var i = 0; i < docs.length; ++i) {
22
- var doc = docs[i];
23
- var root = doc.contents;
24
- if (Array.isArray(root)) root = root[0];
25
-
26
- var _ref = doc.range || [0, 0],
27
- _ref2 = _slicedToArray(_ref, 2),
28
- rootStart = _ref2[0],
29
- rootEnd = _ref2[1];
30
-
31
- var e = doc.errors[0] && doc.errors[0].source;
32
- if (e && e.type === 'SEQ_ITEM') e = e.node;
33
- if (e && (e.type === 'DOCUMENT' || e.range.start < rootStart)) throw new Error();
34
- var docStart = '+DOC';
35
- var pre = src.slice(0, rootStart);
36
- var explicitDoc = /---\s*$/.test(pre);
37
- if (explicitDoc) docStart += ' ---';else if (!doc.contents) continue;
38
- events.push(docStart);
39
- addEvents(events, doc, e, root);
40
- if (doc.contents && doc.contents.length > 1) throw new Error();
41
- var docEnd = '-DOC';
42
-
43
- if (rootEnd) {
44
- var post = src.slice(rootEnd);
45
- if (/^\.\.\./.test(post)) docEnd += ' ...';
46
- }
47
-
48
- events.push(docEnd);
49
- }
50
- } catch (e) {
51
- return {
52
- events: events,
53
- error: error || e
54
- };
55
- }
56
-
57
- events.push('-STR');
58
- return {
59
- events: events,
60
- error: error
61
- };
62
- }
63
-
64
- function addEvents(events, doc, e, node) {
65
- if (!node) {
66
- events.push('=VAL :');
67
- return;
68
- }
69
-
70
- if (e && node.cstNode === e) throw new Error();
71
- var props = '';
72
- var anchor = doc.anchors.getName(node);
73
-
74
- if (anchor) {
75
- if (/\d$/.test(anchor)) {
76
- var alt = anchor.replace(/\d$/, '');
77
- if (doc.anchors.getNode(alt)) anchor = alt;
78
- }
79
-
80
- props = " &".concat(anchor);
81
- }
82
-
83
- if (node.cstNode && node.cstNode.tag) {
84
- var _node$cstNode$tag = node.cstNode.tag,
85
- handle = _node$cstNode$tag.handle,
86
- suffix = _node$cstNode$tag.suffix;
87
- props += handle === '!' && !suffix ? ' <!>' : " <".concat(node.tag, ">");
88
- }
89
-
90
- var scalar = null;
91
-
92
- switch (node.type) {
93
- case 'ALIAS':
94
- {
95
- var alias = doc.anchors.getName(node.source);
96
-
97
- if (/\d$/.test(alias)) {
98
- var _alt = alias.replace(/\d$/, '');
99
-
100
- if (doc.anchors.getNode(_alt)) alias = _alt;
101
- }
102
-
103
- events.push("=ALI".concat(props, " *").concat(alias));
104
- }
105
- break;
106
-
107
- case 'BLOCK_FOLDED':
108
- scalar = '>';
109
- break;
110
-
111
- case 'BLOCK_LITERAL':
112
- scalar = '|';
113
- break;
114
-
115
- case 'PLAIN':
116
- scalar = ':';
117
- break;
118
-
119
- case 'QUOTE_DOUBLE':
120
- scalar = '"';
121
- break;
122
-
123
- case 'QUOTE_SINGLE':
124
- scalar = "'";
125
- break;
126
-
127
- case 'PAIR':
128
- events.push("+MAP".concat(props));
129
- addEvents(events, doc, e, node.key);
130
- addEvents(events, doc, e, node.value);
131
- events.push('-MAP');
132
- break;
133
-
134
- case 'FLOW_SEQ':
135
- case 'SEQ':
136
- events.push("+SEQ".concat(props));
137
- node.items.forEach(function (item) {
138
- addEvents(events, doc, e, item);
139
- });
140
- events.push('-SEQ');
141
- break;
142
-
143
- case 'FLOW_MAP':
144
- case 'MAP':
145
- events.push("+MAP".concat(props));
146
- node.items.forEach(function (_ref3) {
147
- var key = _ref3.key,
148
- value = _ref3.value;
149
- addEvents(events, doc, e, key);
150
- addEvents(events, doc, e, value);
151
- });
152
- events.push('-MAP');
153
- break;
154
-
155
- default:
156
- throw new Error("Unexpected node type ".concat(node.type));
157
- }
158
-
159
- if (scalar) {
160
- var value = node.cstNode.strValue.replace(/\\/g, '\\\\').replace(/\0/g, '\\0').replace(/\x07/g, '\\a').replace(/\x08/g, '\\b').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\v/g, '\\v').replace(/\f/g, '\\f').replace(/\r/g, '\\r').replace(/\x1b/g, '\\e');
161
- events.push("=VAL".concat(props, " ").concat(scalar).concat(value));
162
- }
163
- }
@@ -1,19 +0,0 @@
1
- export function toJSON(value, arg, ctx) {
2
- if (Array.isArray(value)) return value.map(function (v, i) {
3
- return toJSON(v, String(i), ctx);
4
- });
5
-
6
- if (value && typeof value.toJSON === 'function') {
7
- var anchor = ctx && ctx.anchors && ctx.anchors.get(value);
8
- if (anchor) ctx.onCreate = function (res) {
9
- anchor.res = res;
10
- delete ctx.onCreate;
11
- };
12
- var res = value.toJSON(arg, ctx);
13
- if (anchor && ctx.onCreate) ctx.onCreate(res);
14
- return res;
15
- }
16
-
17
- if ((!ctx || !ctx.keep) && typeof value === 'bigint') return Number(value);
18
- return value;
19
- }
@@ -1,39 +0,0 @@
1
- /* global console, process, YAML_SILENCE_DEPRECATION_WARNINGS, YAML_SILENCE_WARNINGS */
2
- function shouldWarn(deprecation) {
3
- var env = typeof process !== 'undefined' && process.env || {};
4
-
5
- if (deprecation) {
6
- if (typeof YAML_SILENCE_DEPRECATION_WARNINGS !== 'undefined') return !YAML_SILENCE_DEPRECATION_WARNINGS;
7
- return !env.YAML_SILENCE_DEPRECATION_WARNINGS;
8
- }
9
-
10
- if (typeof YAML_SILENCE_WARNINGS !== 'undefined') return !YAML_SILENCE_WARNINGS;
11
- return !env.YAML_SILENCE_WARNINGS;
12
- }
13
-
14
- export function warn(warning, type) {
15
- if (shouldWarn(false)) {
16
- var emit = typeof process !== 'undefined' && process.emitWarning; // This will throw in Jest if `warning` is an Error instance due to
17
- // https://github.com/facebook/jest/issues/2549
18
-
19
- if (emit) emit(warning, type);else {
20
- // eslint-disable-next-line no-console
21
- console.warn(type ? "".concat(type, ": ").concat(warning) : warning);
22
- }
23
- }
24
- }
25
- export function warnFileDeprecation(filename) {
26
- if (shouldWarn(true)) {
27
- var path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/');
28
- warn("The endpoint 'yaml/".concat(path, "' will be removed in a future release."), 'DeprecationWarning');
29
- }
30
- }
31
- var warned = {};
32
- export function warnOptionDeprecation(name, alternative) {
33
- if (!warned[name] && shouldWarn(true)) {
34
- warned[name] = true;
35
- var msg = "The option '".concat(name, "' will be removed in a future release");
36
- msg += alternative ? ", use '".concat(alternative, "' instead.") : '.';
37
- warn(msg, 'DeprecationWarning');
38
- }
39
- }