Schema-ea978338.js 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  1. import { l as _inherits, m as _createSuper, b as _classCallCheck, r as _possibleConstructorReturn, a as _createClass, h as _createForOfIteratorHelper, e as _slicedToArray, n as _get, o as _getPrototypeOf, _ as _typeof, T as Type, c as _defineProperty, p as _assertThisInitialized } from './errors-2634d01a.js';
  2. import { P as Pair, Y as YAMLSeq, S as Scalar, d as YAMLMap, j as createPair, e as createNode, c as stringifyString, s as strOptions, n as nullOptions, a as boolOptions, i as intOptions, k as stringifyNumber, b as binaryOptions, t as toJS, l as findPair } from './stringifyNumber-d8af95b1.js';
  3. var MERGE_KEY = '<<';
  4. var Merge = /*#__PURE__*/function (_Pair) {
  5. _inherits(Merge, _Pair);
  6. var _super = _createSuper(Merge);
  7. function Merge(pair) {
  8. var _this;
  9. _classCallCheck(this, Merge);
  10. if (pair instanceof Pair) {
  11. var seq = pair.value;
  12. if (!(seq instanceof YAMLSeq)) {
  13. seq = new YAMLSeq();
  14. seq.items.push(pair.value);
  15. seq.range = pair.value.range;
  16. }
  17. _this = _super.call(this, pair.key, seq);
  18. _this.range = pair.range;
  19. } else {
  20. _this = _super.call(this, new Scalar(MERGE_KEY), new YAMLSeq());
  21. }
  22. _this.type = Pair.Type.MERGE_PAIR;
  23. return _possibleConstructorReturn(_this);
  24. } // If the value associated with a merge key is a single mapping node, each of
  25. // its key/value pairs is inserted into the current mapping, unless the key
  26. // already exists in it. If the value associated with the merge key is a
  27. // sequence, then this sequence is expected to contain mapping nodes and each
  28. // of these nodes is merged in turn according to its order in the sequence.
  29. // Keys in mapping nodes earlier in the sequence override keys specified in
  30. // later mapping nodes. -- http://yaml.org/type/merge.html
  31. _createClass(Merge, [{
  32. key: "addToJSMap",
  33. value: function addToJSMap(ctx, map) {
  34. var _iterator = _createForOfIteratorHelper(this.value.items),
  35. _step;
  36. try {
  37. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  38. var source = _step.value.source;
  39. if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps');
  40. var srcMap = source.toJSON(null, ctx, Map);
  41. var _iterator2 = _createForOfIteratorHelper(srcMap),
  42. _step2;
  43. try {
  44. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  45. var _step2$value = _slicedToArray(_step2.value, 2),
  46. key = _step2$value[0],
  47. value = _step2$value[1];
  48. if (map instanceof Map) {
  49. if (!map.has(key)) map.set(key, value);
  50. } else if (map instanceof Set) {
  51. map.add(key);
  52. } else if (!Object.prototype.hasOwnProperty.call(map, key)) {
  53. Object.defineProperty(map, key, {
  54. value: value,
  55. writable: true,
  56. enumerable: true,
  57. configurable: true
  58. });
  59. }
  60. }
  61. } catch (err) {
  62. _iterator2.e(err);
  63. } finally {
  64. _iterator2.f();
  65. }
  66. }
  67. } catch (err) {
  68. _iterator.e(err);
  69. } finally {
  70. _iterator.f();
  71. }
  72. return map;
  73. }
  74. }, {
  75. key: "toString",
  76. value: function toString(ctx, onComment) {
  77. var seq = this.value;
  78. if (seq.items.length > 1) return _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
  79. this.value = seq.items[0];
  80. var str = _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
  81. this.value = seq;
  82. return str;
  83. }
  84. }]);
  85. return Merge;
  86. }(Pair);
  87. function createMap(schema, obj, ctx) {
  88. var keepUndefined = ctx.keepUndefined,
  89. replacer = ctx.replacer;
  90. var map = new YAMLMap(schema);
  91. var add = function add(key, value) {
  92. if (typeof replacer === 'function') value = replacer.call(obj, key, value);else if (Array.isArray(replacer) && !replacer.includes(key)) return;
  93. if (value !== undefined || keepUndefined) map.items.push(createPair(key, value, ctx));
  94. };
  95. if (obj instanceof Map) {
  96. var _iterator = _createForOfIteratorHelper(obj),
  97. _step;
  98. try {
  99. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  100. var _step$value = _slicedToArray(_step.value, 2),
  101. key = _step$value[0],
  102. value = _step$value[1];
  103. add(key, value);
  104. }
  105. } catch (err) {
  106. _iterator.e(err);
  107. } finally {
  108. _iterator.f();
  109. }
  110. } else if (obj && _typeof(obj) === 'object') {
  111. for (var _i = 0, _Object$keys = Object.keys(obj); _i < _Object$keys.length; _i++) {
  112. var _key = _Object$keys[_i];
  113. add(_key, obj[_key]);
  114. }
  115. }
  116. if (typeof schema.sortMapEntries === 'function') {
  117. map.items.sort(schema.sortMapEntries);
  118. }
  119. return map;
  120. }
  121. var map = {
  122. createNode: createMap,
  123. default: true,
  124. nodeClass: YAMLMap,
  125. tag: 'tag:yaml.org,2002:map',
  126. resolve: function resolve(map) {
  127. return map;
  128. }
  129. };
  130. function createSeq(schema, obj, ctx) {
  131. var replacer = ctx.replacer;
  132. var seq = new YAMLSeq(schema);
  133. if (obj && obj[Symbol.iterator]) {
  134. var i = 0;
  135. var _iterator = _createForOfIteratorHelper(obj),
  136. _step;
  137. try {
  138. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  139. var it = _step.value;
  140. if (typeof replacer === 'function') {
  141. var key = obj instanceof Set ? it : String(i++);
  142. it = replacer.call(obj, key, it);
  143. }
  144. seq.items.push(createNode(it, null, ctx));
  145. }
  146. } catch (err) {
  147. _iterator.e(err);
  148. } finally {
  149. _iterator.f();
  150. }
  151. }
  152. return seq;
  153. }
  154. var seq = {
  155. createNode: createSeq,
  156. default: true,
  157. nodeClass: YAMLSeq,
  158. tag: 'tag:yaml.org,2002:seq',
  159. resolve: function resolve(seq) {
  160. return seq;
  161. }
  162. };
  163. var string = {
  164. identify: function identify(value) {
  165. return typeof value === 'string';
  166. },
  167. default: true,
  168. tag: 'tag:yaml.org,2002:str',
  169. resolve: function resolve(str) {
  170. return str;
  171. },
  172. stringify: function stringify(item, ctx, onComment, onChompKeep) {
  173. ctx = Object.assign({
  174. actualString: true
  175. }, ctx);
  176. return stringifyString(item, ctx, onComment, onChompKeep);
  177. },
  178. options: strOptions
  179. };
  180. var failsafe = [map, seq, string];
  181. /* global BigInt */
  182. var intIdentify = function intIdentify(value) {
  183. return typeof value === 'bigint' || Number.isInteger(value);
  184. };
  185. var intResolve = function intResolve(src, offset, radix) {
  186. return intOptions.asBigInt ? BigInt(src) : parseInt(src.substring(offset), radix);
  187. };
  188. function intStringify(node, radix, prefix) {
  189. var value = node.value;
  190. if (intIdentify(value) && value >= 0) return prefix + value.toString(radix);
  191. return stringifyNumber(node);
  192. }
  193. var nullObj = {
  194. identify: function identify(value) {
  195. return value == null;
  196. },
  197. createNode: function createNode(schema, value, ctx) {
  198. return ctx.wrapScalars ? new Scalar(null) : null;
  199. },
  200. default: true,
  201. tag: 'tag:yaml.org,2002:null',
  202. test: /^(?:~|[Nn]ull|NULL)?$/,
  203. resolve: function resolve(str) {
  204. var node = new Scalar(null);
  205. node.sourceStr = str;
  206. return node;
  207. },
  208. options: nullOptions,
  209. stringify: function stringify(_ref) {
  210. var sourceStr = _ref.sourceStr;
  211. return sourceStr !== null && sourceStr !== void 0 ? sourceStr : nullOptions.nullStr;
  212. }
  213. };
  214. var boolObj = {
  215. identify: function identify(value) {
  216. return typeof value === 'boolean';
  217. },
  218. default: true,
  219. tag: 'tag:yaml.org,2002:bool',
  220. test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
  221. resolve: function resolve(str) {
  222. return str[0] === 't' || str[0] === 'T';
  223. },
  224. options: boolOptions,
  225. stringify: function stringify(_ref2) {
  226. var value = _ref2.value;
  227. return value ? boolOptions.trueStr : boolOptions.falseStr;
  228. }
  229. };
  230. var octObj = {
  231. identify: function identify(value) {
  232. return intIdentify(value) && value >= 0;
  233. },
  234. default: true,
  235. tag: 'tag:yaml.org,2002:int',
  236. format: 'OCT',
  237. test: /^0o[0-7]+$/,
  238. resolve: function resolve(str) {
  239. return intResolve(str, 2, 8);
  240. },
  241. options: intOptions,
  242. stringify: function stringify(node) {
  243. return intStringify(node, 8, '0o');
  244. }
  245. };
  246. var intObj = {
  247. identify: intIdentify,
  248. default: true,
  249. tag: 'tag:yaml.org,2002:int',
  250. test: /^[-+]?[0-9]+$/,
  251. resolve: function resolve(str) {
  252. return intResolve(str, 0, 10);
  253. },
  254. options: intOptions,
  255. stringify: stringifyNumber
  256. };
  257. var hexObj = {
  258. identify: function identify(value) {
  259. return intIdentify(value) && value >= 0;
  260. },
  261. default: true,
  262. tag: 'tag:yaml.org,2002:int',
  263. format: 'HEX',
  264. test: /^0x[0-9a-fA-F]+$/,
  265. resolve: function resolve(str) {
  266. return intResolve(str, 2, 16);
  267. },
  268. options: intOptions,
  269. stringify: function stringify(node) {
  270. return intStringify(node, 16, '0x');
  271. }
  272. };
  273. var nanObj = {
  274. identify: function identify(value) {
  275. return typeof value === 'number';
  276. },
  277. default: true,
  278. tag: 'tag:yaml.org,2002:float',
  279. test: /^(?:[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN))$/,
  280. resolve: function resolve(str) {
  281. return str.slice(-3).toLowerCase() === 'nan' ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY;
  282. },
  283. stringify: stringifyNumber
  284. };
  285. var expObj = {
  286. identify: function identify(value) {
  287. return typeof value === 'number';
  288. },
  289. default: true,
  290. tag: 'tag:yaml.org,2002:float',
  291. format: 'EXP',
  292. test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
  293. resolve: function resolve(str) {
  294. return parseFloat(str);
  295. },
  296. stringify: function stringify(_ref3) {
  297. var value = _ref3.value;
  298. return Number(value).toExponential();
  299. }
  300. };
  301. var floatObj = {
  302. identify: function identify(value) {
  303. return typeof value === 'number';
  304. },
  305. default: true,
  306. tag: 'tag:yaml.org,2002:float',
  307. test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
  308. resolve: function resolve(str) {
  309. var node = new Scalar(parseFloat(str));
  310. var dot = str.indexOf('.');
  311. if (dot !== -1 && str[str.length - 1] === '0') node.minFractionDigits = str.length - dot - 1;
  312. return node;
  313. },
  314. stringify: stringifyNumber
  315. };
  316. var core = failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
  317. /* global BigInt */
  318. var intIdentify$1 = function intIdentify(value) {
  319. return typeof value === 'bigint' || Number.isInteger(value);
  320. };
  321. var stringifyJSON = function stringifyJSON(_ref) {
  322. var value = _ref.value;
  323. return JSON.stringify(value);
  324. };
  325. var json = [map, seq, {
  326. identify: function identify(value) {
  327. return typeof value === 'string';
  328. },
  329. default: true,
  330. tag: 'tag:yaml.org,2002:str',
  331. resolve: function resolve(str) {
  332. return str;
  333. },
  334. stringify: stringifyJSON
  335. }, {
  336. identify: function identify(value) {
  337. return value == null;
  338. },
  339. createNode: function createNode(schema, value, ctx) {
  340. return ctx.wrapScalars ? new Scalar(null) : null;
  341. },
  342. default: true,
  343. tag: 'tag:yaml.org,2002:null',
  344. test: /^null$/,
  345. resolve: function resolve() {
  346. return null;
  347. },
  348. stringify: stringifyJSON
  349. }, {
  350. identify: function identify(value) {
  351. return typeof value === 'boolean';
  352. },
  353. default: true,
  354. tag: 'tag:yaml.org,2002:bool',
  355. test: /^true|false$/,
  356. resolve: function resolve(str) {
  357. return str === 'true';
  358. },
  359. stringify: stringifyJSON
  360. }, {
  361. identify: intIdentify$1,
  362. default: true,
  363. tag: 'tag:yaml.org,2002:int',
  364. test: /^-?(?:0|[1-9][0-9]*)$/,
  365. resolve: function resolve(str) {
  366. return intOptions.asBigInt ? BigInt(str) : parseInt(str, 10);
  367. },
  368. stringify: function stringify(_ref2) {
  369. var value = _ref2.value;
  370. return intIdentify$1(value) ? value.toString() : JSON.stringify(value);
  371. }
  372. }, {
  373. identify: function identify(value) {
  374. return typeof value === 'number';
  375. },
  376. default: true,
  377. tag: 'tag:yaml.org,2002:float',
  378. test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
  379. resolve: function resolve(str) {
  380. return parseFloat(str);
  381. },
  382. stringify: stringifyJSON
  383. }, {
  384. default: true,
  385. test: /^/,
  386. resolve: function resolve(str, onError) {
  387. onError("Unresolved plain scalar ".concat(JSON.stringify(str)));
  388. return str;
  389. }
  390. }];
  391. /* global atob, btoa, Buffer */
  392. var binary = {
  393. identify: function identify(value) {
  394. return value instanceof Uint8Array;
  395. },
  396. // Buffer inherits from Uint8Array
  397. default: false,
  398. tag: 'tag:yaml.org,2002:binary',
  399. /**
  400. * Returns a Buffer in node and an Uint8Array in browsers
  401. *
  402. * To use the resulting buffer as an image, you'll want to do something like:
  403. *
  404. * const blob = new Blob([buffer], { type: 'image/jpeg' })
  405. * document.querySelector('#photo').src = URL.createObjectURL(blob)
  406. */
  407. resolve: function resolve(src, onError) {
  408. if (typeof Buffer === 'function') {
  409. return Buffer.from(src, 'base64');
  410. } else if (typeof atob === 'function') {
  411. // On IE 11, atob() can't handle newlines
  412. var str = atob(src.replace(/[\n\r]/g, ''));
  413. var buffer = new Uint8Array(str.length);
  414. for (var i = 0; i < str.length; ++i) {
  415. buffer[i] = str.charCodeAt(i);
  416. }
  417. return buffer;
  418. } else {
  419. onError('This environment does not support reading binary tags; either Buffer or atob is required');
  420. return src;
  421. }
  422. },
  423. options: binaryOptions,
  424. stringify: function stringify(_ref, ctx, onComment, onChompKeep) {
  425. var comment = _ref.comment,
  426. type = _ref.type,
  427. value = _ref.value;
  428. var src;
  429. if (typeof Buffer === 'function') {
  430. src = value instanceof Buffer ? value.toString('base64') : Buffer.from(value.buffer).toString('base64');
  431. } else if (typeof btoa === 'function') {
  432. var s = '';
  433. for (var i = 0; i < value.length; ++i) {
  434. s += String.fromCharCode(value[i]);
  435. }
  436. src = btoa(s);
  437. } else {
  438. throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');
  439. }
  440. if (!type) type = binaryOptions.defaultType;
  441. if (type === Type.QUOTE_DOUBLE) {
  442. value = src;
  443. } else {
  444. var lineWidth = binaryOptions.lineWidth;
  445. var n = Math.ceil(src.length / lineWidth);
  446. var lines = new Array(n);
  447. for (var _i = 0, o = 0; _i < n; ++_i, o += lineWidth) {
  448. lines[_i] = src.substr(o, lineWidth);
  449. }
  450. value = lines.join(type === Type.BLOCK_LITERAL ? '\n' : ' ');
  451. }
  452. return stringifyString({
  453. comment: comment,
  454. type: type,
  455. value: value
  456. }, ctx, onComment, onChompKeep);
  457. }
  458. };
  459. function parsePairs(seq, onError) {
  460. if (seq instanceof YAMLSeq) {
  461. for (var i = 0; i < seq.items.length; ++i) {
  462. var item = seq.items[i];
  463. if (item instanceof Pair) continue;else if (item instanceof YAMLMap) {
  464. if (item.items.length > 1) onError('Each pair must have its own sequence indicator');
  465. var pair = item.items[0] || new Pair();
  466. if (item.commentBefore) pair.commentBefore = pair.commentBefore ? "".concat(item.commentBefore, "\n").concat(pair.commentBefore) : item.commentBefore;
  467. if (item.comment) pair.comment = pair.comment ? "".concat(item.comment, "\n").concat(pair.comment) : item.comment;
  468. item = pair;
  469. }
  470. seq.items[i] = item instanceof Pair ? item : new Pair(item);
  471. }
  472. } else onError('Expected a sequence for this tag');
  473. return seq;
  474. }
  475. function createPairs(schema, iterable, ctx) {
  476. var replacer = ctx.replacer;
  477. var pairs = new YAMLSeq(schema);
  478. pairs.tag = 'tag:yaml.org,2002:pairs';
  479. var i = 0;
  480. var _iterator = _createForOfIteratorHelper(iterable),
  481. _step;
  482. try {
  483. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  484. var it = _step.value;
  485. if (typeof replacer === 'function') it = replacer.call(iterable, String(i++), it);
  486. var key = void 0,
  487. value = void 0;
  488. if (Array.isArray(it)) {
  489. if (it.length === 2) {
  490. key = it[0];
  491. value = it[1];
  492. } else throw new TypeError("Expected [key, value] tuple: ".concat(it));
  493. } else if (it && it instanceof Object) {
  494. var keys = Object.keys(it);
  495. if (keys.length === 1) {
  496. key = keys[0];
  497. value = it[key];
  498. } else throw new TypeError("Expected { key: value } tuple: ".concat(it));
  499. } else {
  500. key = it;
  501. }
  502. pairs.items.push(createPair(key, value, ctx));
  503. }
  504. } catch (err) {
  505. _iterator.e(err);
  506. } finally {
  507. _iterator.f();
  508. }
  509. return pairs;
  510. }
  511. var pairs = {
  512. default: false,
  513. tag: 'tag:yaml.org,2002:pairs',
  514. resolve: parsePairs,
  515. createNode: createPairs
  516. };
  517. var YAMLOMap = /*#__PURE__*/function (_YAMLSeq) {
  518. _inherits(YAMLOMap, _YAMLSeq);
  519. var _super = _createSuper(YAMLOMap);
  520. function YAMLOMap() {
  521. var _this;
  522. _classCallCheck(this, YAMLOMap);
  523. _this = _super.call(this);
  524. _defineProperty(_assertThisInitialized(_this), "add", YAMLMap.prototype.add.bind(_assertThisInitialized(_this)));
  525. _defineProperty(_assertThisInitialized(_this), "delete", YAMLMap.prototype.delete.bind(_assertThisInitialized(_this)));
  526. _defineProperty(_assertThisInitialized(_this), "get", YAMLMap.prototype.get.bind(_assertThisInitialized(_this)));
  527. _defineProperty(_assertThisInitialized(_this), "has", YAMLMap.prototype.has.bind(_assertThisInitialized(_this)));
  528. _defineProperty(_assertThisInitialized(_this), "set", YAMLMap.prototype.set.bind(_assertThisInitialized(_this)));
  529. _this.tag = YAMLOMap.tag;
  530. return _this;
  531. }
  532. _createClass(YAMLOMap, [{
  533. key: "toJSON",
  534. value: function toJSON(_, ctx) {
  535. var map = new Map();
  536. if (ctx && ctx.onCreate) ctx.onCreate(map);
  537. var _iterator = _createForOfIteratorHelper(this.items),
  538. _step;
  539. try {
  540. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  541. var pair = _step.value;
  542. var key = void 0,
  543. value = void 0;
  544. if (pair instanceof Pair) {
  545. key = toJS(pair.key, '', ctx);
  546. value = toJS(pair.value, key, ctx);
  547. } else {
  548. key = toJS(pair, '', ctx);
  549. }
  550. if (map.has(key)) throw new Error('Ordered maps must not include duplicate keys');
  551. map.set(key, value);
  552. }
  553. } catch (err) {
  554. _iterator.e(err);
  555. } finally {
  556. _iterator.f();
  557. }
  558. return map;
  559. }
  560. }]);
  561. return YAMLOMap;
  562. }(YAMLSeq);
  563. _defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap');
  564. function parseOMap(seq, onError) {
  565. var pairs = parsePairs(seq, onError);
  566. var seenKeys = [];
  567. var _iterator2 = _createForOfIteratorHelper(pairs.items),
  568. _step2;
  569. try {
  570. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  571. var key = _step2.value.key;
  572. if (key instanceof Scalar) {
  573. if (seenKeys.includes(key.value)) {
  574. onError("Ordered maps must not include duplicate keys: ".concat(key.value));
  575. } else {
  576. seenKeys.push(key.value);
  577. }
  578. }
  579. }
  580. } catch (err) {
  581. _iterator2.e(err);
  582. } finally {
  583. _iterator2.f();
  584. }
  585. return Object.assign(new YAMLOMap(), pairs);
  586. }
  587. function createOMap(schema, iterable, ctx) {
  588. var pairs = createPairs(schema, iterable, ctx);
  589. var omap = new YAMLOMap();
  590. omap.items = pairs.items;
  591. return omap;
  592. }
  593. var omap = {
  594. identify: function identify(value) {
  595. return value instanceof Map;
  596. },
  597. nodeClass: YAMLOMap,
  598. default: false,
  599. tag: 'tag:yaml.org,2002:omap',
  600. resolve: parseOMap,
  601. createNode: createOMap
  602. };
  603. var YAMLSet = /*#__PURE__*/function (_YAMLMap) {
  604. _inherits(YAMLSet, _YAMLMap);
  605. var _super = _createSuper(YAMLSet);
  606. function YAMLSet(schema) {
  607. var _this;
  608. _classCallCheck(this, YAMLSet);
  609. _this = _super.call(this, schema);
  610. _this.tag = YAMLSet.tag;
  611. return _this;
  612. }
  613. _createClass(YAMLSet, [{
  614. key: "add",
  615. value: function add(key) {
  616. var pair = key instanceof Pair ? key : new Pair(key);
  617. var prev = findPair(this.items, pair.key);
  618. if (!prev) this.items.push(pair);
  619. }
  620. }, {
  621. key: "get",
  622. value: function get(key, keepPair) {
  623. var pair = findPair(this.items, key);
  624. return !keepPair && pair instanceof Pair ? pair.key instanceof Scalar ? pair.key.value : pair.key : pair;
  625. }
  626. }, {
  627. key: "set",
  628. value: function set(key, value) {
  629. if (typeof value !== 'boolean') throw new Error("Expected boolean value for set(key, value) in a YAML set, not ".concat(_typeof(value)));
  630. var prev = findPair(this.items, key);
  631. if (prev && !value) {
  632. this.items.splice(this.items.indexOf(prev), 1);
  633. } else if (!prev && value) {
  634. this.items.push(new Pair(key));
  635. }
  636. }
  637. }, {
  638. key: "toJSON",
  639. value: function toJSON(_, ctx) {
  640. return _get(_getPrototypeOf(YAMLSet.prototype), "toJSON", this).call(this, _, ctx, Set);
  641. }
  642. }, {
  643. key: "toString",
  644. value: function toString(ctx, onComment, onChompKeep) {
  645. if (!ctx) return JSON.stringify(this);
  646. 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');
  647. }
  648. }]);
  649. return YAMLSet;
  650. }(YAMLMap);
  651. _defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set');
  652. function parseSet(map, onError) {
  653. if (map instanceof YAMLMap) {
  654. if (map.hasAllNullValues()) return Object.assign(new YAMLSet(), map);else onError('Set items must all have null values');
  655. } else onError('Expected a mapping for this tag');
  656. return map;
  657. }
  658. function createSet(schema, iterable, ctx) {
  659. var replacer = ctx.replacer;
  660. var set = new YAMLSet(schema);
  661. var _iterator = _createForOfIteratorHelper(iterable),
  662. _step;
  663. try {
  664. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  665. var value = _step.value;
  666. if (typeof replacer === 'function') value = replacer.call(iterable, value, value);
  667. set.items.push(createPair(value, null, ctx));
  668. }
  669. } catch (err) {
  670. _iterator.e(err);
  671. } finally {
  672. _iterator.f();
  673. }
  674. return set;
  675. }
  676. var set = {
  677. identify: function identify(value) {
  678. return value instanceof Set;
  679. },
  680. nodeClass: YAMLSet,
  681. default: false,
  682. tag: 'tag:yaml.org,2002:set',
  683. resolve: parseSet,
  684. createNode: createSet
  685. };
  686. var parseSexagesimal = function parseSexagesimal(str, isInt) {
  687. var sign = str[0];
  688. var parts = sign === '-' || sign === '+' ? str.substring(1) : str;
  689. var num = function num(n) {
  690. return isInt && intOptions.asBigInt ? BigInt(n) : Number(n);
  691. };
  692. var res = parts.replace(/_/g, '').split(':').reduce(function (res, p) {
  693. return res * num(60) + num(p);
  694. }, num(0));
  695. return sign === '-' ? num(-1) * res : res;
  696. }; // hhhh:mm:ss.sss
  697. var stringifySexagesimal = function stringifySexagesimal(_ref) {
  698. var value = _ref.value;
  699. var num = function num(n) {
  700. return n;
  701. };
  702. if (typeof value === 'bigint') num = function num(n) {
  703. return BigInt(n);
  704. };else if (isNaN(value) || !isFinite(value)) return stringifyNumber(value);
  705. var sign = '';
  706. if (value < 0) {
  707. sign = '-';
  708. value *= num(-1);
  709. }
  710. var _60 = num(60);
  711. var parts = [value % _60]; // seconds, including ms
  712. if (value < 60) {
  713. parts.unshift(0); // at least one : is required
  714. } else {
  715. value = (value - parts[0]) / _60;
  716. parts.unshift(value % _60); // minutes
  717. if (value >= 60) {
  718. value = (value - parts[0]) / _60;
  719. parts.unshift(value); // hours
  720. }
  721. }
  722. return sign + parts.map(function (n) {
  723. return n < 10 ? '0' + String(n) : String(n);
  724. }).join(':').replace(/000000\d*$/, '') // % 60 may introduce error
  725. ;
  726. };
  727. var intTime = {
  728. identify: function identify(value) {
  729. return typeof value === 'bigint' || Number.isInteger(value);
  730. },
  731. default: true,
  732. tag: 'tag:yaml.org,2002:int',
  733. format: 'TIME',
  734. test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,
  735. resolve: function resolve(str) {
  736. return parseSexagesimal(str, true);
  737. },
  738. stringify: stringifySexagesimal
  739. };
  740. var floatTime = {
  741. identify: function identify(value) {
  742. return typeof value === 'number';
  743. },
  744. default: true,
  745. tag: 'tag:yaml.org,2002:float',
  746. format: 'TIME',
  747. test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,
  748. resolve: function resolve(str) {
  749. return parseSexagesimal(str, false);
  750. },
  751. stringify: stringifySexagesimal
  752. };
  753. var timestamp = {
  754. identify: function identify(value) {
  755. return value instanceof Date;
  756. },
  757. default: true,
  758. tag: 'tag:yaml.org,2002:timestamp',
  759. // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
  760. // may be omitted altogether, resulting in a date format. In such a case, the time part is
  761. // assumed to be 00:00:00Z (start of day, UTC).
  762. test: RegExp('^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd
  763. '(?:' + // time is optional
  764. '(?:t|T|[ \\t]+)' + // t | T | whitespace
  765. '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)?
  766. '(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30
  767. ')?$'),
  768. resolve: function resolve(str) {
  769. var _str$match = str.match(timestamp.test),
  770. _str$match2 = _slicedToArray(_str$match, 9),
  771. year = _str$match2[1],
  772. month = _str$match2[2],
  773. day = _str$match2[3],
  774. hour = _str$match2[4],
  775. minute = _str$match2[5],
  776. second = _str$match2[6],
  777. millisec = _str$match2[7],
  778. tz = _str$match2[8];
  779. if (millisec) millisec = (millisec + '00').substr(1, 3);
  780. var date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0);
  781. if (tz && tz !== 'Z') {
  782. var d = parseSexagesimal(tz, false);
  783. if (Math.abs(d) < 30) d *= 60;
  784. date -= 60000 * d;
  785. }
  786. return new Date(date);
  787. },
  788. stringify: function stringify(_ref2) {
  789. var value = _ref2.value;
  790. return value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '');
  791. }
  792. };
  793. /* global BigInt */
  794. var boolStringify = function boolStringify(_ref) {
  795. var value = _ref.value;
  796. return value ? boolOptions.trueStr : boolOptions.falseStr;
  797. };
  798. var intIdentify$2 = function intIdentify(value) {
  799. return typeof value === 'bigint' || Number.isInteger(value);
  800. };
  801. function intResolve$1(str, offset, radix) {
  802. var sign = str[0];
  803. if (sign === '-' || sign === '+') offset += 1;
  804. str = str.substring(offset).replace(/_/g, '');
  805. if (intOptions.asBigInt) {
  806. switch (radix) {
  807. case 2:
  808. str = "0b".concat(str);
  809. break;
  810. case 8:
  811. str = "0o".concat(str);
  812. break;
  813. case 16:
  814. str = "0x".concat(str);
  815. break;
  816. }
  817. var _n = BigInt(str);
  818. return sign === '-' ? BigInt(-1) * _n : _n;
  819. }
  820. var n = parseInt(str, radix);
  821. return sign === '-' ? -1 * n : n;
  822. }
  823. function intStringify$1(node, radix, prefix) {
  824. var value = node.value;
  825. if (intIdentify$2(value)) {
  826. var str = value.toString(radix);
  827. return value < 0 ? '-' + prefix + str.substr(1) : prefix + str;
  828. }
  829. return stringifyNumber(node);
  830. }
  831. var yaml11 = failsafe.concat([{
  832. identify: function identify(value) {
  833. return value == null;
  834. },
  835. createNode: function createNode(schema, value, ctx) {
  836. return ctx.wrapScalars ? new Scalar(null) : null;
  837. },
  838. default: true,
  839. tag: 'tag:yaml.org,2002:null',
  840. test: /^(?:~|[Nn]ull|NULL)?$/,
  841. resolve: function resolve(str) {
  842. var node = new Scalar(null);
  843. node.sourceStr = str;
  844. return node;
  845. },
  846. options: nullOptions,
  847. stringify: function stringify(_ref2) {
  848. var sourceStr = _ref2.sourceStr;
  849. return sourceStr !== null && sourceStr !== void 0 ? sourceStr : nullOptions.nullStr;
  850. }
  851. }, {
  852. identify: function identify(value) {
  853. return typeof value === 'boolean';
  854. },
  855. default: true,
  856. tag: 'tag:yaml.org,2002:bool',
  857. test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
  858. resolve: function resolve() {
  859. return true;
  860. },
  861. options: boolOptions,
  862. stringify: boolStringify
  863. }, {
  864. identify: function identify(value) {
  865. return typeof value === 'boolean';
  866. },
  867. default: true,
  868. tag: 'tag:yaml.org,2002:bool',
  869. test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
  870. resolve: function resolve() {
  871. return false;
  872. },
  873. options: boolOptions,
  874. stringify: boolStringify
  875. }, {
  876. identify: intIdentify$2,
  877. default: true,
  878. tag: 'tag:yaml.org,2002:int',
  879. format: 'BIN',
  880. test: /^[-+]?0b[0-1_]+$/,
  881. resolve: function resolve(str) {
  882. return intResolve$1(str, 2, 2);
  883. },
  884. stringify: function stringify(node) {
  885. return intStringify$1(node, 2, '0b');
  886. }
  887. }, {
  888. identify: intIdentify$2,
  889. default: true,
  890. tag: 'tag:yaml.org,2002:int',
  891. format: 'OCT',
  892. test: /^[-+]?0[0-7_]+$/,
  893. resolve: function resolve(str) {
  894. return intResolve$1(str, 1, 8);
  895. },
  896. stringify: function stringify(node) {
  897. return intStringify$1(node, 8, '0');
  898. }
  899. }, {
  900. identify: intIdentify$2,
  901. default: true,
  902. tag: 'tag:yaml.org,2002:int',
  903. test: /^[-+]?[0-9][0-9_]*$/,
  904. resolve: function resolve(str) {
  905. return intResolve$1(str, 0, 10);
  906. },
  907. stringify: stringifyNumber
  908. }, {
  909. identify: intIdentify$2,
  910. default: true,
  911. tag: 'tag:yaml.org,2002:int',
  912. format: 'HEX',
  913. test: /^[-+]?0x[0-9a-fA-F_]+$/,
  914. resolve: function resolve(str) {
  915. return intResolve$1(str, 2, 16);
  916. },
  917. stringify: function stringify(node) {
  918. return intStringify$1(node, 16, '0x');
  919. }
  920. }, {
  921. identify: function identify(value) {
  922. return typeof value === 'number';
  923. },
  924. default: true,
  925. tag: 'tag:yaml.org,2002:float',
  926. test: /^[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/,
  927. resolve: function resolve(str) {
  928. return str.slice(-3).toLowerCase() === 'nan' ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY;
  929. },
  930. stringify: stringifyNumber
  931. }, {
  932. identify: function identify(value) {
  933. return typeof value === 'number';
  934. },
  935. default: true,
  936. tag: 'tag:yaml.org,2002:float',
  937. format: 'EXP',
  938. test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
  939. resolve: function resolve(str) {
  940. return parseFloat(str.replace(/_/g, ''));
  941. },
  942. stringify: function stringify(_ref3) {
  943. var value = _ref3.value;
  944. return Number(value).toExponential();
  945. }
  946. }, {
  947. identify: function identify(value) {
  948. return typeof value === 'number';
  949. },
  950. default: true,
  951. tag: 'tag:yaml.org,2002:float',
  952. test: /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,
  953. resolve: function resolve(str) {
  954. var node = new Scalar(parseFloat(str.replace(/_/g, '')));
  955. var dot = str.indexOf('.');
  956. if (dot !== -1) {
  957. var f = str.substring(dot + 1).replace(/_/g, '');
  958. if (f[f.length - 1] === '0') node.minFractionDigits = f.length;
  959. }
  960. return node;
  961. },
  962. stringify: stringifyNumber
  963. }], binary, omap, pairs, set, intTime, floatTime, timestamp);
  964. var schemas = {
  965. core: core,
  966. failsafe: failsafe,
  967. json: json,
  968. yaml11: yaml11
  969. };
  970. var tags = {
  971. binary: binary,
  972. bool: boolObj,
  973. float: floatObj,
  974. floatExp: expObj,
  975. floatNaN: nanObj,
  976. floatTime: floatTime,
  977. int: intObj,
  978. intHex: hexObj,
  979. intOct: octObj,
  980. intTime: intTime,
  981. map: map,
  982. null: nullObj,
  983. omap: omap,
  984. pairs: pairs,
  985. seq: seq,
  986. set: set,
  987. timestamp: timestamp
  988. };
  989. function getSchemaTags(schemas, knownTags, customTags, schemaId) {
  990. var tags = schemas[schemaId.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
  991. if (!tags) {
  992. var keys = Object.keys(schemas).map(function (key) {
  993. return JSON.stringify(key);
  994. }).join(', ');
  995. throw new Error("Unknown schema \"".concat(schemaId, "\"; use one of ").concat(keys));
  996. }
  997. if (Array.isArray(customTags)) {
  998. var _iterator = _createForOfIteratorHelper(customTags),
  999. _step;
  1000. try {
  1001. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  1002. var tag = _step.value;
  1003. tags = tags.concat(tag);
  1004. }
  1005. } catch (err) {
  1006. _iterator.e(err);
  1007. } finally {
  1008. _iterator.f();
  1009. }
  1010. } else if (typeof customTags === 'function') {
  1011. tags = customTags(tags.slice());
  1012. }
  1013. for (var i = 0; i < tags.length; ++i) {
  1014. var _tag = tags[i];
  1015. if (typeof _tag === 'string') {
  1016. var tagObj = knownTags[_tag];
  1017. if (!tagObj) {
  1018. var _keys = Object.keys(knownTags).map(function (key) {
  1019. return JSON.stringify(key);
  1020. }).join(', ');
  1021. throw new Error("Unknown custom tag \"".concat(_tag, "\"; use one of ").concat(_keys));
  1022. }
  1023. tags[i] = tagObj;
  1024. }
  1025. }
  1026. return tags;
  1027. }
  1028. var sortMapEntriesByKey = function sortMapEntriesByKey(a, b) {
  1029. return a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
  1030. };
  1031. var coreKnownTags = {
  1032. 'tag:yaml.org,2002:binary': tags.binary,
  1033. 'tag:yaml.org,2002:omap': tags.omap,
  1034. 'tag:yaml.org,2002:pairs': tags.pairs,
  1035. 'tag:yaml.org,2002:set': tags.set,
  1036. 'tag:yaml.org,2002:timestamp': tags.timestamp
  1037. };
  1038. var Schema = function Schema(_ref) {
  1039. var customTags = _ref.customTags,
  1040. merge = _ref.merge,
  1041. resolveKnownTags = _ref.resolveKnownTags,
  1042. schema = _ref.schema,
  1043. sortMapEntries = _ref.sortMapEntries;
  1044. _classCallCheck(this, Schema);
  1045. this.merge = !!merge;
  1046. this.name = schema;
  1047. this.knownTags = resolveKnownTags ? coreKnownTags : {};
  1048. this.tags = getSchemaTags(schemas, tags, customTags, schema); // Used by createNode(), to avoid circular dependencies
  1049. this.map = tags.map;
  1050. this.seq = tags.seq; // Used by createMap()
  1051. this.sortMapEntries = sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null;
  1052. };
  1053. export { Merge as M, Schema as S, MERGE_KEY as a };