| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211 |
- 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';
- 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';
- var MERGE_KEY = '<<';
- var Merge = /*#__PURE__*/function (_Pair) {
- _inherits(Merge, _Pair);
- var _super = _createSuper(Merge);
- function Merge(pair) {
- var _this;
- _classCallCheck(this, Merge);
- if (pair instanceof Pair) {
- var seq = pair.value;
- if (!(seq instanceof YAMLSeq)) {
- seq = new YAMLSeq();
- seq.items.push(pair.value);
- seq.range = pair.value.range;
- }
- _this = _super.call(this, pair.key, seq);
- _this.range = pair.range;
- } else {
- _this = _super.call(this, new Scalar(MERGE_KEY), new YAMLSeq());
- }
- _this.type = Pair.Type.MERGE_PAIR;
- return _possibleConstructorReturn(_this);
- } // If the value associated with a merge key is a single mapping node, each of
- // its key/value pairs is inserted into the current mapping, unless the key
- // already exists in it. If the value associated with the merge key is a
- // sequence, then this sequence is expected to contain mapping nodes and each
- // of these nodes is merged in turn according to its order in the sequence.
- // Keys in mapping nodes earlier in the sequence override keys specified in
- // later mapping nodes. -- http://yaml.org/type/merge.html
- _createClass(Merge, [{
- key: "addToJSMap",
- value: function addToJSMap(ctx, map) {
- var _iterator = _createForOfIteratorHelper(this.value.items),
- _step;
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
- var source = _step.value.source;
- if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps');
- var srcMap = source.toJSON(null, ctx, Map);
- var _iterator2 = _createForOfIteratorHelper(srcMap),
- _step2;
- try {
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
- var _step2$value = _slicedToArray(_step2.value, 2),
- key = _step2$value[0],
- value = _step2$value[1];
- if (map instanceof Map) {
- if (!map.has(key)) map.set(key, value);
- } else if (map instanceof Set) {
- map.add(key);
- } else if (!Object.prototype.hasOwnProperty.call(map, key)) {
- Object.defineProperty(map, key, {
- value: value,
- writable: true,
- enumerable: true,
- configurable: true
- });
- }
- }
- } catch (err) {
- _iterator2.e(err);
- } finally {
- _iterator2.f();
- }
- }
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
- }
- return map;
- }
- }, {
- key: "toString",
- value: function toString(ctx, onComment) {
- var seq = this.value;
- if (seq.items.length > 1) return _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
- this.value = seq.items[0];
- var str = _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
- this.value = seq;
- return str;
- }
- }]);
- return Merge;
- }(Pair);
- function createMap(schema, obj, ctx) {
- var keepUndefined = ctx.keepUndefined,
- replacer = ctx.replacer;
- var map = new YAMLMap(schema);
- var add = function add(key, value) {
- if (typeof replacer === 'function') value = replacer.call(obj, key, value);else if (Array.isArray(replacer) && !replacer.includes(key)) return;
- if (value !== undefined || keepUndefined) map.items.push(createPair(key, value, ctx));
- };
- if (obj instanceof Map) {
- var _iterator = _createForOfIteratorHelper(obj),
- _step;
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
- var _step$value = _slicedToArray(_step.value, 2),
- key = _step$value[0],
- value = _step$value[1];
- add(key, value);
- }
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
- }
- } else if (obj && _typeof(obj) === 'object') {
- for (var _i = 0, _Object$keys = Object.keys(obj); _i < _Object$keys.length; _i++) {
- var _key = _Object$keys[_i];
- add(_key, obj[_key]);
- }
- }
- if (typeof schema.sortMapEntries === 'function') {
- map.items.sort(schema.sortMapEntries);
- }
- return map;
- }
- var map = {
- createNode: createMap,
- default: true,
- nodeClass: YAMLMap,
- tag: 'tag:yaml.org,2002:map',
- resolve: function resolve(map) {
- return map;
- }
- };
- function createSeq(schema, obj, ctx) {
- var replacer = ctx.replacer;
- var seq = new YAMLSeq(schema);
- if (obj && obj[Symbol.iterator]) {
- var i = 0;
- var _iterator = _createForOfIteratorHelper(obj),
- _step;
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
- var it = _step.value;
- if (typeof replacer === 'function') {
- var key = obj instanceof Set ? it : String(i++);
- it = replacer.call(obj, key, it);
- }
- seq.items.push(createNode(it, null, ctx));
- }
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
- }
- }
- return seq;
- }
- var seq = {
- createNode: createSeq,
- default: true,
- nodeClass: YAMLSeq,
- tag: 'tag:yaml.org,2002:seq',
- resolve: function resolve(seq) {
- return seq;
- }
- };
- var string = {
- identify: function identify(value) {
- return typeof value === 'string';
- },
- default: true,
- tag: 'tag:yaml.org,2002:str',
- resolve: function resolve(str) {
- return str;
- },
- stringify: function stringify(item, ctx, onComment, onChompKeep) {
- ctx = Object.assign({
- actualString: true
- }, ctx);
- return stringifyString(item, ctx, onComment, onChompKeep);
- },
- options: strOptions
- };
- var failsafe = [map, seq, string];
- /* global BigInt */
- var intIdentify = function intIdentify(value) {
- return typeof value === 'bigint' || Number.isInteger(value);
- };
- var intResolve = function intResolve(src, offset, radix) {
- return intOptions.asBigInt ? BigInt(src) : parseInt(src.substring(offset), radix);
- };
- function intStringify(node, radix, prefix) {
- var value = node.value;
- if (intIdentify(value) && value >= 0) return prefix + value.toString(radix);
- return stringifyNumber(node);
- }
- var nullObj = {
- identify: function identify(value) {
- return value == null;
- },
- createNode: function createNode(schema, value, ctx) {
- return ctx.wrapScalars ? new Scalar(null) : null;
- },
- default: true,
- tag: 'tag:yaml.org,2002:null',
- test: /^(?:~|[Nn]ull|NULL)?$/,
- resolve: function resolve(str) {
- var node = new Scalar(null);
- node.sourceStr = str;
- return node;
- },
- options: nullOptions,
- stringify: function stringify(_ref) {
- var sourceStr = _ref.sourceStr;
- return sourceStr !== null && sourceStr !== void 0 ? sourceStr : nullOptions.nullStr;
- }
- };
- var boolObj = {
- identify: function identify(value) {
- return typeof value === 'boolean';
- },
- default: true,
- tag: 'tag:yaml.org,2002:bool',
- test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
- resolve: function resolve(str) {
- return str[0] === 't' || str[0] === 'T';
- },
- options: boolOptions,
- stringify: function stringify(_ref2) {
- var value = _ref2.value;
- return value ? boolOptions.trueStr : boolOptions.falseStr;
- }
- };
- var octObj = {
- identify: function identify(value) {
- return intIdentify(value) && value >= 0;
- },
- default: true,
- tag: 'tag:yaml.org,2002:int',
- format: 'OCT',
- test: /^0o[0-7]+$/,
- resolve: function resolve(str) {
- return intResolve(str, 2, 8);
- },
- options: intOptions,
- stringify: function stringify(node) {
- return intStringify(node, 8, '0o');
- }
- };
- var intObj = {
- identify: intIdentify,
- default: true,
- tag: 'tag:yaml.org,2002:int',
- test: /^[-+]?[0-9]+$/,
- resolve: function resolve(str) {
- return intResolve(str, 0, 10);
- },
- options: intOptions,
- stringify: stringifyNumber
- };
- var hexObj = {
- identify: function identify(value) {
- return intIdentify(value) && value >= 0;
- },
- default: true,
- tag: 'tag:yaml.org,2002:int',
- format: 'HEX',
- test: /^0x[0-9a-fA-F]+$/,
- resolve: function resolve(str) {
- return intResolve(str, 2, 16);
- },
- options: intOptions,
- stringify: function stringify(node) {
- return intStringify(node, 16, '0x');
- }
- };
- var nanObj = {
- identify: function identify(value) {
- return typeof value === 'number';
- },
- default: true,
- tag: 'tag:yaml.org,2002:float',
- test: /^(?:[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN))$/,
- resolve: function resolve(str) {
- return str.slice(-3).toLowerCase() === 'nan' ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY;
- },
- stringify: stringifyNumber
- };
- var expObj = {
- identify: function identify(value) {
- return typeof value === 'number';
- },
- default: true,
- tag: 'tag:yaml.org,2002:float',
- format: 'EXP',
- test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
- resolve: function resolve(str) {
- return parseFloat(str);
- },
- stringify: function stringify(_ref3) {
- var value = _ref3.value;
- return Number(value).toExponential();
- }
- };
- var floatObj = {
- identify: function identify(value) {
- return typeof value === 'number';
- },
- default: true,
- tag: 'tag:yaml.org,2002:float',
- test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
- resolve: function resolve(str) {
- var node = new Scalar(parseFloat(str));
- var dot = str.indexOf('.');
- if (dot !== -1 && str[str.length - 1] === '0') node.minFractionDigits = str.length - dot - 1;
- return node;
- },
- stringify: stringifyNumber
- };
- var core = failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
- /* global BigInt */
- var intIdentify$1 = function intIdentify(value) {
- return typeof value === 'bigint' || Number.isInteger(value);
- };
- var stringifyJSON = function stringifyJSON(_ref) {
- var value = _ref.value;
- return JSON.stringify(value);
- };
- var json = [map, seq, {
- identify: function identify(value) {
- return typeof value === 'string';
- },
- default: true,
- tag: 'tag:yaml.org,2002:str',
- resolve: function resolve(str) {
- return str;
- },
- stringify: stringifyJSON
- }, {
- identify: function identify(value) {
- return value == null;
- },
- createNode: function createNode(schema, value, ctx) {
- return ctx.wrapScalars ? new Scalar(null) : null;
- },
- default: true,
- tag: 'tag:yaml.org,2002:null',
- test: /^null$/,
- resolve: function resolve() {
- return null;
- },
- stringify: stringifyJSON
- }, {
- identify: function identify(value) {
- return typeof value === 'boolean';
- },
- default: true,
- tag: 'tag:yaml.org,2002:bool',
- test: /^true|false$/,
- resolve: function resolve(str) {
- return str === 'true';
- },
- stringify: stringifyJSON
- }, {
- identify: intIdentify$1,
- default: true,
- tag: 'tag:yaml.org,2002:int',
- test: /^-?(?:0|[1-9][0-9]*)$/,
- resolve: function resolve(str) {
- return intOptions.asBigInt ? BigInt(str) : parseInt(str, 10);
- },
- stringify: function stringify(_ref2) {
- var value = _ref2.value;
- return intIdentify$1(value) ? value.toString() : JSON.stringify(value);
- }
- }, {
- identify: function identify(value) {
- return typeof value === 'number';
- },
- default: true,
- tag: 'tag:yaml.org,2002:float',
- test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
- resolve: function resolve(str) {
- return parseFloat(str);
- },
- stringify: stringifyJSON
- }, {
- default: true,
- test: /^/,
- resolve: function resolve(str, onError) {
- onError("Unresolved plain scalar ".concat(JSON.stringify(str)));
- return str;
- }
- }];
- /* global atob, btoa, Buffer */
- var binary = {
- identify: function identify(value) {
- return value instanceof Uint8Array;
- },
- // Buffer inherits from Uint8Array
- default: false,
- tag: 'tag:yaml.org,2002:binary',
- /**
- * Returns a Buffer in node and an Uint8Array in browsers
- *
- * To use the resulting buffer as an image, you'll want to do something like:
- *
- * const blob = new Blob([buffer], { type: 'image/jpeg' })
- * document.querySelector('#photo').src = URL.createObjectURL(blob)
- */
- resolve: function resolve(src, onError) {
- if (typeof Buffer === 'function') {
- return Buffer.from(src, 'base64');
- } else if (typeof atob === 'function') {
- // On IE 11, atob() can't handle newlines
- var str = atob(src.replace(/[\n\r]/g, ''));
- var buffer = new Uint8Array(str.length);
- for (var i = 0; i < str.length; ++i) {
- buffer[i] = str.charCodeAt(i);
- }
- return buffer;
- } else {
- onError('This environment does not support reading binary tags; either Buffer or atob is required');
- return src;
- }
- },
- options: binaryOptions,
- stringify: function stringify(_ref, ctx, onComment, onChompKeep) {
- var comment = _ref.comment,
- type = _ref.type,
- value = _ref.value;
- var src;
- if (typeof Buffer === 'function') {
- src = value instanceof Buffer ? value.toString('base64') : Buffer.from(value.buffer).toString('base64');
- } else if (typeof btoa === 'function') {
- var s = '';
- for (var i = 0; i < value.length; ++i) {
- s += String.fromCharCode(value[i]);
- }
- src = btoa(s);
- } else {
- throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');
- }
- if (!type) type = binaryOptions.defaultType;
- if (type === Type.QUOTE_DOUBLE) {
- value = src;
- } else {
- var lineWidth = binaryOptions.lineWidth;
- var n = Math.ceil(src.length / lineWidth);
- var lines = new Array(n);
- for (var _i = 0, o = 0; _i < n; ++_i, o += lineWidth) {
- lines[_i] = src.substr(o, lineWidth);
- }
- value = lines.join(type === Type.BLOCK_LITERAL ? '\n' : ' ');
- }
- return stringifyString({
- comment: comment,
- type: type,
- value: value
- }, ctx, onComment, onChompKeep);
- }
- };
- function parsePairs(seq, onError) {
- if (seq instanceof YAMLSeq) {
- for (var i = 0; i < seq.items.length; ++i) {
- var item = seq.items[i];
- if (item instanceof Pair) continue;else if (item instanceof YAMLMap) {
- if (item.items.length > 1) onError('Each pair must have its own sequence indicator');
- var pair = item.items[0] || new Pair();
- if (item.commentBefore) pair.commentBefore = pair.commentBefore ? "".concat(item.commentBefore, "\n").concat(pair.commentBefore) : item.commentBefore;
- if (item.comment) pair.comment = pair.comment ? "".concat(item.comment, "\n").concat(pair.comment) : item.comment;
- item = pair;
- }
- seq.items[i] = item instanceof Pair ? item : new Pair(item);
- }
- } else onError('Expected a sequence for this tag');
- return seq;
- }
- function createPairs(schema, iterable, ctx) {
- var replacer = ctx.replacer;
- var pairs = new YAMLSeq(schema);
- pairs.tag = 'tag:yaml.org,2002:pairs';
- var i = 0;
- var _iterator = _createForOfIteratorHelper(iterable),
- _step;
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
- var it = _step.value;
- if (typeof replacer === 'function') it = replacer.call(iterable, String(i++), it);
- var key = void 0,
- value = void 0;
- if (Array.isArray(it)) {
- if (it.length === 2) {
- key = it[0];
- value = it[1];
- } else throw new TypeError("Expected [key, value] tuple: ".concat(it));
- } else if (it && it instanceof Object) {
- var keys = Object.keys(it);
- if (keys.length === 1) {
- key = keys[0];
- value = it[key];
- } else throw new TypeError("Expected { key: value } tuple: ".concat(it));
- } else {
- key = it;
- }
- pairs.items.push(createPair(key, value, ctx));
- }
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
- }
- return pairs;
- }
- var pairs = {
- default: false,
- tag: 'tag:yaml.org,2002:pairs',
- resolve: parsePairs,
- createNode: createPairs
- };
- var YAMLOMap = /*#__PURE__*/function (_YAMLSeq) {
- _inherits(YAMLOMap, _YAMLSeq);
- var _super = _createSuper(YAMLOMap);
- function YAMLOMap() {
- var _this;
- _classCallCheck(this, YAMLOMap);
- _this = _super.call(this);
- _defineProperty(_assertThisInitialized(_this), "add", YAMLMap.prototype.add.bind(_assertThisInitialized(_this)));
- _defineProperty(_assertThisInitialized(_this), "delete", YAMLMap.prototype.delete.bind(_assertThisInitialized(_this)));
- _defineProperty(_assertThisInitialized(_this), "get", YAMLMap.prototype.get.bind(_assertThisInitialized(_this)));
- _defineProperty(_assertThisInitialized(_this), "has", YAMLMap.prototype.has.bind(_assertThisInitialized(_this)));
- _defineProperty(_assertThisInitialized(_this), "set", YAMLMap.prototype.set.bind(_assertThisInitialized(_this)));
- _this.tag = YAMLOMap.tag;
- return _this;
- }
- _createClass(YAMLOMap, [{
- key: "toJSON",
- value: function toJSON(_, ctx) {
- var map = new Map();
- if (ctx && ctx.onCreate) ctx.onCreate(map);
- var _iterator = _createForOfIteratorHelper(this.items),
- _step;
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
- var pair = _step.value;
- var key = void 0,
- value = void 0;
- if (pair instanceof Pair) {
- key = toJS(pair.key, '', ctx);
- value = toJS(pair.value, key, ctx);
- } else {
- key = toJS(pair, '', ctx);
- }
- if (map.has(key)) throw new Error('Ordered maps must not include duplicate keys');
- map.set(key, value);
- }
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
- }
- return map;
- }
- }]);
- return YAMLOMap;
- }(YAMLSeq);
- _defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap');
- function parseOMap(seq, onError) {
- var pairs = parsePairs(seq, onError);
- var seenKeys = [];
- var _iterator2 = _createForOfIteratorHelper(pairs.items),
- _step2;
- try {
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
- var key = _step2.value.key;
- if (key instanceof Scalar) {
- if (seenKeys.includes(key.value)) {
- onError("Ordered maps must not include duplicate keys: ".concat(key.value));
- } else {
- seenKeys.push(key.value);
- }
- }
- }
- } catch (err) {
- _iterator2.e(err);
- } finally {
- _iterator2.f();
- }
- return Object.assign(new YAMLOMap(), pairs);
- }
- function createOMap(schema, iterable, ctx) {
- var pairs = createPairs(schema, iterable, ctx);
- var omap = new YAMLOMap();
- omap.items = pairs.items;
- return omap;
- }
- var omap = {
- identify: function identify(value) {
- return value instanceof Map;
- },
- nodeClass: YAMLOMap,
- default: false,
- tag: 'tag:yaml.org,2002:omap',
- resolve: parseOMap,
- createNode: createOMap
- };
- var YAMLSet = /*#__PURE__*/function (_YAMLMap) {
- _inherits(YAMLSet, _YAMLMap);
- var _super = _createSuper(YAMLSet);
- function YAMLSet(schema) {
- var _this;
- _classCallCheck(this, YAMLSet);
- _this = _super.call(this, schema);
- _this.tag = YAMLSet.tag;
- return _this;
- }
- _createClass(YAMLSet, [{
- key: "add",
- value: function add(key) {
- var pair = key instanceof Pair ? key : new Pair(key);
- var prev = findPair(this.items, pair.key);
- if (!prev) this.items.push(pair);
- }
- }, {
- key: "get",
- value: function get(key, keepPair) {
- var pair = findPair(this.items, key);
- return !keepPair && pair instanceof Pair ? pair.key instanceof Scalar ? pair.key.value : pair.key : pair;
- }
- }, {
- key: "set",
- value: function set(key, value) {
- if (typeof value !== 'boolean') throw new Error("Expected boolean value for set(key, value) in a YAML set, not ".concat(_typeof(value)));
- var prev = findPair(this.items, key);
- if (prev && !value) {
- this.items.splice(this.items.indexOf(prev), 1);
- } else if (!prev && value) {
- this.items.push(new Pair(key));
- }
- }
- }, {
- key: "toJSON",
- value: function toJSON(_, ctx) {
- return _get(_getPrototypeOf(YAMLSet.prototype), "toJSON", this).call(this, _, ctx, Set);
- }
- }, {
- key: "toString",
- value: function toString(ctx, onComment, onChompKeep) {
- if (!ctx) return JSON.stringify(this);
- 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');
- }
- }]);
- return YAMLSet;
- }(YAMLMap);
- _defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set');
- function parseSet(map, onError) {
- if (map instanceof YAMLMap) {
- if (map.hasAllNullValues()) return Object.assign(new YAMLSet(), map);else onError('Set items must all have null values');
- } else onError('Expected a mapping for this tag');
- return map;
- }
- function createSet(schema, iterable, ctx) {
- var replacer = ctx.replacer;
- var set = new YAMLSet(schema);
- var _iterator = _createForOfIteratorHelper(iterable),
- _step;
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
- var value = _step.value;
- if (typeof replacer === 'function') value = replacer.call(iterable, value, value);
- set.items.push(createPair(value, null, ctx));
- }
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
- }
- return set;
- }
- var set = {
- identify: function identify(value) {
- return value instanceof Set;
- },
- nodeClass: YAMLSet,
- default: false,
- tag: 'tag:yaml.org,2002:set',
- resolve: parseSet,
- createNode: createSet
- };
- var parseSexagesimal = function parseSexagesimal(str, isInt) {
- var sign = str[0];
- var parts = sign === '-' || sign === '+' ? str.substring(1) : str;
- var num = function num(n) {
- return isInt && intOptions.asBigInt ? BigInt(n) : Number(n);
- };
- var res = parts.replace(/_/g, '').split(':').reduce(function (res, p) {
- return res * num(60) + num(p);
- }, num(0));
- return sign === '-' ? num(-1) * res : res;
- }; // hhhh:mm:ss.sss
- var stringifySexagesimal = function stringifySexagesimal(_ref) {
- var value = _ref.value;
- var num = function num(n) {
- return n;
- };
- if (typeof value === 'bigint') num = function num(n) {
- return BigInt(n);
- };else if (isNaN(value) || !isFinite(value)) return stringifyNumber(value);
- var sign = '';
- if (value < 0) {
- sign = '-';
- value *= num(-1);
- }
- var _60 = num(60);
- var parts = [value % _60]; // seconds, including ms
- if (value < 60) {
- parts.unshift(0); // at least one : is required
- } else {
- value = (value - parts[0]) / _60;
- parts.unshift(value % _60); // minutes
- if (value >= 60) {
- value = (value - parts[0]) / _60;
- parts.unshift(value); // hours
- }
- }
- return sign + parts.map(function (n) {
- return n < 10 ? '0' + String(n) : String(n);
- }).join(':').replace(/000000\d*$/, '') // % 60 may introduce error
- ;
- };
- var intTime = {
- identify: function identify(value) {
- return typeof value === 'bigint' || Number.isInteger(value);
- },
- default: true,
- tag: 'tag:yaml.org,2002:int',
- format: 'TIME',
- test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,
- resolve: function resolve(str) {
- return parseSexagesimal(str, true);
- },
- stringify: stringifySexagesimal
- };
- var floatTime = {
- identify: function identify(value) {
- return typeof value === 'number';
- },
- default: true,
- tag: 'tag:yaml.org,2002:float',
- format: 'TIME',
- test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,
- resolve: function resolve(str) {
- return parseSexagesimal(str, false);
- },
- stringify: stringifySexagesimal
- };
- var timestamp = {
- identify: function identify(value) {
- return value instanceof Date;
- },
- default: true,
- tag: 'tag:yaml.org,2002:timestamp',
- // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
- // may be omitted altogether, resulting in a date format. In such a case, the time part is
- // assumed to be 00:00:00Z (start of day, UTC).
- test: RegExp('^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd
- '(?:' + // time is optional
- '(?:t|T|[ \\t]+)' + // t | T | whitespace
- '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)?
- '(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30
- ')?$'),
- resolve: function resolve(str) {
- var _str$match = str.match(timestamp.test),
- _str$match2 = _slicedToArray(_str$match, 9),
- year = _str$match2[1],
- month = _str$match2[2],
- day = _str$match2[3],
- hour = _str$match2[4],
- minute = _str$match2[5],
- second = _str$match2[6],
- millisec = _str$match2[7],
- tz = _str$match2[8];
- if (millisec) millisec = (millisec + '00').substr(1, 3);
- var date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0);
- if (tz && tz !== 'Z') {
- var d = parseSexagesimal(tz, false);
- if (Math.abs(d) < 30) d *= 60;
- date -= 60000 * d;
- }
- return new Date(date);
- },
- stringify: function stringify(_ref2) {
- var value = _ref2.value;
- return value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '');
- }
- };
- /* global BigInt */
- var boolStringify = function boolStringify(_ref) {
- var value = _ref.value;
- return value ? boolOptions.trueStr : boolOptions.falseStr;
- };
- var intIdentify$2 = function intIdentify(value) {
- return typeof value === 'bigint' || Number.isInteger(value);
- };
- function intResolve$1(str, offset, radix) {
- var sign = str[0];
- if (sign === '-' || sign === '+') offset += 1;
- str = str.substring(offset).replace(/_/g, '');
- if (intOptions.asBigInt) {
- switch (radix) {
- case 2:
- str = "0b".concat(str);
- break;
- case 8:
- str = "0o".concat(str);
- break;
- case 16:
- str = "0x".concat(str);
- break;
- }
- var _n = BigInt(str);
- return sign === '-' ? BigInt(-1) * _n : _n;
- }
- var n = parseInt(str, radix);
- return sign === '-' ? -1 * n : n;
- }
- function intStringify$1(node, radix, prefix) {
- var value = node.value;
- if (intIdentify$2(value)) {
- var str = value.toString(radix);
- return value < 0 ? '-' + prefix + str.substr(1) : prefix + str;
- }
- return stringifyNumber(node);
- }
- var yaml11 = failsafe.concat([{
- identify: function identify(value) {
- return value == null;
- },
- createNode: function createNode(schema, value, ctx) {
- return ctx.wrapScalars ? new Scalar(null) : null;
- },
- default: true,
- tag: 'tag:yaml.org,2002:null',
- test: /^(?:~|[Nn]ull|NULL)?$/,
- resolve: function resolve(str) {
- var node = new Scalar(null);
- node.sourceStr = str;
- return node;
- },
- options: nullOptions,
- stringify: function stringify(_ref2) {
- var sourceStr = _ref2.sourceStr;
- return sourceStr !== null && sourceStr !== void 0 ? sourceStr : nullOptions.nullStr;
- }
- }, {
- identify: function identify(value) {
- return typeof value === 'boolean';
- },
- default: true,
- tag: 'tag:yaml.org,2002:bool',
- test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
- resolve: function resolve() {
- return true;
- },
- options: boolOptions,
- stringify: boolStringify
- }, {
- identify: function identify(value) {
- return typeof value === 'boolean';
- },
- default: true,
- tag: 'tag:yaml.org,2002:bool',
- test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
- resolve: function resolve() {
- return false;
- },
- options: boolOptions,
- stringify: boolStringify
- }, {
- identify: intIdentify$2,
- default: true,
- tag: 'tag:yaml.org,2002:int',
- format: 'BIN',
- test: /^[-+]?0b[0-1_]+$/,
- resolve: function resolve(str) {
- return intResolve$1(str, 2, 2);
- },
- stringify: function stringify(node) {
- return intStringify$1(node, 2, '0b');
- }
- }, {
- identify: intIdentify$2,
- default: true,
- tag: 'tag:yaml.org,2002:int',
- format: 'OCT',
- test: /^[-+]?0[0-7_]+$/,
- resolve: function resolve(str) {
- return intResolve$1(str, 1, 8);
- },
- stringify: function stringify(node) {
- return intStringify$1(node, 8, '0');
- }
- }, {
- identify: intIdentify$2,
- default: true,
- tag: 'tag:yaml.org,2002:int',
- test: /^[-+]?[0-9][0-9_]*$/,
- resolve: function resolve(str) {
- return intResolve$1(str, 0, 10);
- },
- stringify: stringifyNumber
- }, {
- identify: intIdentify$2,
- default: true,
- tag: 'tag:yaml.org,2002:int',
- format: 'HEX',
- test: /^[-+]?0x[0-9a-fA-F_]+$/,
- resolve: function resolve(str) {
- return intResolve$1(str, 2, 16);
- },
- stringify: function stringify(node) {
- return intStringify$1(node, 16, '0x');
- }
- }, {
- identify: function identify(value) {
- return typeof value === 'number';
- },
- default: true,
- tag: 'tag:yaml.org,2002:float',
- test: /^[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/,
- resolve: function resolve(str) {
- return str.slice(-3).toLowerCase() === 'nan' ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY;
- },
- stringify: stringifyNumber
- }, {
- identify: function identify(value) {
- return typeof value === 'number';
- },
- default: true,
- tag: 'tag:yaml.org,2002:float',
- format: 'EXP',
- test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
- resolve: function resolve(str) {
- return parseFloat(str.replace(/_/g, ''));
- },
- stringify: function stringify(_ref3) {
- var value = _ref3.value;
- return Number(value).toExponential();
- }
- }, {
- identify: function identify(value) {
- return typeof value === 'number';
- },
- default: true,
- tag: 'tag:yaml.org,2002:float',
- test: /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,
- resolve: function resolve(str) {
- var node = new Scalar(parseFloat(str.replace(/_/g, '')));
- var dot = str.indexOf('.');
- if (dot !== -1) {
- var f = str.substring(dot + 1).replace(/_/g, '');
- if (f[f.length - 1] === '0') node.minFractionDigits = f.length;
- }
- return node;
- },
- stringify: stringifyNumber
- }], binary, omap, pairs, set, intTime, floatTime, timestamp);
- var schemas = {
- core: core,
- failsafe: failsafe,
- json: json,
- yaml11: yaml11
- };
- var tags = {
- binary: binary,
- bool: boolObj,
- float: floatObj,
- floatExp: expObj,
- floatNaN: nanObj,
- floatTime: floatTime,
- int: intObj,
- intHex: hexObj,
- intOct: octObj,
- intTime: intTime,
- map: map,
- null: nullObj,
- omap: omap,
- pairs: pairs,
- seq: seq,
- set: set,
- timestamp: timestamp
- };
- function getSchemaTags(schemas, knownTags, customTags, schemaId) {
- var tags = schemas[schemaId.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
- if (!tags) {
- var keys = Object.keys(schemas).map(function (key) {
- return JSON.stringify(key);
- }).join(', ');
- throw new Error("Unknown schema \"".concat(schemaId, "\"; use one of ").concat(keys));
- }
- if (Array.isArray(customTags)) {
- var _iterator = _createForOfIteratorHelper(customTags),
- _step;
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
- var tag = _step.value;
- tags = tags.concat(tag);
- }
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
- }
- } else if (typeof customTags === 'function') {
- tags = customTags(tags.slice());
- }
- for (var i = 0; i < tags.length; ++i) {
- var _tag = tags[i];
- if (typeof _tag === 'string') {
- var tagObj = knownTags[_tag];
- if (!tagObj) {
- var _keys = Object.keys(knownTags).map(function (key) {
- return JSON.stringify(key);
- }).join(', ');
- throw new Error("Unknown custom tag \"".concat(_tag, "\"; use one of ").concat(_keys));
- }
- tags[i] = tagObj;
- }
- }
- return tags;
- }
- var sortMapEntriesByKey = function sortMapEntriesByKey(a, b) {
- return a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
- };
- var coreKnownTags = {
- 'tag:yaml.org,2002:binary': tags.binary,
- 'tag:yaml.org,2002:omap': tags.omap,
- 'tag:yaml.org,2002:pairs': tags.pairs,
- 'tag:yaml.org,2002:set': tags.set,
- 'tag:yaml.org,2002:timestamp': tags.timestamp
- };
- var Schema = function Schema(_ref) {
- var customTags = _ref.customTags,
- merge = _ref.merge,
- resolveKnownTags = _ref.resolveKnownTags,
- schema = _ref.schema,
- sortMapEntries = _ref.sortMapEntries;
- _classCallCheck(this, Schema);
- this.merge = !!merge;
- this.name = schema;
- this.knownTags = resolveKnownTags ? coreKnownTags : {};
- this.tags = getSchemaTags(schemas, tags, customTags, schema); // Used by createNode(), to avoid circular dependencies
- this.map = tags.map;
- this.seq = tags.seq; // Used by createMap()
- this.sortMapEntries = sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null;
- };
- export { Merge as M, Schema as S, MERGE_KEY as a };
|