yaml 1.8.3 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/README.md +4 -4
  2. package/browser/dist/PlainValue-ff5147c6.js +1277 -0
  3. package/browser/dist/Schema-2bf2c74e.js +679 -0
  4. package/browser/dist/index.js +923 -38
  5. package/browser/dist/legacy-exports.js +3 -0
  6. package/browser/dist/parse-cst.js +1904 -0
  7. package/browser/dist/resolveSeq-04825f30.js +2373 -0
  8. package/browser/dist/types.js +4 -0
  9. package/browser/dist/util.js +2 -0
  10. package/browser/dist/warnings-0e4b70d3.js +499 -0
  11. package/browser/index.js +1 -1
  12. package/browser/map.js +2 -2
  13. package/browser/pair.js +2 -2
  14. package/browser/parse-cst.js +1 -1
  15. package/browser/scalar.js +2 -2
  16. package/browser/schema.js +8 -6
  17. package/browser/seq.js +2 -2
  18. package/browser/types/binary.js +3 -2
  19. package/browser/types/omap.js +3 -2
  20. package/browser/types/pairs.js +3 -2
  21. package/browser/types/set.js +3 -2
  22. package/browser/types/timestamp.js +6 -6
  23. package/browser/types.js +1 -11
  24. package/browser/util.js +1 -15
  25. package/dist/Document-2cf6b08c.js +757 -0
  26. package/dist/PlainValue-ec8e588e.js +876 -0
  27. package/dist/Schema-42e9705c.js +522 -0
  28. package/dist/index.js +21 -43
  29. package/dist/legacy-exports.js +16 -0
  30. package/dist/parse-cst.js +1747 -0
  31. package/dist/resolveSeq-4a68b39b.js +2115 -0
  32. package/dist/test-events.js +11 -14
  33. package/dist/types.js +23 -0
  34. package/dist/util.js +19 -0
  35. package/dist/warnings-39684f17.js +416 -0
  36. package/index.d.ts +372 -0
  37. package/index.js +1 -1
  38. package/map.js +2 -2
  39. package/package.json +32 -45
  40. package/pair.js +2 -2
  41. package/parse-cst.d.ts +187 -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 +407 -0
  52. package/types.js +16 -10
  53. package/types.mjs +15 -18
  54. package/util.d.ts +86 -0
  55. package/util.js +14 -13
  56. package/util.mjs +13 -19
  57. package/browser/dist/Anchors.js +0 -133
  58. package/browser/dist/Document.js +0 -819
  59. package/browser/dist/addComment.js +0 -8
  60. package/browser/dist/constants.js +0 -26
  61. package/browser/dist/cst/Alias.js +0 -42
  62. package/browser/dist/cst/BlankLine.js +0 -56
  63. package/browser/dist/cst/BlockValue.js +0 -247
  64. package/browser/dist/cst/Collection.js +0 -274
  65. package/browser/dist/cst/CollectionItem.js +0 -136
  66. package/browser/dist/cst/Comment.js +0 -40
  67. package/browser/dist/cst/Directive.js +0 -72
  68. package/browser/dist/cst/Document.js +0 -282
  69. package/browser/dist/cst/FlowCollection.js +0 -216
  70. package/browser/dist/cst/Node.js +0 -388
  71. package/browser/dist/cst/ParseContext.js +0 -248
  72. package/browser/dist/cst/PlainValue.js +0 -166
  73. package/browser/dist/cst/QuoteDouble.js +0 -241
  74. package/browser/dist/cst/QuoteSingle.js +0 -116
  75. package/browser/dist/cst/Range.js +0 -67
  76. package/browser/dist/cst/parse.js +0 -48
  77. package/browser/dist/cst/source-utils.js +0 -168
  78. package/browser/dist/errors.js +0 -112
  79. package/browser/dist/foldFlowLines.js +0 -138
  80. package/browser/dist/listTagNames.js +0 -28
  81. package/browser/dist/schema/Alias.js +0 -139
  82. package/browser/dist/schema/Collection.js +0 -267
  83. package/browser/dist/schema/Map.js +0 -178
  84. package/browser/dist/schema/Merge.js +0 -127
  85. package/browser/dist/schema/Node.js +0 -7
  86. package/browser/dist/schema/Pair.js +0 -171
  87. package/browser/dist/schema/Scalar.js +0 -38
  88. package/browser/dist/schema/Seq.js +0 -114
  89. package/browser/dist/schema/index.js +0 -382
  90. package/browser/dist/schema/parseMap.js +0 -312
  91. package/browser/dist/schema/parseSeq.js +0 -168
  92. package/browser/dist/schema/parseUtils.js +0 -110
  93. package/browser/dist/stringify.js +0 -331
  94. package/browser/dist/tags/core.js +0 -126
  95. package/browser/dist/tags/failsafe/index.js +0 -4
  96. package/browser/dist/tags/failsafe/map.js +0 -56
  97. package/browser/dist/tags/failsafe/seq.js +0 -43
  98. package/browser/dist/tags/failsafe/string.js +0 -28
  99. package/browser/dist/tags/index.js +0 -36
  100. package/browser/dist/tags/json.js +0 -76
  101. package/browser/dist/tags/options.js +0 -23
  102. package/browser/dist/tags/yaml-1.1/binary.js +0 -87
  103. package/browser/dist/tags/yaml-1.1/index.js +0 -157
  104. package/browser/dist/tags/yaml-1.1/omap.js +0 -142
  105. package/browser/dist/tags/yaml-1.1/pairs.js +0 -81
  106. package/browser/dist/tags/yaml-1.1/set.js +0 -114
  107. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -97
  108. package/browser/dist/test-events.js +0 -163
  109. package/browser/dist/toJSON.js +0 -20
  110. package/browser/dist/warnings.js +0 -28
  111. package/dist/Anchors.js +0 -125
  112. package/dist/Document.js +0 -710
  113. package/dist/addComment.js +0 -17
  114. package/dist/constants.js +0 -34
  115. package/dist/cst/Alias.js +0 -38
  116. package/dist/cst/BlankLine.js +0 -56
  117. package/dist/cst/BlockValue.js +0 -248
  118. package/dist/cst/Collection.js +0 -271
  119. package/dist/cst/CollectionItem.js +0 -140
  120. package/dist/cst/Comment.js +0 -38
  121. package/dist/cst/Directive.js +0 -64
  122. package/dist/cst/Document.js +0 -281
  123. package/dist/cst/FlowCollection.js +0 -218
  124. package/dist/cst/Node.js +0 -365
  125. package/dist/cst/ParseContext.js +0 -258
  126. package/dist/cst/PlainValue.js +0 -161
  127. package/dist/cst/QuoteDouble.js +0 -237
  128. package/dist/cst/QuoteSingle.js +0 -113
  129. package/dist/cst/Range.js +0 -63
  130. package/dist/cst/parse.js +0 -55
  131. package/dist/cst/source-utils.js +0 -178
  132. package/dist/errors.js +0 -102
  133. package/dist/foldFlowLines.js +0 -146
  134. package/dist/listTagNames.js +0 -38
  135. package/dist/schema/Alias.js +0 -110
  136. package/dist/schema/Collection.js +0 -188
  137. package/dist/schema/Map.js +0 -103
  138. package/dist/schema/Merge.js +0 -80
  139. package/dist/schema/Node.js +0 -10
  140. package/dist/schema/Pair.js +0 -161
  141. package/dist/schema/Scalar.js +0 -31
  142. package/dist/schema/Seq.js +0 -78
  143. package/dist/schema/index.js +0 -315
  144. package/dist/schema/parseMap.js +0 -343
  145. package/dist/schema/parseSeq.js +0 -180
  146. package/dist/schema/parseUtils.js +0 -104
  147. package/dist/stringify.js +0 -358
  148. package/dist/tags/core.js +0 -114
  149. package/dist/tags/failsafe/index.js +0 -17
  150. package/dist/tags/failsafe/map.js +0 -37
  151. package/dist/tags/failsafe/seq.js +0 -34
  152. package/dist/tags/failsafe/string.js +0 -40
  153. package/dist/tags/index.js +0 -62
  154. package/dist/tags/json.js +0 -60
  155. package/dist/tags/options.js +0 -35
  156. package/dist/tags/yaml-1.1/binary.js +0 -97
  157. package/dist/tags/yaml-1.1/index.js +0 -131
  158. package/dist/tags/yaml-1.1/omap.js +0 -105
  159. package/dist/tags/yaml-1.1/pairs.js +0 -80
  160. package/dist/tags/yaml-1.1/set.js +0 -91
  161. package/dist/tags/yaml-1.1/timestamp.js +0 -93
  162. package/dist/toJSON.js +0 -23
  163. package/dist/warnings.js +0 -39
@@ -1,126 +0,0 @@
1
- import Scalar from '../schema/Scalar';
2
- import { stringifyNumber } from '../stringify';
3
- import failsafe from './failsafe';
4
- import { boolOptions, nullOptions } from './options';
5
- export var nullObj = {
6
- identify: function identify(value) {
7
- return value == null;
8
- },
9
- createNode: function createNode(schema, value, ctx) {
10
- return ctx.wrapScalars ? new Scalar(null) : null;
11
- },
12
- default: true,
13
- tag: 'tag:yaml.org,2002:null',
14
- test: /^(?:~|[Nn]ull|NULL)?$/,
15
- resolve: function resolve() {
16
- return null;
17
- },
18
- options: nullOptions,
19
- stringify: function stringify() {
20
- return nullOptions.nullStr;
21
- }
22
- };
23
- export var boolObj = {
24
- identify: function identify(value) {
25
- return typeof value === 'boolean';
26
- },
27
- default: true,
28
- tag: 'tag:yaml.org,2002:bool',
29
- test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
30
- resolve: function resolve(str) {
31
- return str[0] === 't' || str[0] === 'T';
32
- },
33
- options: boolOptions,
34
- stringify: function stringify(_ref) {
35
- var value = _ref.value;
36
- return value ? boolOptions.trueStr : boolOptions.falseStr;
37
- }
38
- };
39
- export var octObj = {
40
- identify: function identify(value) {
41
- return typeof value === 'number';
42
- },
43
- default: true,
44
- tag: 'tag:yaml.org,2002:int',
45
- format: 'OCT',
46
- test: /^0o([0-7]+)$/,
47
- resolve: function resolve(str, oct) {
48
- return parseInt(oct, 8);
49
- },
50
- stringify: function stringify(_ref2) {
51
- var value = _ref2.value;
52
- return '0o' + value.toString(8);
53
- }
54
- };
55
- export var intObj = {
56
- identify: function identify(value) {
57
- return typeof value === 'number';
58
- },
59
- default: true,
60
- tag: 'tag:yaml.org,2002:int',
61
- test: /^[-+]?[0-9]+$/,
62
- resolve: function resolve(str) {
63
- return parseInt(str, 10);
64
- },
65
- stringify: stringifyNumber
66
- };
67
- export var hexObj = {
68
- identify: function identify(value) {
69
- return typeof value === 'number';
70
- },
71
- default: true,
72
- tag: 'tag:yaml.org,2002:int',
73
- format: 'HEX',
74
- test: /^0x([0-9a-fA-F]+)$/,
75
- resolve: function resolve(str, hex) {
76
- return parseInt(hex, 16);
77
- },
78
- stringify: function stringify(_ref3) {
79
- var value = _ref3.value;
80
- return '0x' + value.toString(16);
81
- }
82
- };
83
- export var nanObj = {
84
- identify: function identify(value) {
85
- return typeof value === 'number';
86
- },
87
- default: true,
88
- tag: 'tag:yaml.org,2002:float',
89
- test: /^(?:[-+]?\.inf|(\.nan))$/i,
90
- resolve: function resolve(str, nan) {
91
- return nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY;
92
- },
93
- stringify: stringifyNumber
94
- };
95
- export var expObj = {
96
- identify: function identify(value) {
97
- return typeof value === 'number';
98
- },
99
- default: true,
100
- tag: 'tag:yaml.org,2002:float',
101
- format: 'EXP',
102
- test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
103
- resolve: function resolve(str) {
104
- return parseFloat(str);
105
- },
106
- stringify: function stringify(_ref4) {
107
- var value = _ref4.value;
108
- return Number(value).toExponential();
109
- }
110
- };
111
- export var floatObj = {
112
- identify: function identify(value) {
113
- return typeof value === 'number';
114
- },
115
- default: true,
116
- tag: 'tag:yaml.org,2002:float',
117
- test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/,
118
- resolve: function resolve(str, frac1, frac2) {
119
- var frac = frac1 || frac2;
120
- var node = new Scalar(parseFloat(str));
121
- if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
122
- return node;
123
- },
124
- stringify: stringifyNumber
125
- };
126
- export default 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 str from './string';
4
- export default [map, seq, str];
@@ -1,56 +0,0 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- import YAMLMap from '../../schema/Map';
4
- import parseMap from '../../schema/parseMap';
5
-
6
- function createMap(schema, obj, ctx) {
7
- var map = new YAMLMap(schema);
8
-
9
- if (obj instanceof Map) {
10
- var _iteratorNormalCompletion = true;
11
- var _didIteratorError = false;
12
- var _iteratorError = undefined;
13
-
14
- try {
15
- for (var _iterator = obj[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
16
- var _step$value = _slicedToArray(_step.value, 2),
17
- key = _step$value[0],
18
- value = _step$value[1];
19
-
20
- map.items.push(schema.createPair(key, value, ctx));
21
- }
22
- } catch (err) {
23
- _didIteratorError = true;
24
- _iteratorError = err;
25
- } finally {
26
- try {
27
- if (!_iteratorNormalCompletion && _iterator.return != null) {
28
- _iterator.return();
29
- }
30
- } finally {
31
- if (_didIteratorError) {
32
- throw _iteratorError;
33
- }
34
- }
35
- }
36
- } else if (obj && _typeof(obj) === 'object') {
37
- for (var _i = 0, _Object$keys = Object.keys(obj); _i < _Object$keys.length; _i++) {
38
- var _key = _Object$keys[_i];
39
- map.items.push(schema.createPair(_key, obj[_key], ctx));
40
- }
41
- }
42
-
43
- if (typeof schema.sortMapEntries === 'function') {
44
- map.items.sort(schema.sortMapEntries);
45
- }
46
-
47
- return map;
48
- }
49
-
50
- export default {
51
- createNode: createMap,
52
- default: true,
53
- nodeClass: YAMLMap,
54
- tag: 'tag:yaml.org,2002:map',
55
- resolve: parseMap
56
- };
@@ -1,43 +0,0 @@
1
- import parseSeq from '../../schema/parseSeq';
2
- import YAMLSeq from '../../schema/Seq';
3
-
4
- function createSeq(schema, obj, ctx) {
5
- var seq = new YAMLSeq(schema);
6
-
7
- if (obj && obj[Symbol.iterator]) {
8
- var _iteratorNormalCompletion = true;
9
- var _didIteratorError = false;
10
- var _iteratorError = undefined;
11
-
12
- try {
13
- for (var _iterator = obj[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
14
- var it = _step.value;
15
- var v = schema.createNode(it, ctx.wrapScalars, null, ctx);
16
- seq.items.push(v);
17
- }
18
- } catch (err) {
19
- _didIteratorError = true;
20
- _iteratorError = err;
21
- } finally {
22
- try {
23
- if (!_iteratorNormalCompletion && _iterator.return != null) {
24
- _iterator.return();
25
- }
26
- } finally {
27
- if (_didIteratorError) {
28
- throw _iteratorError;
29
- }
30
- }
31
- }
32
- }
33
-
34
- return seq;
35
- }
36
-
37
- export default {
38
- createNode: createSeq,
39
- default: true,
40
- nodeClass: YAMLSeq,
41
- tag: 'tag:yaml.org,2002:seq',
42
- resolve: parseSeq
43
- };
@@ -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 default {
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,76 +0,0 @@
1
- import map from './failsafe/map';
2
- import seq from './failsafe/seq';
3
- import Scalar from '../schema/Scalar';
4
- import { resolveString } from './failsafe/string';
5
- var schema = [map, seq, {
6
- identify: function identify(value) {
7
- return typeof value === 'string';
8
- },
9
- default: true,
10
- tag: 'tag:yaml.org,2002:str',
11
- resolve: resolveString,
12
- stringify: function stringify(value) {
13
- return JSON.stringify(value);
14
- }
15
- }, {
16
- identify: function identify(value) {
17
- return value == null;
18
- },
19
- createNode: function createNode(schema, value, ctx) {
20
- return ctx.wrapScalars ? new Scalar(null) : null;
21
- },
22
- default: true,
23
- tag: 'tag:yaml.org,2002:null',
24
- test: /^null$/,
25
- resolve: function resolve() {
26
- return null;
27
- },
28
- stringify: function stringify(value) {
29
- return JSON.stringify(value);
30
- }
31
- }, {
32
- identify: function identify(value) {
33
- return typeof value === 'boolean';
34
- },
35
- default: true,
36
- tag: 'tag:yaml.org,2002:bool',
37
- test: /^true|false$/,
38
- resolve: function resolve(str) {
39
- return str === 'true';
40
- },
41
- stringify: function stringify(value) {
42
- return JSON.stringify(value);
43
- }
44
- }, {
45
- identify: function identify(value) {
46
- return typeof value === 'number';
47
- },
48
- default: true,
49
- tag: 'tag:yaml.org,2002:int',
50
- test: /^-?(?:0|[1-9][0-9]*)$/,
51
- resolve: function resolve(str) {
52
- return parseInt(str, 10);
53
- },
54
- stringify: function stringify(value) {
55
- return JSON.stringify(value);
56
- }
57
- }, {
58
- identify: function identify(value) {
59
- return typeof value === 'number';
60
- },
61
- default: true,
62
- tag: 'tag:yaml.org,2002:float',
63
- test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
64
- resolve: function resolve(str) {
65
- return parseFloat(str);
66
- },
67
- stringify: function stringify(value) {
68
- return JSON.stringify(value);
69
- }
70
- }];
71
-
72
- schema.scalarFallback = function (str) {
73
- throw new SyntaxError("Unresolved plain scalar ".concat(JSON.stringify(str)));
74
- };
75
-
76
- export default schema;
@@ -1,23 +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 nullOptions = {
11
- nullStr: 'null'
12
- };
13
- export var strOptions = {
14
- defaultType: Type.PLAIN,
15
- doubleQuoted: {
16
- jsonEncoding: false,
17
- minMultiLineLength: 40
18
- },
19
- fold: {
20
- lineWidth: 80,
21
- minContentWidth: 20
22
- }
23
- };
@@ -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 default {
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,157 +0,0 @@
1
- import Scalar from '../../schema/Scalar';
2
- import { stringifyNumber } from '../../stringify';
3
- import failsafe from '../failsafe';
4
- import { boolOptions, nullOptions } from '../options';
5
- import binary from './binary';
6
- import omap from './omap';
7
- import pairs from './pairs';
8
- import set from './set';
9
- import { intTime, floatTime, timestamp } from './timestamp';
10
-
11
- var boolStringify = function boolStringify(_ref) {
12
- var value = _ref.value;
13
- return value ? boolOptions.trueStr : boolOptions.falseStr;
14
- };
15
-
16
- export default failsafe.concat([{
17
- identify: function identify(value) {
18
- return value == null;
19
- },
20
- createNode: function createNode(schema, value, ctx) {
21
- return ctx.wrapScalars ? new Scalar(null) : null;
22
- },
23
- default: true,
24
- tag: 'tag:yaml.org,2002:null',
25
- test: /^(?:~|[Nn]ull|NULL)?$/,
26
- resolve: function resolve() {
27
- return null;
28
- },
29
- options: nullOptions,
30
- stringify: function stringify() {
31
- return nullOptions.nullStr;
32
- }
33
- }, {
34
- identify: function identify(value) {
35
- return typeof value === 'boolean';
36
- },
37
- default: true,
38
- tag: 'tag:yaml.org,2002:bool',
39
- test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
40
- resolve: function resolve() {
41
- return true;
42
- },
43
- options: boolOptions,
44
- stringify: boolStringify
45
- }, {
46
- identify: function identify(value) {
47
- return typeof value === 'boolean';
48
- },
49
- default: true,
50
- tag: 'tag:yaml.org,2002:bool',
51
- test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
52
- resolve: function resolve() {
53
- return false;
54
- },
55
- options: boolOptions,
56
- stringify: boolStringify
57
- }, {
58
- identify: function identify(value) {
59
- return typeof value === 'number';
60
- },
61
- default: true,
62
- tag: 'tag:yaml.org,2002:int',
63
- format: 'BIN',
64
- test: /^0b([0-1_]+)$/,
65
- resolve: function resolve(str, bin) {
66
- return parseInt(bin.replace(/_/g, ''), 2);
67
- },
68
- stringify: function stringify(_ref2) {
69
- var value = _ref2.value;
70
- return '0b' + value.toString(2);
71
- }
72
- }, {
73
- identify: function identify(value) {
74
- return typeof value === 'number';
75
- },
76
- default: true,
77
- tag: 'tag:yaml.org,2002:int',
78
- format: 'OCT',
79
- test: /^[-+]?0([0-7_]+)$/,
80
- resolve: function resolve(str, oct) {
81
- return parseInt(oct.replace(/_/g, ''), 8);
82
- },
83
- stringify: function stringify(_ref3) {
84
- var value = _ref3.value;
85
- return (value < 0 ? '-0' : '0') + value.toString(8);
86
- }
87
- }, {
88
- identify: function identify(value) {
89
- return typeof value === 'number';
90
- },
91
- default: true,
92
- tag: 'tag:yaml.org,2002:int',
93
- test: /^[-+]?[0-9][0-9_]*$/,
94
- resolve: function resolve(str) {
95
- return parseInt(str.replace(/_/g, ''), 10);
96
- },
97
- stringify: stringifyNumber
98
- }, {
99
- identify: function identify(value) {
100
- return typeof value === 'number';
101
- },
102
- default: true,
103
- tag: 'tag:yaml.org,2002:int',
104
- format: 'HEX',
105
- test: /^0x([0-9a-fA-F_]+)$/,
106
- resolve: function resolve(str, hex) {
107
- return parseInt(hex.replace(/_/g, ''), 16);
108
- },
109
- stringify: function stringify(_ref4) {
110
- var value = _ref4.value;
111
- return (value < 0 ? '-0x' : '0x') + value.toString(16);
112
- }
113
- }, {
114
- identify: function identify(value) {
115
- return typeof value === 'number';
116
- },
117
- default: true,
118
- tag: 'tag:yaml.org,2002:float',
119
- test: /^(?:[-+]?\.inf|(\.nan))$/i,
120
- resolve: function resolve(str, nan) {
121
- return nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY;
122
- },
123
- stringify: stringifyNumber
124
- }, {
125
- identify: function identify(value) {
126
- return typeof value === 'number';
127
- },
128
- default: true,
129
- tag: 'tag:yaml.org,2002:float',
130
- format: 'EXP',
131
- test: /^[-+]?([0-9][0-9_]*)?(\.[0-9_]*)?[eE][-+]?[0-9]+$/,
132
- resolve: function resolve(str) {
133
- return parseFloat(str.replace(/_/g, ''));
134
- },
135
- stringify: function stringify(_ref5) {
136
- var value = _ref5.value;
137
- return Number(value).toExponential();
138
- }
139
- }, {
140
- identify: function identify(value) {
141
- return typeof value === 'number';
142
- },
143
- default: true,
144
- tag: 'tag:yaml.org,2002:float',
145
- test: /^[-+]?(?:[0-9][0-9_]*)?\.([0-9_]*)$/,
146
- resolve: function resolve(str, frac) {
147
- var node = new Scalar(parseFloat(str.replace(/_/g, '')));
148
-
149
- if (frac) {
150
- var f = frac.replace(/_/g, '');
151
- if (f[f.length - 1] === '0') node.minFractionDigits = f.length;
152
- }
153
-
154
- return node;
155
- },
156
- stringify: stringifyNumber
157
- }], binary, omap, pairs, set, intTime, floatTime, timestamp);