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,141 +0,0 @@
1
- /* global BigInt */
2
- import { Scalar } from '../schema/Scalar';
3
- import { stringifyNumber } from '../stringify';
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
-
21
- export var nullObj = {
22
- identify: function identify(value) {
23
- return value == null;
24
- },
25
- createNode: function createNode(schema, value, ctx) {
26
- return ctx.wrapScalars ? new Scalar(null) : null;
27
- },
28
- default: true,
29
- tag: 'tag:yaml.org,2002:null',
30
- test: /^(?:~|[Nn]ull|NULL)?$/,
31
- resolve: function resolve() {
32
- return null;
33
- },
34
- options: nullOptions,
35
- stringify: function stringify() {
36
- return nullOptions.nullStr;
37
- }
38
- };
39
- export var boolObj = {
40
- identify: function identify(value) {
41
- return typeof value === 'boolean';
42
- },
43
- default: true,
44
- tag: 'tag:yaml.org,2002:bool',
45
- test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
46
- resolve: function resolve(str) {
47
- return str[0] === 't' || str[0] === 'T';
48
- },
49
- options: boolOptions,
50
- stringify: function stringify(_ref) {
51
- var value = _ref.value;
52
- return value ? boolOptions.trueStr : boolOptions.falseStr;
53
- }
54
- };
55
- export var octObj = {
56
- identify: function identify(value) {
57
- return intIdentify(value) && value >= 0;
58
- },
59
- default: true,
60
- tag: 'tag:yaml.org,2002:int',
61
- format: 'OCT',
62
- test: /^0o([0-7]+)$/,
63
- resolve: function resolve(str, oct) {
64
- return intResolve(str, oct, 8);
65
- },
66
- options: intOptions,
67
- stringify: function stringify(node) {
68
- return intStringify(node, 8, '0o');
69
- }
70
- };
71
- export var intObj = {
72
- identify: intIdentify,
73
- default: true,
74
- tag: 'tag:yaml.org,2002:int',
75
- test: /^[-+]?[0-9]+$/,
76
- resolve: function resolve(str) {
77
- return intResolve(str, str, 10);
78
- },
79
- options: intOptions,
80
- stringify: stringifyNumber
81
- };
82
- export var hexObj = {
83
- identify: function identify(value) {
84
- return intIdentify(value) && value >= 0;
85
- },
86
- default: true,
87
- tag: 'tag:yaml.org,2002:int',
88
- format: 'HEX',
89
- test: /^0x([0-9a-fA-F]+)$/,
90
- resolve: function resolve(str, hex) {
91
- return intResolve(str, hex, 16);
92
- },
93
- options: intOptions,
94
- stringify: function stringify(node) {
95
- return intStringify(node, 16, '0x');
96
- }
97
- };
98
- export var nanObj = {
99
- identify: function identify(value) {
100
- return typeof value === 'number';
101
- },
102
- default: true,
103
- tag: 'tag:yaml.org,2002:float',
104
- test: /^(?:[-+]?\.inf|(\.nan))$/i,
105
- resolve: function resolve(str, nan) {
106
- return nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY;
107
- },
108
- stringify: stringifyNumber
109
- };
110
- export var expObj = {
111
- identify: function identify(value) {
112
- return typeof value === 'number';
113
- },
114
- default: true,
115
- tag: 'tag:yaml.org,2002:float',
116
- format: 'EXP',
117
- test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
118
- resolve: function resolve(str) {
119
- return parseFloat(str);
120
- },
121
- stringify: function stringify(_ref2) {
122
- var value = _ref2.value;
123
- return Number(value).toExponential();
124
- }
125
- };
126
- export var floatObj = {
127
- identify: function identify(value) {
128
- return typeof value === 'number';
129
- },
130
- default: true,
131
- tag: 'tag:yaml.org,2002:float',
132
- test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/,
133
- resolve: function resolve(str, frac1, frac2) {
134
- var frac = frac1 || frac2;
135
- var node = new Scalar(parseFloat(str));
136
- if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
137
- return node;
138
- },
139
- stringify: stringifyNumber
140
- };
141
- export var core = failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
@@ -1,4 +0,0 @@
1
- import { map } from './map';
2
- import { seq } from './seq';
3
- import { string } from './string';
4
- export var failsafe = [map, seq, string];
@@ -1,53 +0,0 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
-
4
- 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; } } }; }
5
-
6
- 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); }
7
-
8
- 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; }
9
-
10
- import { YAMLMap } from '../../schema/Map';
11
- import { parseMap } from '../../schema/parseMap';
12
-
13
- function createMap(schema, obj, ctx) {
14
- var map = new YAMLMap(schema);
15
-
16
- if (obj instanceof Map) {
17
- var _iterator = _createForOfIteratorHelper(obj),
18
- _step;
19
-
20
- try {
21
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
22
- var _step$value = _slicedToArray(_step.value, 2),
23
- key = _step$value[0],
24
- value = _step$value[1];
25
-
26
- map.items.push(schema.createPair(key, value, ctx));
27
- }
28
- } catch (err) {
29
- _iterator.e(err);
30
- } finally {
31
- _iterator.f();
32
- }
33
- } else if (obj && _typeof(obj) === 'object') {
34
- for (var _i = 0, _Object$keys = Object.keys(obj); _i < _Object$keys.length; _i++) {
35
- var _key = _Object$keys[_i];
36
- map.items.push(schema.createPair(_key, obj[_key], ctx));
37
- }
38
- }
39
-
40
- if (typeof schema.sortMapEntries === 'function') {
41
- map.items.sort(schema.sortMapEntries);
42
- }
43
-
44
- return map;
45
- }
46
-
47
- export var map = {
48
- createNode: createMap,
49
- default: true,
50
- nodeClass: YAMLMap,
51
- tag: 'tag:yaml.org,2002:map',
52
- resolve: parseMap
53
- };
@@ -1,39 +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 { parseSeq } from '../../schema/parseSeq';
8
- import { YAMLSeq } from '../../schema/Seq';
9
-
10
- function createSeq(schema, obj, ctx) {
11
- var seq = new YAMLSeq(schema);
12
-
13
- if (obj && obj[Symbol.iterator]) {
14
- var _iterator = _createForOfIteratorHelper(obj),
15
- _step;
16
-
17
- try {
18
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
19
- var it = _step.value;
20
- var v = schema.createNode(it, ctx.wrapScalars, null, ctx);
21
- seq.items.push(v);
22
- }
23
- } catch (err) {
24
- _iterator.e(err);
25
- } finally {
26
- _iterator.f();
27
- }
28
- }
29
-
30
- return seq;
31
- }
32
-
33
- export var seq = {
34
- createNode: createSeq,
35
- default: true,
36
- nodeClass: YAMLSeq,
37
- tag: 'tag:yaml.org,2002:seq',
38
- resolve: parseSeq
39
- };
@@ -1,28 +0,0 @@
1
- import { stringifyString } from '../../stringify';
2
- import { strOptions } from '../options';
3
- export var resolveString = function resolveString(doc, node) {
4
- // on error, will return { str: string, errors: Error[] }
5
- var res = node.strValue;
6
- if (!res) return '';
7
- if (typeof res === 'string') return res;
8
- res.errors.forEach(function (error) {
9
- if (!error.source) error.source = node;
10
- doc.errors.push(error);
11
- });
12
- return res.str;
13
- };
14
- export var string = {
15
- identify: function identify(value) {
16
- return typeof value === 'string';
17
- },
18
- default: true,
19
- tag: 'tag:yaml.org,2002:str',
20
- resolve: resolveString,
21
- stringify: function stringify(item, ctx, onComment, onChompKeep) {
22
- ctx = Object.assign({
23
- actualString: true
24
- }, ctx);
25
- return stringifyString(item, ctx, onComment, onChompKeep);
26
- },
27
- options: strOptions
28
- };
@@ -1,36 +0,0 @@
1
- import { core, nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj } from './core';
2
- import { failsafe } from './failsafe';
3
- import { json } from './json';
4
- import { yaml11 } from './yaml-1.1';
5
- import { map } from './failsafe/map';
6
- import { seq } from './failsafe/seq';
7
- import { binary } from './yaml-1.1/binary';
8
- import { omap } from './yaml-1.1/omap';
9
- import { pairs } from './yaml-1.1/pairs';
10
- import { set } from './yaml-1.1/set';
11
- import { floatTime, intTime, timestamp } from './yaml-1.1/timestamp';
12
- export var schemas = {
13
- core: core,
14
- failsafe: failsafe,
15
- json: json,
16
- yaml11: yaml11
17
- };
18
- export var tags = {
19
- binary: binary,
20
- bool: boolObj,
21
- float: floatObj,
22
- floatExp: expObj,
23
- floatNaN: nanObj,
24
- floatTime: floatTime,
25
- int: intObj,
26
- intHex: hexObj,
27
- intOct: octObj,
28
- intTime: intTime,
29
- map: map,
30
- null: nullObj,
31
- omap: omap,
32
- pairs: pairs,
33
- seq: seq,
34
- set: set,
35
- timestamp: timestamp
36
- };
@@ -1,77 +0,0 @@
1
- /* global BigInt */
2
- import { map } from './failsafe/map';
3
- import { seq } from './failsafe/seq';
4
- import { Scalar } from '../schema/Scalar';
5
- import { resolveString } from './failsafe/string';
6
- import { intOptions } from './options';
7
-
8
- var intIdentify = function intIdentify(value) {
9
- return typeof value === 'bigint' || Number.isInteger(value);
10
- };
11
-
12
- var stringifyJSON = function stringifyJSON(_ref) {
13
- var value = _ref.value;
14
- return JSON.stringify(value);
15
- };
16
-
17
- export var json = [map, seq, {
18
- identify: function identify(value) {
19
- return typeof value === 'string';
20
- },
21
- default: true,
22
- tag: 'tag:yaml.org,2002:str',
23
- resolve: resolveString,
24
- stringify: stringifyJSON
25
- }, {
26
- identify: function identify(value) {
27
- return value == null;
28
- },
29
- createNode: function createNode(schema, value, ctx) {
30
- return ctx.wrapScalars ? new Scalar(null) : null;
31
- },
32
- default: true,
33
- tag: 'tag:yaml.org,2002:null',
34
- test: /^null$/,
35
- resolve: function resolve() {
36
- return null;
37
- },
38
- stringify: stringifyJSON
39
- }, {
40
- identify: function identify(value) {
41
- return typeof value === 'boolean';
42
- },
43
- default: true,
44
- tag: 'tag:yaml.org,2002:bool',
45
- test: /^true|false$/,
46
- resolve: function resolve(str) {
47
- return str === 'true';
48
- },
49
- stringify: stringifyJSON
50
- }, {
51
- identify: intIdentify,
52
- default: true,
53
- tag: 'tag:yaml.org,2002:int',
54
- test: /^-?(?:0|[1-9][0-9]*)$/,
55
- resolve: function resolve(str) {
56
- return intOptions.asBigInt ? BigInt(str) : parseInt(str, 10);
57
- },
58
- stringify: function stringify(_ref2) {
59
- var value = _ref2.value;
60
- return intIdentify(value) ? value.toString() : JSON.stringify(value);
61
- }
62
- }, {
63
- identify: function identify(value) {
64
- return typeof value === 'number';
65
- },
66
- default: true,
67
- tag: 'tag:yaml.org,2002:float',
68
- test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
69
- resolve: function resolve(str) {
70
- return parseFloat(str);
71
- },
72
- stringify: stringifyJSON
73
- }];
74
-
75
- json.scalarFallback = function (str) {
76
- throw new SyntaxError("Unresolved plain scalar ".concat(JSON.stringify(str)));
77
- };
@@ -1,26 +0,0 @@
1
- import { Type } from '../constants';
2
- export var binaryOptions = {
3
- defaultType: Type.BLOCK_LITERAL,
4
- lineWidth: 76
5
- };
6
- export var boolOptions = {
7
- trueStr: 'true',
8
- falseStr: 'false'
9
- };
10
- export var intOptions = {
11
- asBigInt: false
12
- };
13
- export var nullOptions = {
14
- nullStr: 'null'
15
- };
16
- export var strOptions = {
17
- defaultType: Type.PLAIN,
18
- doubleQuoted: {
19
- jsonEncoding: false,
20
- minMultiLineLength: 40
21
- },
22
- fold: {
23
- lineWidth: 80,
24
- minContentWidth: 20
25
- }
26
- };
@@ -1,87 +0,0 @@
1
- /* global atob, btoa, Buffer */
2
- import { Type } from '../../constants';
3
- import { YAMLReferenceError } from '../../errors';
4
- import { stringifyString } from '../../stringify';
5
- import { resolveString } from '../failsafe/string';
6
- import { binaryOptions as options } from '../options';
7
- export var binary = {
8
- identify: function identify(value) {
9
- return value instanceof Uint8Array;
10
- },
11
- // Buffer inherits from Uint8Array
12
- default: false,
13
- tag: 'tag:yaml.org,2002:binary',
14
-
15
- /**
16
- * Returns a Buffer in node and an Uint8Array in browsers
17
- *
18
- * To use the resulting buffer as an image, you'll want to do something like:
19
- *
20
- * const blob = new Blob([buffer], { type: 'image/jpeg' })
21
- * document.querySelector('#photo').src = URL.createObjectURL(blob)
22
- */
23
- resolve: function resolve(doc, node) {
24
- var src = resolveString(doc, node);
25
-
26
- if (typeof Buffer === 'function') {
27
- return Buffer.from(src, 'base64');
28
- } else if (typeof atob === 'function') {
29
- // On IE 11, atob() can't handle newlines
30
- var str = atob(src.replace(/[\n\r]/g, ''));
31
- var buffer = new Uint8Array(str.length);
32
-
33
- for (var i = 0; i < str.length; ++i) {
34
- buffer[i] = str.charCodeAt(i);
35
- }
36
-
37
- return buffer;
38
- } else {
39
- var msg = 'This environment does not support reading binary tags; either Buffer or atob is required';
40
- doc.errors.push(new YAMLReferenceError(node, msg));
41
- return null;
42
- }
43
- },
44
- options: options,
45
- stringify: function stringify(_ref, ctx, onComment, onChompKeep) {
46
- var comment = _ref.comment,
47
- type = _ref.type,
48
- value = _ref.value;
49
- var src;
50
-
51
- if (typeof Buffer === 'function') {
52
- src = value instanceof Buffer ? value.toString('base64') : Buffer.from(value.buffer).toString('base64');
53
- } else if (typeof btoa === 'function') {
54
- var s = '';
55
-
56
- for (var i = 0; i < value.length; ++i) {
57
- s += String.fromCharCode(value[i]);
58
- }
59
-
60
- src = btoa(s);
61
- } else {
62
- throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');
63
- }
64
-
65
- if (!type) type = options.defaultType;
66
-
67
- if (type === Type.QUOTE_DOUBLE) {
68
- value = src;
69
- } else {
70
- var lineWidth = options.lineWidth;
71
- var n = Math.ceil(src.length / lineWidth);
72
- var lines = new Array(n);
73
-
74
- for (var _i = 0, o = 0; _i < n; ++_i, o += lineWidth) {
75
- lines[_i] = src.substr(o, lineWidth);
76
- }
77
-
78
- value = lines.join(type === Type.BLOCK_LITERAL ? '\n' : ' ');
79
- }
80
-
81
- return stringifyString({
82
- comment: comment,
83
- type: type,
84
- value: value
85
- }, ctx, onComment, onChompKeep);
86
- }
87
- };
@@ -1,189 +0,0 @@
1
- /* global BigInt */
2
- import { Scalar } from '../../schema/Scalar';
3
- import { stringifyNumber } from '../../stringify';
4
- import { failsafe } from '../failsafe';
5
- import { boolOptions, intOptions, nullOptions } from '../options';
6
- import { binary } from './binary';
7
- import { omap } from './omap';
8
- import { pairs } from './pairs';
9
- import { set } from './set';
10
- import { intTime, floatTime, timestamp } from './timestamp';
11
-
12
- var boolStringify = function boolStringify(_ref) {
13
- var value = _ref.value;
14
- return value ? boolOptions.trueStr : boolOptions.falseStr;
15
- };
16
-
17
- var intIdentify = function intIdentify(value) {
18
- return typeof value === 'bigint' || Number.isInteger(value);
19
- };
20
-
21
- function intResolve(sign, src, radix) {
22
- var str = src.replace(/_/g, '');
23
-
24
- if (intOptions.asBigInt) {
25
- switch (radix) {
26
- case 2:
27
- str = "0b".concat(str);
28
- break;
29
-
30
- case 8:
31
- str = "0o".concat(str);
32
- break;
33
-
34
- case 16:
35
- str = "0x".concat(str);
36
- break;
37
- }
38
-
39
- var _n = BigInt(str);
40
-
41
- return sign === '-' ? BigInt(-1) * _n : _n;
42
- }
43
-
44
- var n = parseInt(str, radix);
45
- return sign === '-' ? -1 * n : n;
46
- }
47
-
48
- function intStringify(node, radix, prefix) {
49
- var value = node.value;
50
-
51
- if (intIdentify(value)) {
52
- var str = value.toString(radix);
53
- return value < 0 ? '-' + prefix + str.substr(1) : prefix + str;
54
- }
55
-
56
- return stringifyNumber(node);
57
- }
58
-
59
- export var yaml11 = failsafe.concat([{
60
- identify: function identify(value) {
61
- return value == null;
62
- },
63
- createNode: function createNode(schema, value, ctx) {
64
- return ctx.wrapScalars ? new Scalar(null) : null;
65
- },
66
- default: true,
67
- tag: 'tag:yaml.org,2002:null',
68
- test: /^(?:~|[Nn]ull|NULL)?$/,
69
- resolve: function resolve() {
70
- return null;
71
- },
72
- options: nullOptions,
73
- stringify: function stringify() {
74
- return nullOptions.nullStr;
75
- }
76
- }, {
77
- identify: function identify(value) {
78
- return typeof value === 'boolean';
79
- },
80
- default: true,
81
- tag: 'tag:yaml.org,2002:bool',
82
- test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
83
- resolve: function resolve() {
84
- return true;
85
- },
86
- options: boolOptions,
87
- stringify: boolStringify
88
- }, {
89
- identify: function identify(value) {
90
- return typeof value === 'boolean';
91
- },
92
- default: true,
93
- tag: 'tag:yaml.org,2002:bool',
94
- test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
95
- resolve: function resolve() {
96
- return false;
97
- },
98
- options: boolOptions,
99
- stringify: boolStringify
100
- }, {
101
- identify: intIdentify,
102
- default: true,
103
- tag: 'tag:yaml.org,2002:int',
104
- format: 'BIN',
105
- test: /^([-+]?)0b([0-1_]+)$/,
106
- resolve: function resolve(str, sign, bin) {
107
- return intResolve(sign, bin, 2);
108
- },
109
- stringify: function stringify(node) {
110
- return intStringify(node, 2, '0b');
111
- }
112
- }, {
113
- identify: intIdentify,
114
- default: true,
115
- tag: 'tag:yaml.org,2002:int',
116
- format: 'OCT',
117
- test: /^([-+]?)0([0-7_]+)$/,
118
- resolve: function resolve(str, sign, oct) {
119
- return intResolve(sign, oct, 8);
120
- },
121
- stringify: function stringify(node) {
122
- return intStringify(node, 8, '0');
123
- }
124
- }, {
125
- identify: intIdentify,
126
- default: true,
127
- tag: 'tag:yaml.org,2002:int',
128
- test: /^([-+]?)([0-9][0-9_]*)$/,
129
- resolve: function resolve(str, sign, abs) {
130
- return intResolve(sign, abs, 10);
131
- },
132
- stringify: stringifyNumber
133
- }, {
134
- identify: intIdentify,
135
- default: true,
136
- tag: 'tag:yaml.org,2002:int',
137
- format: 'HEX',
138
- test: /^([-+]?)0x([0-9a-fA-F_]+)$/,
139
- resolve: function resolve(str, sign, hex) {
140
- return intResolve(sign, hex, 16);
141
- },
142
- stringify: function stringify(node) {
143
- return intStringify(node, 16, '0x');
144
- }
145
- }, {
146
- identify: function identify(value) {
147
- return typeof value === 'number';
148
- },
149
- default: true,
150
- tag: 'tag:yaml.org,2002:float',
151
- test: /^(?:[-+]?\.inf|(\.nan))$/i,
152
- resolve: function resolve(str, nan) {
153
- return nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY;
154
- },
155
- stringify: stringifyNumber
156
- }, {
157
- identify: function identify(value) {
158
- return typeof value === 'number';
159
- },
160
- default: true,
161
- tag: 'tag:yaml.org,2002:float',
162
- format: 'EXP',
163
- test: /^[-+]?([0-9][0-9_]*)?(\.[0-9_]*)?[eE][-+]?[0-9]+$/,
164
- resolve: function resolve(str) {
165
- return parseFloat(str.replace(/_/g, ''));
166
- },
167
- stringify: function stringify(_ref2) {
168
- var value = _ref2.value;
169
- return Number(value).toExponential();
170
- }
171
- }, {
172
- identify: function identify(value) {
173
- return typeof value === 'number';
174
- },
175
- default: true,
176
- tag: 'tag:yaml.org,2002:float',
177
- test: /^[-+]?(?:[0-9][0-9_]*)?\.([0-9_]*)$/,
178
- resolve: function resolve(str, frac) {
179
- var node = new Scalar(parseFloat(str.replace(/_/g, '')));
180
-
181
- if (frac) {
182
- var f = frac.replace(/_/g, '');
183
- if (f[f.length - 1] === '0') node.minFractionDigits = f.length;
184
- }
185
-
186
- return node;
187
- },
188
- stringify: stringifyNumber
189
- }], binary, omap, pairs, set, intTime, floatTime, timestamp);