warnings-df54cb69.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. import { o as YAMLReferenceError, T as Type, g as YAMLSemanticError, _ as _createForOfIteratorHelper, e as _defineProperty, j as _inherits, k as _createSuper, c as _classCallCheck, p as _assertThisInitialized, b as _createClass, a as _typeof, l as _get, m as _getPrototypeOf } from './PlainValue-b8036b75.js';
  2. import { j as resolveString, b as binaryOptions, c as stringifyString, h as resolveSeq, P as Pair, d as YAMLMap, Y as YAMLSeq, t as toJSON, S as Scalar, l as findPair, g as resolveMap, k as stringifyNumber } from './resolveSeq-492ab440.js';
  3. /* global atob, btoa, Buffer */
  4. var binary = {
  5. identify: function identify(value) {
  6. return value instanceof Uint8Array;
  7. },
  8. // Buffer inherits from Uint8Array
  9. default: false,
  10. tag: 'tag:yaml.org,2002:binary',
  11. /**
  12. * Returns a Buffer in node and an Uint8Array in browsers
  13. *
  14. * To use the resulting buffer as an image, you'll want to do something like:
  15. *
  16. * const blob = new Blob([buffer], { type: 'image/jpeg' })
  17. * document.querySelector('#photo').src = URL.createObjectURL(blob)
  18. */
  19. resolve: function resolve(doc, node) {
  20. var src = resolveString(doc, node);
  21. if (typeof Buffer === 'function') {
  22. return Buffer.from(src, 'base64');
  23. } else if (typeof atob === 'function') {
  24. // On IE 11, atob() can't handle newlines
  25. var str = atob(src.replace(/[\n\r]/g, ''));
  26. var buffer = new Uint8Array(str.length);
  27. for (var i = 0; i < str.length; ++i) {
  28. buffer[i] = str.charCodeAt(i);
  29. }
  30. return buffer;
  31. } else {
  32. var msg = 'This environment does not support reading binary tags; either Buffer or atob is required';
  33. doc.errors.push(new YAMLReferenceError(node, msg));
  34. return null;
  35. }
  36. },
  37. options: binaryOptions,
  38. stringify: function stringify(_ref, ctx, onComment, onChompKeep) {
  39. var comment = _ref.comment,
  40. type = _ref.type,
  41. value = _ref.value;
  42. var src;
  43. if (typeof Buffer === 'function') {
  44. src = value instanceof Buffer ? value.toString('base64') : Buffer.from(value.buffer).toString('base64');
  45. } else if (typeof btoa === 'function') {
  46. var s = '';
  47. for (var i = 0; i < value.length; ++i) {
  48. s += String.fromCharCode(value[i]);
  49. }
  50. src = btoa(s);
  51. } else {
  52. throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');
  53. }
  54. if (!type) type = binaryOptions.defaultType;
  55. if (type === Type.QUOTE_DOUBLE) {
  56. value = src;
  57. } else {
  58. var lineWidth = binaryOptions.lineWidth;
  59. var n = Math.ceil(src.length / lineWidth);
  60. var lines = new Array(n);
  61. for (var _i = 0, o = 0; _i < n; ++_i, o += lineWidth) {
  62. lines[_i] = src.substr(o, lineWidth);
  63. }
  64. value = lines.join(type === Type.BLOCK_LITERAL ? '\n' : ' ');
  65. }
  66. return stringifyString({
  67. comment: comment,
  68. type: type,
  69. value: value
  70. }, ctx, onComment, onChompKeep);
  71. }
  72. };
  73. function parsePairs(doc, cst) {
  74. var seq = resolveSeq(doc, cst);
  75. for (var i = 0; i < seq.items.length; ++i) {
  76. var item = seq.items[i];
  77. if (item instanceof Pair) continue;else if (item instanceof YAMLMap) {
  78. if (item.items.length > 1) {
  79. var msg = 'Each pair must have its own sequence indicator';
  80. throw new YAMLSemanticError(cst, msg);
  81. }
  82. var pair = item.items[0] || new Pair();
  83. if (item.commentBefore) pair.commentBefore = pair.commentBefore ? "".concat(item.commentBefore, "\n").concat(pair.commentBefore) : item.commentBefore;
  84. if (item.comment) pair.comment = pair.comment ? "".concat(item.comment, "\n").concat(pair.comment) : item.comment;
  85. item = pair;
  86. }
  87. seq.items[i] = item instanceof Pair ? item : new Pair(item);
  88. }
  89. return seq;
  90. }
  91. function createPairs(schema, iterable, ctx) {
  92. var pairs = new YAMLSeq(schema);
  93. pairs.tag = 'tag:yaml.org,2002:pairs';
  94. var _iterator = _createForOfIteratorHelper(iterable),
  95. _step;
  96. try {
  97. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  98. var it = _step.value;
  99. var key = void 0,
  100. value = void 0;
  101. if (Array.isArray(it)) {
  102. if (it.length === 2) {
  103. key = it[0];
  104. value = it[1];
  105. } else throw new TypeError("Expected [key, value] tuple: ".concat(it));
  106. } else if (it && it instanceof Object) {
  107. var keys = Object.keys(it);
  108. if (keys.length === 1) {
  109. key = keys[0];
  110. value = it[key];
  111. } else throw new TypeError("Expected { key: value } tuple: ".concat(it));
  112. } else {
  113. key = it;
  114. }
  115. var pair = schema.createPair(key, value, ctx);
  116. pairs.items.push(pair);
  117. }
  118. } catch (err) {
  119. _iterator.e(err);
  120. } finally {
  121. _iterator.f();
  122. }
  123. return pairs;
  124. }
  125. var pairs = {
  126. default: false,
  127. tag: 'tag:yaml.org,2002:pairs',
  128. resolve: parsePairs,
  129. createNode: createPairs
  130. };
  131. var YAMLOMap = /*#__PURE__*/function (_YAMLSeq) {
  132. _inherits(YAMLOMap, _YAMLSeq);
  133. var _super = _createSuper(YAMLOMap);
  134. function YAMLOMap() {
  135. var _this;
  136. _classCallCheck(this, YAMLOMap);
  137. _this = _super.call(this);
  138. _defineProperty(_assertThisInitialized(_this), "add", YAMLMap.prototype.add.bind(_assertThisInitialized(_this)));
  139. _defineProperty(_assertThisInitialized(_this), "delete", YAMLMap.prototype.delete.bind(_assertThisInitialized(_this)));
  140. _defineProperty(_assertThisInitialized(_this), "get", YAMLMap.prototype.get.bind(_assertThisInitialized(_this)));
  141. _defineProperty(_assertThisInitialized(_this), "has", YAMLMap.prototype.has.bind(_assertThisInitialized(_this)));
  142. _defineProperty(_assertThisInitialized(_this), "set", YAMLMap.prototype.set.bind(_assertThisInitialized(_this)));
  143. _this.tag = YAMLOMap.tag;
  144. return _this;
  145. }
  146. _createClass(YAMLOMap, [{
  147. key: "toJSON",
  148. value: function toJSON$1(_, ctx) {
  149. var map = new Map();
  150. if (ctx && ctx.onCreate) ctx.onCreate(map);
  151. var _iterator = _createForOfIteratorHelper(this.items),
  152. _step;
  153. try {
  154. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  155. var pair = _step.value;
  156. var key = void 0,
  157. value = void 0;
  158. if (pair instanceof Pair) {
  159. key = toJSON(pair.key, '', ctx);
  160. value = toJSON(pair.value, key, ctx);
  161. } else {
  162. key = toJSON(pair, '', ctx);
  163. }
  164. if (map.has(key)) throw new Error('Ordered maps must not include duplicate keys');
  165. map.set(key, value);
  166. }
  167. } catch (err) {
  168. _iterator.e(err);
  169. } finally {
  170. _iterator.f();
  171. }
  172. return map;
  173. }
  174. }]);
  175. return YAMLOMap;
  176. }(YAMLSeq);
  177. _defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap');
  178. function parseOMap(doc, cst) {
  179. var pairs = parsePairs(doc, cst);
  180. var seenKeys = [];
  181. var _iterator2 = _createForOfIteratorHelper(pairs.items),
  182. _step2;
  183. try {
  184. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  185. var key = _step2.value.key;
  186. if (key instanceof Scalar) {
  187. if (seenKeys.includes(key.value)) {
  188. var msg = 'Ordered maps must not include duplicate keys';
  189. throw new YAMLSemanticError(cst, msg);
  190. } else {
  191. seenKeys.push(key.value);
  192. }
  193. }
  194. }
  195. } catch (err) {
  196. _iterator2.e(err);
  197. } finally {
  198. _iterator2.f();
  199. }
  200. return Object.assign(new YAMLOMap(), pairs);
  201. }
  202. function createOMap(schema, iterable, ctx) {
  203. var pairs = createPairs(schema, iterable, ctx);
  204. var omap = new YAMLOMap();
  205. omap.items = pairs.items;
  206. return omap;
  207. }
  208. var omap = {
  209. identify: function identify(value) {
  210. return value instanceof Map;
  211. },
  212. nodeClass: YAMLOMap,
  213. default: false,
  214. tag: 'tag:yaml.org,2002:omap',
  215. resolve: parseOMap,
  216. createNode: createOMap
  217. };
  218. var YAMLSet = /*#__PURE__*/function (_YAMLMap) {
  219. _inherits(YAMLSet, _YAMLMap);
  220. var _super = _createSuper(YAMLSet);
  221. function YAMLSet() {
  222. var _this;
  223. _classCallCheck(this, YAMLSet);
  224. _this = _super.call(this);
  225. _this.tag = YAMLSet.tag;
  226. return _this;
  227. }
  228. _createClass(YAMLSet, [{
  229. key: "add",
  230. value: function add(key) {
  231. var pair = key instanceof Pair ? key : new Pair(key);
  232. var prev = findPair(this.items, pair.key);
  233. if (!prev) this.items.push(pair);
  234. }
  235. }, {
  236. key: "get",
  237. value: function get(key, keepPair) {
  238. var pair = findPair(this.items, key);
  239. return !keepPair && pair instanceof Pair ? pair.key instanceof Scalar ? pair.key.value : pair.key : pair;
  240. }
  241. }, {
  242. key: "set",
  243. value: function set(key, value) {
  244. if (typeof value !== 'boolean') throw new Error("Expected boolean value for set(key, value) in a YAML set, not ".concat(_typeof(value)));
  245. var prev = findPair(this.items, key);
  246. if (prev && !value) {
  247. this.items.splice(this.items.indexOf(prev), 1);
  248. } else if (!prev && value) {
  249. this.items.push(new Pair(key));
  250. }
  251. }
  252. }, {
  253. key: "toJSON",
  254. value: function toJSON(_, ctx) {
  255. return _get(_getPrototypeOf(YAMLSet.prototype), "toJSON", this).call(this, _, ctx, Set);
  256. }
  257. }, {
  258. key: "toString",
  259. value: function toString(ctx, onComment, onChompKeep) {
  260. if (!ctx) return JSON.stringify(this);
  261. 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');
  262. }
  263. }]);
  264. return YAMLSet;
  265. }(YAMLMap);
  266. _defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set');
  267. function parseSet(doc, cst) {
  268. var map = resolveMap(doc, cst);
  269. if (!map.hasAllNullValues()) throw new YAMLSemanticError(cst, 'Set items must all have null values');
  270. return Object.assign(new YAMLSet(), map);
  271. }
  272. function createSet(schema, iterable, ctx) {
  273. var set = new YAMLSet();
  274. var _iterator = _createForOfIteratorHelper(iterable),
  275. _step;
  276. try {
  277. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  278. var value = _step.value;
  279. set.items.push(schema.createPair(value, null, ctx));
  280. }
  281. } catch (err) {
  282. _iterator.e(err);
  283. } finally {
  284. _iterator.f();
  285. }
  286. return set;
  287. }
  288. var set = {
  289. identify: function identify(value) {
  290. return value instanceof Set;
  291. },
  292. nodeClass: YAMLSet,
  293. default: false,
  294. tag: 'tag:yaml.org,2002:set',
  295. resolve: parseSet,
  296. createNode: createSet
  297. };
  298. var parseSexagesimal = function parseSexagesimal(sign, parts) {
  299. var n = parts.split(':').reduce(function (n, p) {
  300. return n * 60 + Number(p);
  301. }, 0);
  302. return sign === '-' ? -n : n;
  303. }; // hhhh:mm:ss.sss
  304. var stringifySexagesimal = function stringifySexagesimal(_ref) {
  305. var value = _ref.value;
  306. if (isNaN(value) || !isFinite(value)) return stringifyNumber(value);
  307. var sign = '';
  308. if (value < 0) {
  309. sign = '-';
  310. value = Math.abs(value);
  311. }
  312. var parts = [value % 60]; // seconds, including ms
  313. if (value < 60) {
  314. parts.unshift(0); // at least one : is required
  315. } else {
  316. value = Math.round((value - parts[0]) / 60);
  317. parts.unshift(value % 60); // minutes
  318. if (value >= 60) {
  319. value = Math.round((value - parts[0]) / 60);
  320. parts.unshift(value); // hours
  321. }
  322. }
  323. return sign + parts.map(function (n) {
  324. return n < 10 ? '0' + String(n) : String(n);
  325. }).join(':').replace(/000000\d*$/, '') // % 60 may introduce error
  326. ;
  327. };
  328. var intTime = {
  329. identify: function identify(value) {
  330. return typeof value === 'number';
  331. },
  332. default: true,
  333. tag: 'tag:yaml.org,2002:int',
  334. format: 'TIME',
  335. test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+)$/,
  336. resolve: function resolve(str, sign, parts) {
  337. return parseSexagesimal(sign, parts.replace(/_/g, ''));
  338. },
  339. stringify: stringifySexagesimal
  340. };
  341. var floatTime = {
  342. identify: function identify(value) {
  343. return typeof value === 'number';
  344. },
  345. default: true,
  346. tag: 'tag:yaml.org,2002:float',
  347. format: 'TIME',
  348. test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*)$/,
  349. resolve: function resolve(str, sign, parts) {
  350. return parseSexagesimal(sign, parts.replace(/_/g, ''));
  351. },
  352. stringify: stringifySexagesimal
  353. };
  354. var timestamp = {
  355. identify: function identify(value) {
  356. return value instanceof Date;
  357. },
  358. default: true,
  359. tag: 'tag:yaml.org,2002:timestamp',
  360. // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
  361. // may be omitted altogether, resulting in a date format. In such a case, the time part is
  362. // assumed to be 00:00:00Z (start of day, UTC).
  363. test: RegExp('^(?:' + '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd
  364. '(?:(?:t|T|[ \\t]+)' + // t | T | whitespace
  365. '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)?
  366. '(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30
  367. ')?' + ')$'),
  368. resolve: function resolve(str, year, month, day, hour, minute, second, millisec, tz) {
  369. if (millisec) millisec = (millisec + '00').substr(1, 3);
  370. var date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0);
  371. if (tz && tz !== 'Z') {
  372. var d = parseSexagesimal(tz[0], tz.slice(1));
  373. if (Math.abs(d) < 30) d *= 60;
  374. date -= 60000 * d;
  375. }
  376. return new Date(date);
  377. },
  378. stringify: function stringify(_ref2) {
  379. var value = _ref2.value;
  380. return value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '');
  381. }
  382. };
  383. /* global console, process, YAML_SILENCE_DEPRECATION_WARNINGS, YAML_SILENCE_WARNINGS */
  384. function shouldWarn(deprecation) {
  385. var env = typeof process !== 'undefined' && process.env || {};
  386. if (deprecation) {
  387. if (typeof YAML_SILENCE_DEPRECATION_WARNINGS !== 'undefined') return !YAML_SILENCE_DEPRECATION_WARNINGS;
  388. return !env.YAML_SILENCE_DEPRECATION_WARNINGS;
  389. }
  390. if (typeof YAML_SILENCE_WARNINGS !== 'undefined') return !YAML_SILENCE_WARNINGS;
  391. return !env.YAML_SILENCE_WARNINGS;
  392. }
  393. function warn(warning, type) {
  394. if (shouldWarn(false)) {
  395. var emit = typeof process !== 'undefined' && process.emitWarning; // This will throw in Jest if `warning` is an Error instance due to
  396. // https://github.com/facebook/jest/issues/2549
  397. if (emit) emit(warning, type);else {
  398. // eslint-disable-next-line no-console
  399. console.warn(type ? "".concat(type, ": ").concat(warning) : warning);
  400. }
  401. }
  402. }
  403. function warnFileDeprecation(filename) {
  404. if (shouldWarn(true)) {
  405. var path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/');
  406. warn("The endpoint 'yaml/".concat(path, "' will be removed in a future release."), 'DeprecationWarning');
  407. }
  408. }
  409. var warned = {};
  410. function warnOptionDeprecation(name, alternative) {
  411. if (!warned[name] && shouldWarn(true)) {
  412. warned[name] = true;
  413. var msg = "The option '".concat(name, "' will be removed in a future release");
  414. msg += alternative ? ", use '".concat(alternative, "' instead.") : '.';
  415. warn(msg, 'DeprecationWarning');
  416. }
  417. }
  418. export { warnOptionDeprecation as a, binary as b, warnFileDeprecation as c, floatTime as f, intTime as i, omap as o, pairs as p, set as s, timestamp as t, warn as w };