diff --git a/.vscode/settings.json b/.vscode/settings.json index 2c9c7f8..335e514 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "editorInfo.foreground": "#50d5fa14", "terminal.ansiBrightBlack": "#50a2ff9c", "activityBar.background": "#4884b2", + "activityBar.activeBorder": "#712e54", "activityBar.foreground": "#e7e7e7", "activityBar.inactiveForeground": "#e7e7e799", "activityBarBadge.background": "#712e54", diff --git a/dist/hashids.js b/dist/hashids.js index 664d8da..0e87d34 100644 --- a/dist/hashids.js +++ b/dist/hashids.js @@ -10,17 +10,11 @@ factory(mod.exports); global.Hashids = mod.exports; } -})(typeof globalThis === "object" ? globalThis : typeof self === "object" ? self : this, function (_exports) { +})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) { "use strict"; _exports.__esModule = true; - _exports.unicodeSubstr = _exports.onlyChars = _exports.withoutChars = _exports.keepUniqueChars = _exports.default = void 0; - - function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); } - - function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } - - function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } + _exports.onlyChars = _exports.withoutChars = _exports.keepUnique = _exports.default = void 0; function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } @@ -50,7 +44,6 @@ seps = 'cfhistuCFHISTU'; } - this.salt = salt; this.minLength = minLength; if (typeof minLength !== 'number') { @@ -65,7 +58,14 @@ throw new TypeError("Hashids: Provided alphabet has to be a string (is " + typeof alphabet + ")"); } - var uniqueAlphabet = keepUniqueChars(alphabet); + var saltChars = _toConsumableArray(salt); + + var alphabetChars = _toConsumableArray(alphabet); + + var sepsChars = _toConsumableArray(seps); + + this.salt = saltChars; + var uniqueAlphabet = keepUnique(alphabetChars); if (uniqueAlphabet.length < minAlphabetLength) { throw new Error("Hashids: alphabet must contain at least " + minAlphabetLength + " unique characters, provided: " + uniqueAlphabet); @@ -73,34 +73,42 @@ /** `alphabet` should not contains `seps` */ - this.alphabet = withoutChars(uniqueAlphabet, seps); + this.alphabet = withoutChars(uniqueAlphabet, sepsChars); /** `seps` should contain only characters present in `alphabet` */ - var filteredSeps = onlyChars(seps, uniqueAlphabet); - this.seps = shuffle(filteredSeps, salt); + var filteredSeps = onlyChars(sepsChars, uniqueAlphabet); + this.seps = shuffle(filteredSeps, saltChars); var sepsLength; var diff; - if (_toConsumableArray(this.seps).length === 0 || _toConsumableArray(this.alphabet).length / _toConsumableArray(this.seps).length > sepDiv) { - sepsLength = Math.ceil(_toConsumableArray(this.alphabet).length / sepDiv); + if (this.seps.length === 0 || this.alphabet.length / this.seps.length > sepDiv) { + sepsLength = Math.ceil(this.alphabet.length / sepDiv); + + if (sepsLength > this.seps.length) { + var _this$seps; - if (sepsLength > _toConsumableArray(this.seps).length) { - diff = sepsLength - _toConsumableArray(this.seps).length; - this.seps += unicodeSubstr(this.alphabet, 0, diff); - this.alphabet = unicodeSubstr(this.alphabet, diff); + diff = sepsLength - this.seps.length; + + (_this$seps = this.seps).push.apply(_this$seps, _toConsumableArray(this.alphabet.slice(0, diff))); + + this.alphabet = this.alphabet.slice(diff); } } - this.alphabet = shuffle(this.alphabet, salt); - var guardCount = Math.ceil(_toConsumableArray(this.alphabet).length / guardDiv); + this.alphabet = shuffle(this.alphabet, saltChars); + var guardCount = Math.ceil(this.alphabet.length / guardDiv); - if (_toConsumableArray(this.alphabet).length < 3) { - this.guards = unicodeSubstr(this.seps, 0, guardCount); - this.seps = unicodeSubstr(this.seps, guardCount); + if (this.alphabet.length < 3) { + this.guards = this.seps.slice(0, guardCount); + this.seps = this.seps.slice(guardCount); } else { - this.guards = unicodeSubstr(this.alphabet, 0, guardCount); - this.alphabet = unicodeSubstr(this.alphabet, guardCount); + this.guards = this.alphabet.slice(0, guardCount); + this.alphabet = this.alphabet.slice(guardCount); } + + this.guardsRegExp = makeAnyCharRegExp(this.guards); + this.sepsRegExp = makeAnyCharRegExp(this.seps); + this.allowedCharsRegExp = makeEveryCharRegExp([].concat(_toConsumableArray(this.alphabet), _toConsumableArray(this.guards), _toConsumableArray(this.seps))); } var _proto = Hashids.prototype; @@ -133,7 +141,7 @@ return ret; } - return this._encode(numbers); + return this._encode(numbers).join(''); }; _proto.decode = function decode(id) { @@ -186,50 +194,57 @@ _proto._encode = function _encode(numbers) { var _this = this; - var ret; var alphabet = this.alphabet; var numbersIdInt = numbers.reduce(function (last, number, i) { return last + (typeof number === 'bigint' ? Number(number % BigInt(i + 100)) : number % (i + 100)); }, 0); - ret = _toConsumableArray(alphabet)[numbersIdInt % _toConsumableArray(alphabet).length]; - var lottery = ret; - - var seps = _toConsumableArray(this.seps); + var ret = [alphabet[numbersIdInt % alphabet.length]]; + var lottery = ret.slice(); + var seps = this.seps; + var guards = this.guards; + numbers.forEach(function (number, i) { + var _ret; - var guards = _toConsumableArray(this.guards); + var buffer = lottery.concat(_this.salt, alphabet); // const buffer = [...lottery, ...this.salt, ...alphabet] - numbers.forEach(function (number, i) { - var buffer = lottery + _this.salt + alphabet; - alphabet = shuffle(alphabet, unicodeSubstr(buffer, 0)); + alphabet = shuffle(alphabet, buffer); var last = toAlphabet(number, alphabet); - ret += last; + + (_ret = ret).push.apply(_ret, _toConsumableArray(last)); if (i + 1 < numbers.length) { - var charCode = last.codePointAt(0) + i; + var charCode = last[0].codePointAt(0) + i; var extraNumber = typeof number === 'bigint' ? Number(number % BigInt(charCode)) : number % charCode; - ret += seps[extraNumber % seps.length]; + ret.push(seps[extraNumber % seps.length]); } }); - if (_toConsumableArray(ret).length < this.minLength) { - var prefixGuardIndex = (numbersIdInt + _toConsumableArray(ret)[0].codePointAt(0)) % guards.length; - ret = guards[prefixGuardIndex] + ret; + if (ret.length < this.minLength) { + var prefixGuardIndex = (numbersIdInt + ret[0].codePointAt(0)) % guards.length; + ret.unshift(guards[prefixGuardIndex]); - if (_toConsumableArray(ret).length < this.minLength) { - var suffixGuardIndex = (numbersIdInt + _toConsumableArray(ret)[2].codePointAt(0)) % guards.length; - ret = ret + guards[suffixGuardIndex]; + if (ret.length < this.minLength) { + var suffixGuardIndex = (numbersIdInt + ret[2].codePointAt(0)) % guards.length; + ret.push(guards[suffixGuardIndex]); } } - var halfLength = Math.floor(_toConsumableArray(alphabet).length / 2); + var halfLength = Math.floor(alphabet.length / 2); + + while (ret.length < this.minLength) { + var _ret2, _ret3; - while (_toConsumableArray(ret).length < this.minLength) { alphabet = shuffle(alphabet, alphabet); - ret = unicodeSubstr(alphabet, halfLength) + ret + unicodeSubstr(alphabet, 0, halfLength); - var excess = _toConsumableArray(ret).length - this.minLength; + + (_ret2 = ret).unshift.apply(_ret2, _toConsumableArray(alphabet.slice(halfLength))); + + (_ret3 = ret).push.apply(_ret3, _toConsumableArray(alphabet.slice(0, halfLength))); + + var excess = ret.length - this.minLength; if (excess > 0) { - ret = unicodeSubstr(ret, excess / 2, this.minLength); + var halfOfExcess = excess / 2; + ret = ret.slice(halfOfExcess, halfOfExcess + this.minLength); } } @@ -237,55 +252,61 @@ }; _proto.isValidId = function isValidId(id) { - var _this2 = this; - - return _toConsumableArray(id).every(function (char) { - return _this2.alphabet.includes(char) || _this2.guards.includes(char) || _this2.seps.includes(char); - }); - }; + return this.allowedCharsRegExp.test(id); // return this._isValidId([...id]) + } // private _isValidId(idChars: string[]): boolean { + // return idChars.every( + // (char) => + // this.alphabet.includes(char) || + // this.guards.includes(char) || + // this.seps.includes(char), + // ) + // } + ; _proto._decode = function _decode(id) { - var _this3 = this; - if (!this.isValidId(id)) { - throw new Error("The provided ID (" + id + ") is invalid, as it contains characters that do not exist in the alphabet (" + this.guards + this.seps + this.alphabet + ")"); + throw new Error("The provided ID (" + id + ") is invalid, as it contains characters that do not exist in the alphabet (" + this.guards.join('') + this.seps.join('') + this.alphabet.join('') + ")"); } - var idGuardsArray = splitAtMatch(id, function (char) { - return _this3.guards.includes(char); - }); + var idGuardsArray = id.split(this.guardsRegExp); // splitAtMatch(idChars, (char) => + // this.guards.includes(char), + // ) + var splitIndex = idGuardsArray.length === 3 || idGuardsArray.length === 2 ? 1 : 0; var idBreakdown = idGuardsArray[splitIndex]; + if (idBreakdown.length === 0) return []; + var lotteryChar = idBreakdown[Symbol.iterator]().next().value; + var idArray = idBreakdown.slice(lotteryChar.length).split(this.sepsRegExp); // const idBreakdownArray = [...idBreakdown] + // const [lotteryChar, ...rest] = idBreakdownArray + // const idArray = rest.join('').split(this.sepsRegExp) - var idBreakdownArray = _toConsumableArray(idBreakdown); + var lastAlphabet = this.alphabet; + var result = []; - if (idBreakdownArray.length === 0) return []; + for (var _iterator = idArray, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; - var _idBreakdownArray = _toArray(idBreakdownArray), - lotteryChar = _idBreakdownArray[0], - chars = _idBreakdownArray.slice(1); + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } - var rest = chars.join(''); - var idArray = splitAtMatch(rest, function (char) { - return _this3.seps.includes(char); - }); + var subId = _ref; + var buffer = [lotteryChar].concat(_toConsumableArray(this.salt), _toConsumableArray(lastAlphabet)); + var nextAlphabet = shuffle(lastAlphabet, buffer.slice(0, lastAlphabet.length)); + result.push(fromAlphabet(_toConsumableArray(subId), nextAlphabet)); + lastAlphabet = nextAlphabet; + } // if the result is different from what we'd expect, we return an empty result (malformed input): + + + if (this._encode(result).join('') !== id) return []; // if (this._encode(result).some((char, index) => idChars[index] !== char)) { + // return [] + // } - var _idArray$reduce = idArray.reduce(function (_ref, subId) { - var result = _ref.result, - lastAlphabet = _ref.lastAlphabet; - var buffer = lotteryChar + _this3.salt + lastAlphabet; - var nextAlphabet = shuffle(lastAlphabet, unicodeSubstr(buffer, 0, _toConsumableArray(lastAlphabet).length)); - return { - result: [].concat(_toConsumableArray(result), [fromAlphabet(subId, nextAlphabet)]), - lastAlphabet: nextAlphabet - }; - }, { - result: [], - lastAlphabet: this.alphabet - }), - result = _idArray$reduce.result; - - if (this._encode(result) !== id) return []; return result; }; @@ -297,49 +318,28 @@ var sepDiv = 3.5; var guardDiv = 12; - var keepUniqueChars = function keepUniqueChars(str) { - return Array.from(new Set(str)).join(''); + var keepUnique = function keepUnique(content) { + return Array.from(new Set(content)); }; - _exports.keepUniqueChars = keepUniqueChars; - - var withoutChars = function withoutChars(_ref2, _ref3) { - var _ref4 = _toArray(_ref2), - str = _ref4.slice(0); - - var _ref5 = _toArray(_ref3), - without = _ref5.slice(0); + _exports.keepUnique = keepUnique; - return str.filter(function (char) { - return !without.includes(char); - }).join(''); + var withoutChars = function withoutChars(chars, _withoutChars) { + return chars.filter(function (char) { + return !_withoutChars.includes(char); + }); }; _exports.withoutChars = withoutChars; - var onlyChars = function onlyChars(_ref6, _ref7) { - var _ref8 = _toArray(_ref6), - str = _ref8.slice(0); - - var _ref9 = _toArray(_ref7), - only = _ref9.slice(0); - - return str.filter(function (char) { - return only.includes(char); - }).join(''); + var onlyChars = function onlyChars(chars, keepChars) { + return chars.filter(function (char) { + return keepChars.includes(char); + }); }; _exports.onlyChars = onlyChars; - var unicodeSubstr = function unicodeSubstr(_ref10, from, to) { - var _ref11 = _toArray(_ref10), - str = _ref11.slice(0); - - return str.slice(from, to === undefined ? undefined : from + to).join(''); - }; - - _exports.unicodeSubstr = unicodeSubstr; - var isIntegerNumber = function isIntegerNumber(n) { return typeof n === 'bigint' || !Number.isNaN(Number(n)) && Math.floor(Number(n)) === n; }; @@ -348,84 +348,68 @@ return typeof n === 'bigint' || n >= 0 && Number.isSafeInteger(n); }; - function shuffle(alphabet, _ref12) { - var _ref13 = _toArray(_ref12), - salt = _ref13.slice(0); + function shuffle(alphabetChars, saltChars) { + if (saltChars.length === 0) { + return alphabetChars; + } var integer; + var transformed = alphabetChars.slice(); - if (!salt.length) { - return alphabet; - } - - var alphabetChars = _toConsumableArray(alphabet); + for (var i = transformed.length - 1, v = 0, p = 0; i > 0; i--, v++) { + v %= saltChars.length; + p += integer = saltChars[v].codePointAt(0); + var j = (integer + v + p) % i; // swap characters at positions i and j - for (var i = alphabetChars.length - 1, v = 0, p = 0; i > 0; i--, v++) { - v %= salt.length; - p += integer = salt[v].codePointAt(0); - var j = (integer + v + p) % i // swap characters at positions i and j - ; - var _ref14 = [alphabetChars[i], alphabetChars[j]]; - alphabetChars[j] = _ref14[0]; - alphabetChars[i] = _ref14[1]; + var a = transformed[i]; + var b = transformed[j]; + transformed[j] = a; + transformed[i] = b; } - return alphabetChars.join(''); + return transformed; } - var toAlphabet = function toAlphabet(input, _ref15) { - var _ref16 = _toArray(_ref15), - alphabet = _ref16.slice(0); - - var id = ''; + var toAlphabet = function toAlphabet(input, alphabetChars) { + var id = []; if (typeof input === 'bigint') { - var alphabetLength = BigInt(alphabet.length); + var alphabetLength = BigInt(alphabetChars.length); do { - id = alphabet[Number(input % alphabetLength)] + id; + id.unshift(alphabetChars[Number(input % alphabetLength)]); input = input / alphabetLength; } while (input > BigInt(0)); } else { do { - id = alphabet[input % alphabet.length] + id; - input = Math.floor(input / alphabet.length); + id.unshift(alphabetChars[input % alphabetChars.length]); + input = Math.floor(input / alphabetChars.length); } while (input > 0); } return id; }; - var fromAlphabet = function fromAlphabet(_ref17, _ref18) { - var _ref19 = _toArray(_ref17), - input = _ref19.slice(0); - - var _ref20 = _toArray(_ref18), - alphabet = _ref20.slice(0); - - return input.map(function (item) { - var index = alphabet.indexOf(item); + var fromAlphabet = function fromAlphabet(inputChars, alphabetChars) { + return inputChars.reduce(function (carry, item) { + var index = alphabetChars.indexOf(item); if (index === -1) { - var inputString = input.join(''); - var alphabetString = alphabet.join(''); - throw new Error("The provided ID (" + inputString + ") is invalid, as it contains characters that do not exist in the alphabet (" + alphabetString + ")"); + throw new Error("The provided ID (" + inputChars.join('') + ") is invalid, as it contains characters that do not exist in the alphabet (" + alphabetChars.join('') + ")"); } - return index; - }).reduce(function (carry, index) { if (typeof carry === 'bigint') { - return carry * BigInt(alphabet.length) + BigInt(index); + return carry * BigInt(alphabetChars.length) + BigInt(index); } - var value = carry * alphabet.length + index; + var value = carry * alphabetChars.length + index; var isSafeValue = Number.isSafeInteger(value); if (isSafeValue) { return value; } else { if (typeof BigInt === 'function') { - return BigInt(carry) * BigInt(alphabet.length) + BigInt(index); + return BigInt(carry) * BigInt(alphabetChars.length) + BigInt(index); } else { // we do not have support for BigInt: throw new Error("Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment"); @@ -434,22 +418,11 @@ }, 0); }; - var splitAtMatch = function splitAtMatch(_ref21, match) { - var _ref22 = _toArray(_ref21), - chars = _ref22.slice(0); - - return chars.reduce(function (groups, char) { - return match(char) ? [].concat(_toConsumableArray(groups), ['']) : [].concat(_toConsumableArray(groups.slice(0, -1)), [groups[groups.length - 1] + char]); - }, ['']); - }; - var safeToParseNumberRegExp = /^\+?[0-9]+$/; var safeParseInt10 = function safeParseInt10(str) { return safeToParseNumberRegExp.test(str) ? parseInt(str, 10) : NaN; }; - /** note: this doesn't need to support unicode, since it's used to split hex strings only */ - var splitAtIntervalAndMap = function splitAtIntervalAndMap(str, nth, map) { return Array.from({ @@ -458,6 +431,30 @@ return map(str.slice(index * nth, (index + 1) * nth)); }); }; + + var makeAnyCharRegExp = function makeAnyCharRegExp(chars) { + return new RegExp(chars.map(function (char) { + return escapeRegExp(char); + }) // we need to sort these from longest to shortest, + // as they may contain multibyte unicode characters (these should come first) + .sort(function (a, b) { + return b.length - a.length; + }).join('|')); + }; + + var makeEveryCharRegExp = function makeEveryCharRegExp(chars) { + return new RegExp("^[" + chars.map(function (char) { + return escapeRegExp(char); + }) // we need to sort these from longest to shortest, + // as they may contain multibyte unicode characters (these should come first) + .sort(function (a, b) { + return b.length - a.length; + }).join('') + "]+$"); + }; + + var escapeRegExp = function escapeRegExp(text) { + return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); + }; }); //# sourceMappingURL=hashids.js.map \ No newline at end of file diff --git a/dist/hashids.js.map b/dist/hashids.js.map index 90bb779..a37b51a 100644 --- a/dist/hashids.js.map +++ b/dist/hashids.js.map @@ -1 +1 @@ -{"version":3,"sources":["../lib/hashids.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAEqB,O;;;AAKnB,qBACU,IADV,EAEU,SAFV,EAGE,QAHF,EAIE,IAJF,EAKE;AAAA,UAJQ,IAIR;AAJQ,QAAA,IAIR,GAJe,EAIf;AAAA;;AAAA,UAHQ,SAGR;AAHQ,QAAA,SAGR,GAHoB,CAGpB;AAAA;;AAAA,UAFA,QAEA;AAFA,QAAA,QAEA,GAFW,gEAEX;AAAA;;AAAA,UADA,IACA;AADA,QAAA,IACA,GADO,gBACP;AAAA;;AAAA,WAJQ,IAIR,GAJQ,IAIR;AAAA,WAHQ,SAGR,GAHQ,SAGR;;AACA,UAAI,OAAO,SAAP,KAAqB,QAAzB,EAAmC;AACjC,cAAM,IAAI,SAAJ,2DACoD,OAAO,SAD3D,OAAN;AAGD;;AACD,UAAI,OAAO,IAAP,KAAgB,QAApB,EAA8B;AAC5B,cAAM,IAAI,SAAJ,sDAC+C,OAAO,IADtD,OAAN;AAGD;;AACD,UAAI,OAAO,QAAP,KAAoB,QAAxB,EAAkC;AAChC,cAAM,IAAI,SAAJ,wDACiD,OAAO,QADxD,OAAN;AAGD;;AAED,UAAM,cAAc,GAAG,eAAe,CAAC,QAAD,CAAtC;;AAEA,UAAI,cAAc,CAAC,MAAf,GAAwB,iBAA5B,EAA+C;AAC7C,cAAM,IAAI,KAAJ,8CACuC,iBADvC,sCACyF,cADzF,CAAN;AAGD;AAED;;;AACA,WAAK,QAAL,GAAgB,YAAY,CAAC,cAAD,EAAiB,IAAjB,CAA5B;AACA;;AACA,UAAM,YAAY,GAAG,SAAS,CAAC,IAAD,EAAO,cAAP,CAA9B;AACA,WAAK,IAAL,GAAY,OAAO,CAAC,YAAD,EAAe,IAAf,CA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NumberLike = number | bigint\n\nexport default class Hashids {\n private alphabet: string\n private seps: string\n private guards: string\n\n public constructor(\n private salt = '',\n private minLength = 0,\n alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',\n seps = 'cfhistuCFHISTU',\n ) {\n if (typeof minLength !== 'number') {\n throw new TypeError(\n `Hashids: Provided 'minLength' has to be a number (is ${typeof minLength})`,\n )\n }\n if (typeof salt !== 'string') {\n throw new TypeError(\n `Hashids: Provided 'salt' has to be a string (is ${typeof salt})`,\n )\n }\n if (typeof alphabet !== 'string') {\n throw new TypeError(\n `Hashids: Provided alphabet has to be a string (is ${typeof alphabet})`,\n )\n }\n\n const uniqueAlphabet = keepUniqueChars(alphabet)\n\n if (uniqueAlphabet.length < minAlphabetLength) {\n throw new Error(\n `Hashids: alphabet must contain at least ${minAlphabetLength} unique characters, provided: ${uniqueAlphabet}`,\n )\n }\n\n /** `alphabet` should not contains `seps` */\n this.alphabet = withoutChars(uniqueAlphabet, seps)\n /** `seps` should contain only characters present in `alphabet` */\n const filteredSeps = onlyChars(seps, uniqueAlphabet)\n this.seps = shuffle(filteredSeps, salt)\n\n let sepsLength\n let diff\n\n if (\n [...this.seps].length === 0 ||\n [...this.alphabet].length / [...this.seps].length > sepDiv\n ) {\n sepsLength = Math.ceil([...this.alphabet].length / sepDiv)\n\n if (sepsLength > [...this.seps].length) {\n diff = sepsLength - [...this.seps].length\n this.seps += unicodeSubstr(this.alphabet, 0, diff)\n this.alphabet = unicodeSubstr(this.alphabet, diff)\n }\n }\n\n this.alphabet = shuffle(this.alphabet, salt)\n const guardCount = Math.ceil([...this.alphabet].length / guardDiv)\n\n if ([...this.alphabet].length < 3) {\n this.guards = unicodeSubstr(this.seps, 0, guardCount)\n this.seps = unicodeSubstr(this.seps, guardCount)\n } else {\n this.guards = unicodeSubstr(this.alphabet, 0, guardCount)\n this.alphabet = unicodeSubstr(this.alphabet, guardCount)\n }\n }\n\n public encode(numbers: string): string\n public encode(numbers: NumberLike[]): string\n public encode(...numbers: NumberLike[]): string\n public encode(numbers: string[]): string\n public encode(...numbers: string[]): string\n public encode(\n first: T[] | T,\n ...numbers: T[]\n ): string {\n const ret = ''\n\n if (Array.isArray(first)) {\n numbers = first\n } else {\n // eslint-disable-next-line eqeqeq\n numbers = [...(first != null ? [first] : []), ...numbers]\n }\n\n if (!numbers.length) {\n return ret\n }\n\n if (!numbers.every(isIntegerNumber)) {\n numbers = numbers.map((n) =>\n typeof n === 'bigint' || typeof n === 'number'\n ? n\n : safeParseInt10(String(n)),\n ) as T[]\n }\n\n if (!(numbers as NumberLike[]).every(isPositiveAndFinite)) {\n return ret\n }\n\n return this._encode(numbers as number[])\n }\n\n public decode(id: string): NumberLike[] {\n if (!id || typeof id !== 'string' || id.length === 0) return []\n return this._decode(id)\n }\n\n /**\n * @description Splits a hex string into groups of 12-digit hexadecimal numbers,\n * then prefixes each with '1' and encodes the resulting array of numbers\n *\n * Encoding '00000000000f00000000000f000f' would be the equivalent of:\n * Hashids.encode([0x100000000000f, 0x100000000000f, 0x1000f])\n *\n * This means that if your environment supports BigInts,\n * you will get different (shorter) results if you provide\n * a BigInt representation of your hex and use `encode` directly, e.g.:\n * Hashids.encode(BigInt(`0x${hex}`))\n *\n * To decode such a representation back to a hex string, use the following snippet:\n * Hashids.decode(id)[0].toString(16)\n */\n public encodeHex(hex: string | bigint): string {\n switch (typeof hex) {\n case 'bigint':\n hex = hex.toString(16)\n break\n case 'string':\n if (!/^[0-9a-fA-F]+$/.test(hex)) return ''\n break\n default:\n throw new Error(\n `Hashids: The provided value is neither a string, nor a BigInt (got: ${typeof hex})`,\n )\n }\n\n const numbers = splitAtIntervalAndMap(hex, 12, (part) =>\n parseInt(`1${part}`, 16),\n )\n return this.encode(numbers)\n }\n\n public decodeHex(id: string) {\n return this.decode(id)\n .map((number) => number.toString(16).slice(1))\n .join('')\n }\n\n private _encode(numbers: NumberLike[]): string {\n let ret: string\n let alphabet = this.alphabet\n\n const numbersIdInt = numbers.reduce(\n (last, number, i) =>\n last +\n (typeof number === 'bigint'\n ? Number(number % BigInt(i + 100))\n : number % (i + 100)),\n 0,\n )\n\n ret = [...alphabet][numbersIdInt % [...alphabet].length]\n const lottery = ret\n\n const seps = [...this.seps]\n const guards = [...this.guards]\n\n numbers.forEach((number, i) => {\n const buffer = lottery + this.salt + alphabet\n\n alphabet = shuffle(alphabet, unicodeSubstr(buffer, 0))\n const last = toAlphabet(number, alphabet)\n\n ret += last\n\n if (i + 1 < numbers.length) {\n const charCode = last.codePointAt(0)! + i\n const extraNumber =\n typeof number === 'bigint'\n ? Number(number % BigInt(charCode))\n : number % charCode\n ret += seps[extraNumber % seps.length]\n }\n })\n\n if ([...ret].length < this.minLength) {\n const prefixGuardIndex =\n (numbersIdInt + [...ret][0].codePointAt(0)!) % guards.length\n ret = guards[prefixGuardIndex] + ret\n\n if ([...ret].length < this.minLength) {\n const suffixGuardIndex =\n (numbersIdInt + [...ret][2].codePointAt(0)!) % guards.length\n ret = ret + guards[suffixGuardIndex]\n }\n }\n\n const halfLength = Math.floor([...alphabet].length / 2)\n while ([...ret].length < this.minLength) {\n alphabet = shuffle(alphabet, alphabet)\n ret =\n unicodeSubstr(alphabet, halfLength) +\n ret +\n unicodeSubstr(alphabet, 0, halfLength)\n\n const excess = [...ret].length - this.minLength\n if (excess > 0) {\n ret = unicodeSubstr(ret, excess / 2, this.minLength)\n }\n }\n\n return ret\n }\n\n public isValidId(id: string): boolean {\n return [...id].every(\n (char) =>\n this.alphabet.includes(char) ||\n this.guards.includes(char) ||\n this.seps.includes(char),\n )\n }\n\n private _decode(id: string): NumberLike[] {\n if (!this.isValidId(id)) {\n throw new Error(\n `The provided ID (${id}) is invalid, as it contains characters that do not exist in the alphabet (${this.guards}${this.seps}${this.alphabet})`,\n )\n }\n const idGuardsArray = splitAtMatch(id, (char) => this.guards.includes(char))\n const splitIndex =\n idGuardsArray.length === 3 || idGuardsArray.length === 2 ? 1 : 0\n\n const idBreakdown = idGuardsArray[splitIndex]\n const idBreakdownArray = [...idBreakdown]\n if (idBreakdownArray.length === 0) return []\n\n const [lotteryChar, ...chars] = idBreakdownArray\n const rest = chars.join('')\n const idArray = splitAtMatch(rest, (char) => this.seps.includes(char))\n\n const {result} = idArray.reduce(\n ({result, lastAlphabet}, subId) => {\n const buffer = lotteryChar + this.salt + lastAlphabet\n const nextAlphabet = shuffle(\n lastAlphabet,\n unicodeSubstr(buffer, 0, [...lastAlphabet].length),\n )\n return {\n result: [...result, fromAlphabet(subId, nextAlphabet)],\n lastAlphabet: nextAlphabet,\n }\n },\n {result: [] as NumberLike[], lastAlphabet: this.alphabet},\n )\n\n if (this._encode(result) !== id) return []\n return result\n }\n}\n\nconst minAlphabetLength = 16\nconst sepDiv = 3.5\nconst guardDiv = 12\n\nexport const keepUniqueChars = (str: string) =>\n Array.from(new Set(str)).join('')\n\nexport const withoutChars = ([...str]: string, [...without]: string) =>\n str.filter((char) => !without.includes(char)).join('')\n\nexport const onlyChars = ([...str]: string, [...only]: string) =>\n str.filter((char) => only.includes(char)).join('')\n\nexport const unicodeSubstr = ([...str]: string, from: number, to?: number) =>\n str.slice(from, to === undefined ? undefined : from + to).join('')\n\nconst isIntegerNumber = (n: NumberLike | string) =>\n typeof n === 'bigint' ||\n (!Number.isNaN(Number(n)) && Math.floor(Number(n)) === n)\n\nconst isPositiveAndFinite = (n: NumberLike) =>\n typeof n === 'bigint' || (n >= 0 && Number.isSafeInteger(n))\n\nfunction shuffle(alphabet: string, [...salt]: string) {\n let integer: number\n\n if (!salt.length) {\n return alphabet\n }\n\n const alphabetChars = [...alphabet]\n\n for (let i = alphabetChars.length - 1, v = 0, p = 0; i > 0; i--, v++) {\n v %= salt.length\n p += integer = salt[v].codePointAt(0)!\n const j = (integer + v + p) % i\n\n // swap characters at positions i and j\n ;[alphabetChars[j], alphabetChars[i]] = [alphabetChars[i], alphabetChars[j]]\n }\n\n return alphabetChars.join('')\n}\n\nconst toAlphabet = (input: NumberLike, [...alphabet]: string) => {\n let id = ''\n\n if (typeof input === 'bigint') {\n const alphabetLength = BigInt(alphabet.length)\n do {\n id = alphabet[Number(input % alphabetLength)] + id\n input = input / alphabetLength\n } while (input > BigInt(0))\n } else {\n do {\n id = alphabet[input % alphabet.length] + id\n input = Math.floor(input / alphabet.length)\n } while (input > 0)\n }\n\n return id\n}\n\nconst fromAlphabet = ([...input]: string, [...alphabet]: string) =>\n input\n .map((item) => {\n const index = alphabet.indexOf(item)\n if (index === -1) {\n const inputString = input.join('')\n const alphabetString = alphabet.join('')\n throw new Error(\n `The provided ID (${inputString}) is invalid, as it contains characters that do not exist in the alphabet (${alphabetString})`,\n )\n }\n return index\n })\n .reduce(\n (carry, index) => {\n if (typeof carry === 'bigint') {\n return carry * BigInt(alphabet.length) + BigInt(index)\n }\n const value = carry * alphabet.length + index\n const isSafeValue = Number.isSafeInteger(value)\n if (isSafeValue) {\n return value\n } else {\n if (typeof BigInt === 'function') {\n return BigInt(carry) * BigInt(alphabet.length) + BigInt(index)\n } else {\n // we do not have support for BigInt:\n throw new Error(\n `Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment`,\n )\n }\n }\n },\n 0 as NumberLike,\n )\n\nconst splitAtMatch = ([...chars]: string, match: (char: string) => boolean) =>\n chars.reduce(\n (groups, char) =>\n match(char)\n ? [...groups, '']\n : [...groups.slice(0, -1), groups[groups.length - 1] + char],\n [''],\n )\n\nconst safeToParseNumberRegExp = /^\\+?[0-9]+$/\nconst safeParseInt10 = (str: string) =>\n safeToParseNumberRegExp.test(str) ? parseInt(str, 10) : NaN\n\n/** note: this doesn't need to support unicode, since it's used to split hex strings only */\nconst splitAtIntervalAndMap = (\n str: string,\n nth: number,\n map: (n: string) => T,\n): T[] =>\n Array.from({length: Math.ceil(str.length / nth)}, (_, index) =>\n map(str.slice(index * nth, (index + 1) * nth)),\n )\n"]} \ No newline at end of file +{"version":3,"sources":["../lib/hashids.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;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,CAAC,MAAJ,GAAa,GAAvB;AAAT,KAArB,EAA4D,UAAC,CAAD,EAAI,KAAJ;AAAA,aAC1D,GAAG,CAAC,GAAG,CAAC,KAAJ,CAAU,KAAK,GAAG,GAAlB,EAAuB,CAAC,KAAK,GAAG,CAAT,IAAc,GAArC,CAAD,CADuD;AAAA,KAA5D,CAL4B;AAAA,GAA9B;;AASA,MAAM,iBAAiB,GAAG,SAApB,iBAAoB,CAAC,KAAD;AAAA,WACxB,IAAI,MAAJ,CACE,KAAK,CACF,GADH,CACO,UAAC,IAAD;AAAA,aAAU,YAAY,CAAC,IAAD,CAAtB;AAAA,KADP,EAEE;AACA;AAHF,KAIG,IAJH,CAIQ,UAAC,CAAD,EAAI,CAAJ;AAAA,aAAU,CAAC,CAAC,MAAF,GAAW,CAAC,CAAC,MAAvB;AAAA,KAJR,EAKG,IALH,CAKQ,GALR,CADF,CADwB;AAAA,GAA1B;;AAUA,MAAM,mBAAmB,GAAG,SAAtB,mBAAsB,CAAC,KAAD;AAAA,WAC1B,IAAI,MAAJ,QACO,KAAK,CACP,GADE,CACE,UAAC,IAAD;AAAA,aAAU,YAAY,CAAC,IAAD,CAAtB;AAAA,KADF,EAEH;AACA;AAHG,KAIF,IAJE,CAIG,UAAC,CAAD,EAAI,CAAJ;AAAA,aAAU,CAAC,CAAC,MAAF,GAAW,CAAC,CAAC,MAAvB;AAAA,KAJH,EAKF,IALE,CAKG,EALH,CADP,SAD0B;AAAA,GAA5B;;AAUA,MAAM,YAAY,GAAG,SAAf,YAAe,CAAC,IAAD;AAAA,WACnB,IAAI,CAAC,OAAL,CAAa,0BAAb,EAAyC,MAAzC,CADmB;AAAA,GAArB","file":"hashids.js","sourcesContent":["type NumberLike = number | bigint\n\nexport default class Hashids {\n private alphabet: string[]\n private seps: string[]\n private guards: string[]\n private salt: string[]\n private guardsRegExp: RegExp\n private sepsRegExp: RegExp\n private allowedCharsRegExp: RegExp\n\n public constructor(\n salt = '',\n private minLength = 0,\n alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',\n seps = 'cfhistuCFHISTU',\n ) {\n if (typeof minLength !== 'number') {\n throw new TypeError(\n `Hashids: Provided 'minLength' has to be a number (is ${typeof minLength})`,\n )\n }\n if (typeof salt !== 'string') {\n throw new TypeError(\n `Hashids: Provided 'salt' has to be a string (is ${typeof salt})`,\n )\n }\n if (typeof alphabet !== 'string') {\n throw new TypeError(\n `Hashids: Provided alphabet has to be a string (is ${typeof alphabet})`,\n )\n }\n\n const saltChars = [...salt]\n const alphabetChars = [...alphabet]\n const sepsChars = [...seps]\n\n this.salt = saltChars\n\n const uniqueAlphabet = keepUnique(alphabetChars)\n\n if (uniqueAlphabet.length < minAlphabetLength) {\n throw new Error(\n `Hashids: alphabet must contain at least ${minAlphabetLength} unique characters, provided: ${uniqueAlphabet}`,\n )\n }\n\n /** `alphabet` should not contains `seps` */\n this.alphabet = withoutChars(uniqueAlphabet, sepsChars)\n /** `seps` should contain only characters present in `alphabet` */\n const filteredSeps = onlyChars(sepsChars, uniqueAlphabet)\n this.seps = shuffle(filteredSeps, saltChars)\n\n let sepsLength\n let diff\n\n if (\n this.seps.length === 0 ||\n this.alphabet.length / this.seps.length > sepDiv\n ) {\n sepsLength = Math.ceil(this.alphabet.length / sepDiv)\n\n if (sepsLength > this.seps.length) {\n diff = sepsLength - this.seps.length\n this.seps.push(...this.alphabet.slice(0, diff))\n this.alphabet = this.alphabet.slice(diff)\n }\n }\n\n this.alphabet = shuffle(this.alphabet, saltChars)\n const guardCount = Math.ceil(this.alphabet.length / guardDiv)\n\n if (this.alphabet.length < 3) {\n this.guards = this.seps.slice(0, guardCount)\n this.seps = this.seps.slice(guardCount)\n } else {\n this.guards = this.alphabet.slice(0, guardCount)\n this.alphabet = this.alphabet.slice(guardCount)\n }\n\n this.guardsRegExp = makeAnyCharRegExp(this.guards)\n this.sepsRegExp = makeAnyCharRegExp(this.seps)\n this.allowedCharsRegExp = makeEveryCharRegExp([\n ...this.alphabet,\n ...this.guards,\n ...this.seps,\n ])\n }\n\n public encode(numbers: string): string\n public encode(numbers: NumberLike[]): string\n public encode(...numbers: NumberLike[]): string\n public encode(numbers: string[]): string\n public encode(...numbers: string[]): string\n public encode(\n first: T[] | T,\n ...numbers: T[]\n ): string {\n const ret = ''\n\n if (Array.isArray(first)) {\n numbers = first\n } else {\n // eslint-disable-next-line eqeqeq\n numbers = [...(first != null ? [first] : []), ...numbers]\n }\n\n if (!numbers.length) {\n return ret\n }\n\n if (!numbers.every(isIntegerNumber)) {\n numbers = numbers.map((n) =>\n typeof n === 'bigint' || typeof n === 'number'\n ? n\n : safeParseInt10(String(n)),\n ) as T[]\n }\n\n if (!(numbers as NumberLike[]).every(isPositiveAndFinite)) {\n return ret\n }\n\n return this._encode(numbers as number[]).join('')\n }\n\n public decode(id: string): NumberLike[] {\n if (!id || typeof id !== 'string' || id.length === 0) return []\n return this._decode(id)\n }\n\n /**\n * @description Splits a hex string into groups of 12-digit hexadecimal numbers,\n * then prefixes each with '1' and encodes the resulting array of numbers\n *\n * Encoding '00000000000f00000000000f000f' would be the equivalent of:\n * Hashids.encode([0x100000000000f, 0x100000000000f, 0x1000f])\n *\n * This means that if your environment supports BigInts,\n * you will get different (shorter) results if you provide\n * a BigInt representation of your hex and use `encode` directly, e.g.:\n * Hashids.encode(BigInt(`0x${hex}`))\n *\n * To decode such a representation back to a hex string, use the following snippet:\n * Hashids.decode(id)[0].toString(16)\n */\n public encodeHex(hex: string | bigint): string {\n switch (typeof hex) {\n case 'bigint':\n hex = hex.toString(16)\n break\n case 'string':\n if (!/^[0-9a-fA-F]+$/.test(hex)) return ''\n break\n default:\n throw new Error(\n `Hashids: The provided value is neither a string, nor a BigInt (got: ${typeof hex})`,\n )\n }\n\n const numbers = splitAtIntervalAndMap(hex, 12, (part) =>\n parseInt(`1${part}`, 16),\n )\n return this.encode(numbers)\n }\n\n public decodeHex(id: string) {\n return this.decode(id)\n .map((number) => number.toString(16).slice(1))\n .join('')\n }\n\n private _encode(numbers: NumberLike[]): string[] {\n let alphabet = this.alphabet\n\n const numbersIdInt = numbers.reduce(\n (last, number, i) =>\n last +\n (typeof number === 'bigint'\n ? Number(number % BigInt(i + 100))\n : number % (i + 100)),\n 0,\n )\n\n let ret: string[] = [alphabet[numbersIdInt % alphabet.length]]\n const lottery = ret.slice()\n\n const seps = this.seps\n const guards = this.guards\n\n numbers.forEach((number, i) => {\n const buffer = lottery.concat(this.salt, alphabet)\n // const buffer = [...lottery, ...this.salt, ...alphabet]\n\n alphabet = shuffle(alphabet, buffer)\n const last = toAlphabet(number, alphabet)\n\n ret.push(...last)\n\n if (i + 1 < numbers.length) {\n const charCode = last[0].codePointAt(0)! + i\n const extraNumber =\n typeof number === 'bigint'\n ? Number(number % BigInt(charCode))\n : number % charCode\n ret.push(seps[extraNumber % seps.length])\n }\n })\n\n if (ret.length < this.minLength) {\n const prefixGuardIndex =\n (numbersIdInt + ret[0].codePointAt(0)!) % guards.length\n ret.unshift(guards[prefixGuardIndex])\n\n if (ret.length < this.minLength) {\n const suffixGuardIndex =\n (numbersIdInt + ret[2].codePointAt(0)!) % guards.length\n ret.push(guards[suffixGuardIndex])\n }\n }\n\n const halfLength = Math.floor(alphabet.length / 2)\n while (ret.length < this.minLength) {\n alphabet = shuffle(alphabet, alphabet)\n ret.unshift(...alphabet.slice(halfLength))\n ret.push(...alphabet.slice(0, halfLength))\n\n const excess = ret.length - this.minLength\n if (excess > 0) {\n const halfOfExcess = excess / 2\n ret = ret.slice(halfOfExcess, halfOfExcess + this.minLength)\n }\n }\n\n return ret\n }\n\n public isValidId(id: string): boolean {\n return this.allowedCharsRegExp.test(id)\n // return this._isValidId([...id])\n }\n\n // private _isValidId(idChars: string[]): boolean {\n // return idChars.every(\n // (char) =>\n // this.alphabet.includes(char) ||\n // this.guards.includes(char) ||\n // this.seps.includes(char),\n // )\n // }\n\n private _decode(id: string): NumberLike[] {\n if (!this.isValidId(id)) {\n throw new Error(\n `The provided ID (${id}) is invalid, as it contains characters that do not exist in the alphabet (${this.guards.join(\n '',\n )}${this.seps.join('')}${this.alphabet.join('')})`,\n )\n }\n const idGuardsArray = id.split(this.guardsRegExp)\n // splitAtMatch(idChars, (char) =>\n // this.guards.includes(char),\n // )\n const splitIndex =\n idGuardsArray.length === 3 || idGuardsArray.length === 2 ? 1 : 0\n\n const idBreakdown = idGuardsArray[splitIndex]\n if (idBreakdown.length === 0) return []\n\n const lotteryChar = idBreakdown[Symbol.iterator]().next().value as string\n const idArray = idBreakdown.slice(lotteryChar.length).split(this.sepsRegExp)\n\n // const idBreakdownArray = [...idBreakdown]\n // const [lotteryChar, ...rest] = idBreakdownArray\n // const idArray = rest.join('').split(this.sepsRegExp)\n\n let lastAlphabet: string[] = this.alphabet\n const result: NumberLike[] = []\n\n for (const subId of idArray) {\n const buffer = [lotteryChar, ...this.salt, ...lastAlphabet]\n const nextAlphabet = shuffle(\n lastAlphabet,\n buffer.slice(0, lastAlphabet.length),\n )\n result.push(fromAlphabet([...subId], nextAlphabet))\n lastAlphabet = nextAlphabet\n }\n\n // if the result is different from what we'd expect, we return an empty result (malformed input):\n if (this._encode(result).join('') !== id) return []\n // if (this._encode(result).some((char, index) => idChars[index] !== char)) {\n // return []\n // }\n return result\n }\n}\n\nconst minAlphabetLength = 16\nconst sepDiv = 3.5\nconst guardDiv = 12\n\nexport const keepUnique = (content: Iterable): T[] =>\n Array.from(new Set(content))\n\nexport const withoutChars = (\n chars: string[],\n withoutChars: string[],\n): string[] => chars.filter((char) => !withoutChars.includes(char))\n\nexport const onlyChars = (chars: string[], keepChars: string[]): string[] =>\n chars.filter((char) => keepChars.includes(char))\n\nconst isIntegerNumber = (n: NumberLike | string) =>\n typeof n === 'bigint' ||\n (!Number.isNaN(Number(n)) && Math.floor(Number(n)) === n)\n\nconst isPositiveAndFinite = (n: NumberLike) =>\n typeof n === 'bigint' || (n >= 0 && Number.isSafeInteger(n))\n\nfunction shuffle(alphabetChars: string[], saltChars: string[]): string[] {\n if (saltChars.length === 0) {\n return alphabetChars\n }\n\n let integer: number\n const transformed = alphabetChars.slice()\n\n for (let i = transformed.length - 1, v = 0, p = 0; i > 0; i--, v++) {\n v %= saltChars.length\n p += integer = saltChars[v].codePointAt(0)!\n const j = (integer + v + p) % i\n\n // swap characters at positions i and j\n const a = transformed[i]\n const b = transformed[j]\n transformed[j] = a\n transformed[i] = b\n }\n\n return transformed\n}\n\nconst toAlphabet = (input: NumberLike, alphabetChars: string[]): string[] => {\n const id: string[] = []\n\n if (typeof input === 'bigint') {\n const alphabetLength = BigInt(alphabetChars.length)\n do {\n id.unshift(alphabetChars[Number(input % alphabetLength)])\n input = input / alphabetLength\n } while (input > BigInt(0))\n } else {\n do {\n id.unshift(alphabetChars[input % alphabetChars.length])\n input = Math.floor(input / alphabetChars.length)\n } while (input > 0)\n }\n\n return id\n}\n\nconst fromAlphabet = (\n inputChars: string[],\n alphabetChars: string[],\n): NumberLike =>\n inputChars.reduce((carry, item) => {\n const index = alphabetChars.indexOf(item)\n if (index === -1) {\n throw new Error(\n `The provided ID (${inputChars.join(\n '',\n )}) is invalid, as it contains characters that do not exist in the alphabet (${alphabetChars.join(\n '',\n )})`,\n )\n }\n if (typeof carry === 'bigint') {\n return carry * BigInt(alphabetChars.length) + BigInt(index)\n }\n const value = carry * alphabetChars.length + index\n const isSafeValue = Number.isSafeInteger(value)\n if (isSafeValue) {\n return value\n } else {\n if (typeof BigInt === 'function') {\n return BigInt(carry) * BigInt(alphabetChars.length) + BigInt(index)\n } else {\n // we do not have support for BigInt:\n throw new Error(\n `Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment`,\n )\n }\n }\n }, 0 as NumberLike)\n\nconst safeToParseNumberRegExp = /^\\+?[0-9]+$/\nconst safeParseInt10 = (str: string) =>\n safeToParseNumberRegExp.test(str) ? parseInt(str, 10) : NaN\n\nconst splitAtIntervalAndMap = (\n str: string,\n nth: number,\n map: (n: string) => T,\n): T[] =>\n Array.from({length: Math.ceil(str.length / nth)}, (_, index) =>\n map(str.slice(index * nth, (index + 1) * nth)),\n )\n\nconst makeAnyCharRegExp = (chars: string[]) =>\n new RegExp(\n chars\n .map((char) => escapeRegExp(char))\n // we need to sort these from longest to shortest,\n // as they may contain multibyte unicode characters (these should come first)\n .sort((a, b) => b.length - a.length)\n .join('|'),\n )\n\nconst makeEveryCharRegExp = (chars: string[]) =>\n new RegExp(\n `^[${chars\n .map((char) => escapeRegExp(char))\n // we need to sort these from longest to shortest,\n // as they may contain multibyte unicode characters (these should come first)\n .sort((a, b) => b.length - a.length)\n .join('')}]+$`,\n )\n\nconst escapeRegExp = (text: string) =>\n text.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&')\n"]} \ No newline at end of file diff --git a/dist/hashids.min.js b/dist/hashids.min.js index 9ec43df..8ffe330 100644 --- a/dist/hashids.min.js +++ b/dist/hashids.min.js @@ -1,2 +1,2 @@ -!function(t,e){if("function"==typeof define&&define.amd)define("Hashids",["exports"],e);else if("undefined"!=typeof exports)e(exports);else{var n={exports:{}};e(n.exports),t.Hashids=n.exports}}("object"==typeof globalThis?globalThis:"object"==typeof self?self:this,(function(t){"use strict";function e(t){return function(t){if(Array.isArray(t))return t}(t)||r(t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function n(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);es)&&(d=Math.ceil(n(this.alphabet).length/s))>n(this.seps).length&&(p=d-n(this.seps).length,this.seps+=c(this.alphabet,0,p),this.alphabet=c(this.alphabet,p)),this.alphabet=g(this.alphabet,t);var b=Math.ceil(n(this.alphabet).length/a);n(this.alphabet).length<3?(this.guards=c(this.seps,0,b),this.seps=c(this.seps,b)):(this.guards=c(this.alphabet,0,b),this.alphabet=c(this.alphabet,b))}var r=t.prototype;return r.encode=function(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),i=1;i0&&(e=c(e,d/2,this.minLength))}return e},r.isValidId=function(t){var e=this;return n(t).every((function(t){return e.alphabet.includes(t)||e.guards.includes(t)||e.seps.includes(t)}))},r._decode=function(t){var r=this;if(!this.isValidId(t))throw new Error("The provided ID ("+t+") is invalid, as it contains characters that do not exist in the alphabet ("+this.guards+this.seps+this.alphabet+")");var i=b(t,(function(t){return r.guards.includes(t)})),o=n(i[3===i.length||2===i.length?1:0]);if(0===o.length)return[];var s=e(o),a=s[0],h=s.slice(1).join(""),u=b(h,(function(t){return r.seps.includes(t)})).reduce((function(t,e){var i=t.result,o=t.lastAlphabet,s=a+r.salt+o,h=g(o,c(s,0,n(o).length));return{result:[].concat(n(i),[v(e,h)]),lastAlphabet:h}}),{result:[],lastAlphabet:this.alphabet}).result;return this._encode(u)!==t?[]:u},t}();t.default=i;var o=16,s=3.5,a=12,h=function(t){return Array.from(new Set(t)).join("")};t.keepUniqueChars=h;var u=function(t,n){var r=e(t).slice(0),i=e(n).slice(0);return r.filter((function(t){return!i.includes(t)})).join("")};t.withoutChars=u;var l=function(t,n){var r=e(t).slice(0),i=e(n).slice(0);return r.filter((function(t){return i.includes(t)})).join("")};t.onlyChars=l;var c=function(t,n,r){return e(t).slice(0).slice(n,void 0===r?void 0:n+r).join("")};t.unicodeSubstr=c;var f=function(t){return"bigint"==typeof t||!Number.isNaN(Number(t))&&Math.floor(Number(t))===t},d=function(t){return"bigint"==typeof t||t>=0&&Number.isSafeInteger(t)};function g(t,r){var i,o=e(r).slice(0);if(!o.length)return t;for(var s=n(t),a=s.length-1,h=0,u=0;a>0;a--,h++){u+=i=o[h%=o.length].codePointAt(0);var l=(i+h+u)%a,c=[s[a],s[l]];s[l]=c[0],s[a]=c[1]}return s.join("")}var p=function(t,n){var r=e(n).slice(0),i="";if("bigint"==typeof t){var o=BigInt(r.length);do{i=r[Number(t%o)]+i,t/=o}while(t>BigInt(0))}else do{i=r[t%r.length]+i,t=Math.floor(t/r.length)}while(t>0);return i},v=function(t,n){var r=e(t).slice(0),i=e(n).slice(0);return r.map((function(t){var e=i.indexOf(t);if(-1===e){var n=r.join(""),o=i.join("");throw new Error("The provided ID ("+n+") is invalid, as it contains characters that do not exist in the alphabet ("+o+")")}return e})).reduce((function(t,e){if("bigint"==typeof t)return t*BigInt(i.length)+BigInt(e);var n=t*i.length+e;if(Number.isSafeInteger(n))return n;if("function"==typeof BigInt)return BigInt(t)*BigInt(i.length)+BigInt(e);throw new Error("Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment")}),0)},b=function(t,r){return e(t).slice(0).reduce((function(t,e){return r(e)?[].concat(n(t),[""]):[].concat(n(t.slice(0,-1)),[t[t.length-1]+e])}),[""])},y=/^\+?[0-9]+$/,m=function(t){return y.test(t)?parseInt(t,10):NaN},w=function(t,e,n){return Array.from({length:Math.ceil(t.length/e)},(function(r,i){return n(t.slice(i*e,(i+1)*e))}))}})); +!function(t,e){if("function"==typeof define&&define.amd)define("Hashids",["exports"],e);else if("undefined"!=typeof exports)e(exports);else{var n={exports:{}};e(n.exports),t.Hashids=n.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(t){"use strict";function e(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);er)&&((b=Math.ceil(this.alphabet.length/r))>this.seps.length&&(m=b-this.seps.length,(w=this.seps).push.apply(w,e(this.alphabet.slice(0,m))),this.alphabet=this.alphabet.slice(m)));this.alphabet=f(this.alphabet,p);var x=Math.ceil(this.alphabet.length/s);this.alphabet.length<3?(this.guards=this.seps.slice(0,x),this.seps=this.seps.slice(x)):(this.guards=this.alphabet.slice(0,x),this.alphabet=this.alphabet.slice(x)),this.guardsRegExp=v(this.guards),this.sepsRegExp=v(this.seps),this.allowedCharsRegExp=y([].concat(e(this.alphabet),e(this.guards),e(this.seps)))}var n=t.prototype;return n.encode=function(t){for(var n=arguments.length,i=new Array(n>1?n-1:0),r=1;r0){var v=b/2;s=s.slice(v,v+this.minLength)}}return s},n.isValidId=function(t){return this.allowedCharsRegExp.test(t)},n._decode=function(t){if(!this.isValidId(t))throw new Error("The provided ID ("+t+") is invalid, as it contains characters that do not exist in the alphabet ("+this.guards.join("")+this.seps.join("")+this.alphabet.join("")+")");var n=t.split(this.guardsRegExp),i=n[3===n.length||2===n.length?1:0];if(0===i.length)return[];var r=i[Symbol.iterator]().next().value,s=i.slice(r.length).split(this.sepsRegExp),o=this.alphabet,a=[],h=s,l=Array.isArray(h),u=0;for(h=l?h:h[Symbol.iterator]();;){var p;if(l){if(u>=h.length)break;p=h[u++]}else{if((u=h.next()).done)break;p=u.value}var g=p,d=f(o,[r].concat(e(this.salt),e(o)).slice(0,o.length));a.push(c(e(g),d)),o=d}return this._encode(a).join("")!==t?[]:a},t}();t.default=n;var i=16,r=3.5,s=12,o=function(t){return Array.from(new Set(t))};t.keepUnique=o;var a=function(t,e){return t.filter((function(t){return!e.includes(t)}))};t.withoutChars=a;var h=function(t,e){return t.filter((function(t){return e.includes(t)}))};t.onlyChars=h;var l=function(t){return"bigint"==typeof t||!Number.isNaN(Number(t))&&Math.floor(Number(t))===t},u=function(t){return"bigint"==typeof t||t>=0&&Number.isSafeInteger(t)};function f(t,e){if(0===e.length)return t;for(var n,i=t.slice(),r=i.length-1,s=0,o=0;r>0;r--,s++){o+=n=e[s%=e.length].codePointAt(0);var a=(n+s+o)%r,h=i[r],l=i[a];i[a]=h,i[r]=l}return i}var p=function(t,e){var n=[];if("bigint"==typeof t){var i=BigInt(e.length);do{n.unshift(e[Number(t%i)]),t/=i}while(t>BigInt(0))}else do{n.unshift(e[t%e.length]),t=Math.floor(t/e.length)}while(t>0);return n},c=function(t,e){return t.reduce((function(n,i){var r=e.indexOf(i);if(-1===r)throw new Error("The provided ID ("+t.join("")+") is invalid, as it contains characters that do not exist in the alphabet ("+e.join("")+")");if("bigint"==typeof n)return n*BigInt(e.length)+BigInt(r);var s=n*e.length+r;if(Number.isSafeInteger(s))return s;if("function"==typeof BigInt)return BigInt(n)*BigInt(e.length)+BigInt(r);throw new Error("Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment")}),0)},g=/^\+?[0-9]+$/,d=function(t){return g.test(t)?parseInt(t,10):NaN},b=function(t,e,n){return Array.from({length:Math.ceil(t.length/e)},(function(i,r){return n(t.slice(r*e,(r+1)*e))}))},v=function(t){return new RegExp(t.map((function(t){return m(t)})).sort((function(t,e){return e.length-t.length})).join("|"))},y=function(t){return new RegExp("^["+t.map((function(t){return m(t)})).sort((function(t,e){return e.length-t.length})).join("")+"]+$")},m=function(t){return t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}})); //# sourceMappingURL=hashids.min.js.map \ No newline at end of file diff --git a/dist/hashids.min.js.map b/dist/hashids.min.js.map index e6a4652..bb81c47 100644 --- a/dist/hashids.min.js.map +++ b/dist/hashids.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["hashids.js"],"names":["global","factory","define","amd","exports","mod","Hashids","globalThis","self","this","_exports","_toArray","arr","Array","isArray","_arrayWithHoles","_iterableToArray","TypeError","_nonIterableRest","_toConsumableArray","i","arr2","length","_arrayWithoutHoles","_nonIterableSpread","iter","Symbol","iterator","Object","prototype","toString","call","from","__esModule","unicodeSubstr","onlyChars","withoutChars","keepUniqueChars","default","salt","minLength","alphabet","seps","uniqueAlphabet","minAlphabetLength","Error","sepsLength","diff","filteredSeps","shuffle","sepDiv","Math","ceil","guardCount","guardDiv","guards","_proto","encode","first","_len","arguments","numbers","_key","ret","concat","every","isIntegerNumber","map","n","safeParseInt10","String","isPositiveAndFinite","_encode","decode","id","_decode","encodeHex","hex","test","splitAtIntervalAndMap","part","parseInt","decodeHex","number","slice","join","_this","numbersIdInt","reduce","last","Number","BigInt","lottery","forEach","buffer","toAlphabet","charCode","codePointAt","extraNumber","prefixGuardIndex","suffixGuardIndex","halfLength","floor","excess","isValidId","_this2","char","includes","_this3","idGuardsArray","splitAtMatch","idBreakdownArray","_idBreakdownArray","lotteryChar","rest","result","_ref","subId","lastAlphabet","nextAlphabet","fromAlphabet","str","Set","_ref2","_ref3","without","filter","_ref6","_ref7","only","_ref10","to","undefined","isNaN","isSafeInteger","_ref12","integer","alphabetChars","v","p","j","_ref14","input","_ref15","alphabetLength","_ref17","_ref18","item","index","indexOf","inputString","alphabetString","carry","value","_ref21","match","groups","safeToParseNumberRegExp","NaN","nth","_"],"mappings":"CAAA,SAAWA,EAAQC,GACjB,GAAsB,mBAAXC,QAAyBA,OAAOC,IACzCD,OAAO,UAAW,CAAC,WAAYD,QAC1B,GAAuB,oBAAZG,QAChBH,EAAQG,aACH,CACL,IAAIC,EAAM,CACRD,QAAS,IAEXH,EAAQI,EAAID,SACZJ,EAAOM,QAAUD,EAAID,SAVzB,CAYyB,iBAAfG,WAA0BA,WAA6B,iBAATC,KAAoBA,KAAOC,MAAM,SAAUC,GACjG,aAKA,SAASC,EAASC,GAAO,OAIzB,SAAyBA,GAAO,GAAIC,MAAMC,QAAQF,GAAM,OAAOA,EAJ/BG,CAAgBH,IAAQI,EAAiBJ,IAEzE,WAA8B,MAAM,IAAIK,UAAU,wDAF+BC,GAMjF,SAASC,EAAmBP,GAAO,OAMnC,SAA4BA,GAAO,GAAIC,MAAMC,QAAQF,GAAM,CAAE,IAAK,IAAIQ,EAAI,EAAGC,EAAO,IAAIR,MAAMD,EAAIU,QAASF,EAAIR,EAAIU,OAAQF,IAAOC,EAAKD,GAAKR,EAAIQ,GAAM,OAAOC,GANnHE,CAAmBX,IAAQI,EAAiBJ,IAEtF,WAAgC,MAAM,IAAIK,UAAU,mDAF0CO,GAI9F,SAASR,EAAiBS,GAAQ,GAAIC,OAAOC,YAAYC,OAAOH,IAAkD,uBAAzCG,OAAOC,UAAUC,SAASC,KAAKN,GAAgC,OAAOZ,MAAMmB,KAAKP,GAb1Jf,EAASuB,YAAa,EACtBvB,EAASwB,cAAgBxB,EAASyB,UAAYzB,EAAS0B,aAAe1B,EAAS2B,gBAAkB3B,EAAS4B,aAAU,EAgBpH,IAAIhC,EAEJ,WACE,SAASA,EAAQiC,EAAMC,EAAWC,EAAUC,GAoB1C,QAnBa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EAAQD,EAAQ/G,EAASnB,OAAS8H,EAGtC,GAFkB1D,OAAO4C,cAAcmB,GAGrC,OAAOA,EAEP,GAAsB,mBAAX9D,OACT,OAAOA,OAAO6D,GAAS7D,OAAOlD,EAASnB,QAAUqE,OAAOyD,GAGxD,MAAM,IAAIvG,MAAM,gHAGnB,IAGDiE,EAAe,SAAsB4C,EAAQC,GAI/C,OAHahJ,EAAS+I,GACHtE,MAAM,GAEZI,QAAO,SAAUoE,EAAQlD,GACpC,OAAOiD,EAAMjD,GAAQ,GAAG1C,OAAO7C,EAAmByI,GAAS,CAAC,KAAO,GAAG5F,OAAO7C,EAAmByI,EAAOxE,MAAM,GAAI,IAAK,CAACwE,EAAOA,EAAOtI,OAAS,GAAKoF,MAClJ,CAAC,MAGFmD,EAA0B,cAE1BxF,EAAiB,SAAwBoD,GAC3C,OAAOoC,EAAwB/E,KAAK2C,GAAOxC,SAASwC,EAAK,IAAMqC,KAK7D/E,EAAwB,SAA+B0C,EAAKsC,EAAK5F,GACnE,OAAOtD,MAAMmB,KAAK,CAChBV,OAAQ6B,KAAKC,KAAKqE,EAAInG,OAASyI,KAC9B,SAAUC,EAAGZ,GACd,OAAOjF,EAAIsD,EAAIrC,MAAMgE,EAAQW,GAAMX,EAAQ,GAAKW"} \ No newline at end of file +{"version":3,"sources":["hashids.js"],"names":["global","factory","define","amd","exports","mod","Hashids","globalThis","self","this","_exports","_toConsumableArray","arr","Array","isArray","i","arr2","length","_arrayWithoutHoles","iter","Symbol","iterator","Object","prototype","toString","call","from","_iterableToArray","TypeError","_nonIterableSpread","__esModule","onlyChars","withoutChars","keepUnique","default","salt","minLength","alphabet","seps","saltChars","alphabetChars","sepsChars","uniqueAlphabet","minAlphabetLength","Error","sepsLength","diff","_this$seps","filteredSeps","shuffle","sepDiv","Math","ceil","push","apply","slice","guardCount","guardDiv","guards","guardsRegExp","makeAnyCharRegExp","sepsRegExp","allowedCharsRegExp","makeEveryCharRegExp","concat","_proto","encode","first","_len","arguments","numbers","_key","ret","every","isIntegerNumber","map","n","safeParseInt10","String","isPositiveAndFinite","_encode","join","decode","id","_decode","encodeHex","hex","test","splitAtIntervalAndMap","part","parseInt","decodeHex","number","_this","numbersIdInt","reduce","last","Number","BigInt","lottery","forEach","_ret","buffer","toAlphabet","charCode","codePointAt","extraNumber","prefixGuardIndex","unshift","suffixGuardIndex","halfLength","floor","_ret2","_ret3","excess","halfOfExcess","isValidId","idGuardsArray","split","idBreakdown","lotteryChar","next","value","idArray","lastAlphabet","result","_iterator","_isArray","_i","_ref","done","subId","nextAlphabet","fromAlphabet","content","Set","chars","_withoutChars","filter","char","includes","keepChars","isNaN","isSafeInteger","integer","transformed","v","p","j","a","b","input","alphabetLength","inputChars","carry","item","index","indexOf","safeToParseNumberRegExp","str","NaN","nth","_","RegExp","escapeRegExp","sort","text","replace"],"mappings":"CAAA,SAAWA,EAAQC,GACjB,GAAsB,mBAAXC,QAAyBA,OAAOC,IACzCD,OAAO,UAAW,CAAC,WAAYD,QAC1B,GAAuB,oBAAZG,QAChBH,EAAQG,aACH,CACL,IAAIC,EAAM,CACRD,QAAS,IAEXH,EAAQI,EAAID,SACZJ,EAAOM,QAAUD,EAAID,SAVzB,CAYyB,oBAAfG,WAA6BA,WAA6B,oBAATC,KAAuBA,KAAOC,MAAM,SAAUC,GACvG,aAKA,SAASC,EAAmBC,GAAO,OAMnC,SAA4BA,GAAO,GAAIC,MAAMC,QAAQF,GAAM,CAAE,IAAK,IAAIG,EAAI,EAAGC,EAAO,IAAIH,MAAMD,EAAIK,QAASF,EAAIH,EAAIK,OAAQF,IAAOC,EAAKD,GAAKH,EAAIG,GAAM,OAAOC,GANnHE,CAAmBN,IAI7D,SAA0BO,GAAQ,GAAIC,OAAOC,YAAYC,OAAOH,IAAkD,uBAAzCG,OAAOC,UAAUC,SAASC,KAAKN,GAAgC,OAAON,MAAMa,KAAKP,GAJrFQ,CAAiBf,IAEtF,WAAgC,MAAM,IAAIgB,UAAU,mDAF0CC,GAH9F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,EAEP,GAAsB,mBAAXxB,OACT,OAAOA,OAAOwD,GAASxD,OAAO1D,EAAcvB,QAAUiF,OAAO0D,GAG7D,MAAM,IAAIhH,MAAM,gHAGnB,IAGDkH,EAA0B,cAE1BjF,EAAiB,SAAwBkF,GAC3C,OAAOD,EAAwBvE,KAAKwE,GAAOrE,SAASqE,EAAK,IAAMC,KAG7DxE,EAAwB,SAA+BuE,EAAKE,EAAKtF,GACnE,OAAO9D,MAAMa,KAAK,CAChBT,OAAQkC,KAAKC,KAAK2G,EAAI9I,OAASgJ,KAC9B,SAAUC,EAAGN,GACd,OAAOjF,EAAIoF,EAAIxG,MAAMqG,EAAQK,GAAML,EAAQ,GAAKK,QAIhDrG,EAAoB,SAA2B4E,GACjD,OAAO,IAAI2B,OAAO3B,EAAM7D,KAAI,SAAUgE,GACpC,OAAOyB,EAAazB,MAGrB0B,MAAK,SAAUhB,EAAGC,GACjB,OAAOA,EAAErI,OAASoI,EAAEpI,UACnBgE,KAAK,OAGNlB,EAAsB,SAA6ByE,GACrD,OAAO,IAAI2B,OAAO,KAAO3B,EAAM7D,KAAI,SAAUgE,GAC3C,OAAOyB,EAAazB,MAGrB0B,MAAK,SAAUhB,EAAGC,GACjB,OAAOA,EAAErI,OAASoI,EAAEpI,UACnBgE,KAAK,IAAM,QAGZmF,EAAe,SAAsBE,GACvC,OAAOA,EAAKC,QAAQ,2BAA4B"} \ No newline at end of file diff --git a/esm/index.js b/esm/index.js index 4dae568..154fee3 100644 --- a/esm/index.js +++ b/esm/index.js @@ -1,9 +1,3 @@ -function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); } - -function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } - -function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } - function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } @@ -32,7 +26,6 @@ function () { seps = 'cfhistuCFHISTU'; } - this.salt = salt; this.minLength = minLength; if (typeof minLength !== 'number') { @@ -47,7 +40,14 @@ function () { throw new TypeError("Hashids: Provided alphabet has to be a string (is " + typeof alphabet + ")"); } - var uniqueAlphabet = keepUniqueChars(alphabet); + var saltChars = _toConsumableArray(salt); + + var alphabetChars = _toConsumableArray(alphabet); + + var sepsChars = _toConsumableArray(seps); + + this.salt = saltChars; + var uniqueAlphabet = keepUnique(alphabetChars); if (uniqueAlphabet.length < minAlphabetLength) { throw new Error("Hashids: alphabet must contain at least " + minAlphabetLength + " unique characters, provided: " + uniqueAlphabet); @@ -55,34 +55,42 @@ function () { /** `alphabet` should not contains `seps` */ - this.alphabet = withoutChars(uniqueAlphabet, seps); + this.alphabet = withoutChars(uniqueAlphabet, sepsChars); /** `seps` should contain only characters present in `alphabet` */ - var filteredSeps = onlyChars(seps, uniqueAlphabet); - this.seps = shuffle(filteredSeps, salt); + var filteredSeps = onlyChars(sepsChars, uniqueAlphabet); + this.seps = shuffle(filteredSeps, saltChars); var sepsLength; var diff; - if (_toConsumableArray(this.seps).length === 0 || _toConsumableArray(this.alphabet).length / _toConsumableArray(this.seps).length > sepDiv) { - sepsLength = Math.ceil(_toConsumableArray(this.alphabet).length / sepDiv); + if (this.seps.length === 0 || this.alphabet.length / this.seps.length > sepDiv) { + sepsLength = Math.ceil(this.alphabet.length / sepDiv); + + if (sepsLength > this.seps.length) { + var _this$seps; - if (sepsLength > _toConsumableArray(this.seps).length) { - diff = sepsLength - _toConsumableArray(this.seps).length; - this.seps += unicodeSubstr(this.alphabet, 0, diff); - this.alphabet = unicodeSubstr(this.alphabet, diff); + diff = sepsLength - this.seps.length; + + (_this$seps = this.seps).push.apply(_this$seps, _toConsumableArray(this.alphabet.slice(0, diff))); + + this.alphabet = this.alphabet.slice(diff); } } - this.alphabet = shuffle(this.alphabet, salt); - var guardCount = Math.ceil(_toConsumableArray(this.alphabet).length / guardDiv); + this.alphabet = shuffle(this.alphabet, saltChars); + var guardCount = Math.ceil(this.alphabet.length / guardDiv); - if (_toConsumableArray(this.alphabet).length < 3) { - this.guards = unicodeSubstr(this.seps, 0, guardCount); - this.seps = unicodeSubstr(this.seps, guardCount); + if (this.alphabet.length < 3) { + this.guards = this.seps.slice(0, guardCount); + this.seps = this.seps.slice(guardCount); } else { - this.guards = unicodeSubstr(this.alphabet, 0, guardCount); - this.alphabet = unicodeSubstr(this.alphabet, guardCount); + this.guards = this.alphabet.slice(0, guardCount); + this.alphabet = this.alphabet.slice(guardCount); } + + this.guardsRegExp = makeAnyCharRegExp(this.guards); + this.sepsRegExp = makeAnyCharRegExp(this.seps); + this.allowedCharsRegExp = makeEveryCharRegExp([].concat(_toConsumableArray(this.alphabet), _toConsumableArray(this.guards), _toConsumableArray(this.seps))); } var _proto = Hashids.prototype; @@ -115,7 +123,7 @@ function () { return ret; } - return this._encode(numbers); + return this._encode(numbers).join(''); }; _proto.decode = function decode(id) { @@ -168,50 +176,57 @@ function () { _proto._encode = function _encode(numbers) { var _this = this; - var ret; var alphabet = this.alphabet; var numbersIdInt = numbers.reduce(function (last, number, i) { return last + (typeof number === 'bigint' ? Number(number % BigInt(i + 100)) : number % (i + 100)); }, 0); - ret = _toConsumableArray(alphabet)[numbersIdInt % _toConsumableArray(alphabet).length]; - var lottery = ret; - - var seps = _toConsumableArray(this.seps); + var ret = [alphabet[numbersIdInt % alphabet.length]]; + var lottery = ret.slice(); + var seps = this.seps; + var guards = this.guards; + numbers.forEach(function (number, i) { + var _ret; - var guards = _toConsumableArray(this.guards); + var buffer = lottery.concat(_this.salt, alphabet); // const buffer = [...lottery, ...this.salt, ...alphabet] - numbers.forEach(function (number, i) { - var buffer = lottery + _this.salt + alphabet; - alphabet = shuffle(alphabet, unicodeSubstr(buffer, 0)); + alphabet = shuffle(alphabet, buffer); var last = toAlphabet(number, alphabet); - ret += last; + + (_ret = ret).push.apply(_ret, _toConsumableArray(last)); if (i + 1 < numbers.length) { - var charCode = last.codePointAt(0) + i; + var charCode = last[0].codePointAt(0) + i; var extraNumber = typeof number === 'bigint' ? Number(number % BigInt(charCode)) : number % charCode; - ret += seps[extraNumber % seps.length]; + ret.push(seps[extraNumber % seps.length]); } }); - if (_toConsumableArray(ret).length < this.minLength) { - var prefixGuardIndex = (numbersIdInt + _toConsumableArray(ret)[0].codePointAt(0)) % guards.length; - ret = guards[prefixGuardIndex] + ret; + if (ret.length < this.minLength) { + var prefixGuardIndex = (numbersIdInt + ret[0].codePointAt(0)) % guards.length; + ret.unshift(guards[prefixGuardIndex]); - if (_toConsumableArray(ret).length < this.minLength) { - var suffixGuardIndex = (numbersIdInt + _toConsumableArray(ret)[2].codePointAt(0)) % guards.length; - ret = ret + guards[suffixGuardIndex]; + if (ret.length < this.minLength) { + var suffixGuardIndex = (numbersIdInt + ret[2].codePointAt(0)) % guards.length; + ret.push(guards[suffixGuardIndex]); } } - var halfLength = Math.floor(_toConsumableArray(alphabet).length / 2); + var halfLength = Math.floor(alphabet.length / 2); + + while (ret.length < this.minLength) { + var _ret2, _ret3; - while (_toConsumableArray(ret).length < this.minLength) { alphabet = shuffle(alphabet, alphabet); - ret = unicodeSubstr(alphabet, halfLength) + ret + unicodeSubstr(alphabet, 0, halfLength); - var excess = _toConsumableArray(ret).length - this.minLength; + + (_ret2 = ret).unshift.apply(_ret2, _toConsumableArray(alphabet.slice(halfLength))); + + (_ret3 = ret).push.apply(_ret3, _toConsumableArray(alphabet.slice(0, halfLength))); + + var excess = ret.length - this.minLength; if (excess > 0) { - ret = unicodeSubstr(ret, excess / 2, this.minLength); + var halfOfExcess = excess / 2; + ret = ret.slice(halfOfExcess, halfOfExcess + this.minLength); } } @@ -219,55 +234,61 @@ function () { }; _proto.isValidId = function isValidId(id) { - var _this2 = this; - - return _toConsumableArray(id).every(function (char) { - return _this2.alphabet.includes(char) || _this2.guards.includes(char) || _this2.seps.includes(char); - }); - }; + return this.allowedCharsRegExp.test(id); // return this._isValidId([...id]) + } // private _isValidId(idChars: string[]): boolean { + // return idChars.every( + // (char) => + // this.alphabet.includes(char) || + // this.guards.includes(char) || + // this.seps.includes(char), + // ) + // } + ; _proto._decode = function _decode(id) { - var _this3 = this; - if (!this.isValidId(id)) { - throw new Error("The provided ID (" + id + ") is invalid, as it contains characters that do not exist in the alphabet (" + this.guards + this.seps + this.alphabet + ")"); + throw new Error("The provided ID (" + id + ") is invalid, as it contains characters that do not exist in the alphabet (" + this.guards.join('') + this.seps.join('') + this.alphabet.join('') + ")"); } - var idGuardsArray = splitAtMatch(id, function (char) { - return _this3.guards.includes(char); - }); + var idGuardsArray = id.split(this.guardsRegExp); // splitAtMatch(idChars, (char) => + // this.guards.includes(char), + // ) + var splitIndex = idGuardsArray.length === 3 || idGuardsArray.length === 2 ? 1 : 0; var idBreakdown = idGuardsArray[splitIndex]; + if (idBreakdown.length === 0) return []; + var lotteryChar = idBreakdown[Symbol.iterator]().next().value; + var idArray = idBreakdown.slice(lotteryChar.length).split(this.sepsRegExp); // const idBreakdownArray = [...idBreakdown] + // const [lotteryChar, ...rest] = idBreakdownArray + // const idArray = rest.join('').split(this.sepsRegExp) + + var lastAlphabet = this.alphabet; + var result = []; + + for (var _iterator = idArray, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; - var idBreakdownArray = _toConsumableArray(idBreakdown); + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } - if (idBreakdownArray.length === 0) return []; + var subId = _ref; + var buffer = [lotteryChar].concat(_toConsumableArray(this.salt), _toConsumableArray(lastAlphabet)); + var nextAlphabet = shuffle(lastAlphabet, buffer.slice(0, lastAlphabet.length)); + result.push(fromAlphabet(_toConsumableArray(subId), nextAlphabet)); + lastAlphabet = nextAlphabet; + } // if the result is different from what we'd expect, we return an empty result (malformed input): - var _idBreakdownArray = _toArray(idBreakdownArray), - lotteryChar = _idBreakdownArray[0], - chars = _idBreakdownArray.slice(1); - var rest = chars.join(''); - var idArray = splitAtMatch(rest, function (char) { - return _this3.seps.includes(char); - }); + if (this._encode(result).join('') !== id) return []; // if (this._encode(result).some((char, index) => idChars[index] !== char)) { + // return [] + // } - var _idArray$reduce = idArray.reduce(function (_ref, subId) { - var result = _ref.result, - lastAlphabet = _ref.lastAlphabet; - var buffer = lotteryChar + _this3.salt + lastAlphabet; - var nextAlphabet = shuffle(lastAlphabet, unicodeSubstr(buffer, 0, _toConsumableArray(lastAlphabet).length)); - return { - result: [].concat(_toConsumableArray(result), [fromAlphabet(subId, nextAlphabet)]), - lastAlphabet: nextAlphabet - }; - }, { - result: [], - lastAlphabet: this.alphabet - }), - result = _idArray$reduce.result; - - if (this._encode(result) !== id) return []; return result; }; @@ -278,36 +299,18 @@ export { Hashids as default }; var minAlphabetLength = 16; var sepDiv = 3.5; var guardDiv = 12; -export var keepUniqueChars = function keepUniqueChars(str) { - return Array.from(new Set(str)).join(''); +export var keepUnique = function keepUnique(content) { + return Array.from(new Set(content)); }; -export var withoutChars = function withoutChars(_ref2, _ref3) { - var _ref4 = _toArray(_ref2), - str = _ref4.slice(0); - - var _ref5 = _toArray(_ref3), - without = _ref5.slice(0); - - return str.filter(function (char) { - return !without.includes(char); - }).join(''); -}; -export var onlyChars = function onlyChars(_ref6, _ref7) { - var _ref8 = _toArray(_ref6), - str = _ref8.slice(0); - - var _ref9 = _toArray(_ref7), - only = _ref9.slice(0); - - return str.filter(function (char) { - return only.includes(char); - }).join(''); +export var withoutChars = function withoutChars(chars, _withoutChars) { + return chars.filter(function (char) { + return !_withoutChars.includes(char); + }); }; -export var unicodeSubstr = function unicodeSubstr(_ref10, from, to) { - var _ref11 = _toArray(_ref10), - str = _ref11.slice(0); - - return str.slice(from, to === undefined ? undefined : from + to).join(''); +export var onlyChars = function onlyChars(chars, keepChars) { + return chars.filter(function (char) { + return keepChars.includes(char); + }); }; var isIntegerNumber = function isIntegerNumber(n) { @@ -318,84 +321,68 @@ var isPositiveAndFinite = function isPositiveAndFinite(n) { return typeof n === 'bigint' || n >= 0 && Number.isSafeInteger(n); }; -function shuffle(alphabet, _ref12) { - var _ref13 = _toArray(_ref12), - salt = _ref13.slice(0); +function shuffle(alphabetChars, saltChars) { + if (saltChars.length === 0) { + return alphabetChars; + } var integer; + var transformed = alphabetChars.slice(); - if (!salt.length) { - return alphabet; - } - - var alphabetChars = _toConsumableArray(alphabet); + for (var i = transformed.length - 1, v = 0, p = 0; i > 0; i--, v++) { + v %= saltChars.length; + p += integer = saltChars[v].codePointAt(0); + var j = (integer + v + p) % i; // swap characters at positions i and j - for (var i = alphabetChars.length - 1, v = 0, p = 0; i > 0; i--, v++) { - v %= salt.length; - p += integer = salt[v].codePointAt(0); - var j = (integer + v + p) % i // swap characters at positions i and j - ; - var _ref14 = [alphabetChars[i], alphabetChars[j]]; - alphabetChars[j] = _ref14[0]; - alphabetChars[i] = _ref14[1]; + var a = transformed[i]; + var b = transformed[j]; + transformed[j] = a; + transformed[i] = b; } - return alphabetChars.join(''); + return transformed; } -var toAlphabet = function toAlphabet(input, _ref15) { - var _ref16 = _toArray(_ref15), - alphabet = _ref16.slice(0); - - var id = ''; +var toAlphabet = function toAlphabet(input, alphabetChars) { + var id = []; if (typeof input === 'bigint') { - var alphabetLength = BigInt(alphabet.length); + var alphabetLength = BigInt(alphabetChars.length); do { - id = alphabet[Number(input % alphabetLength)] + id; + id.unshift(alphabetChars[Number(input % alphabetLength)]); input = input / alphabetLength; } while (input > BigInt(0)); } else { do { - id = alphabet[input % alphabet.length] + id; - input = Math.floor(input / alphabet.length); + id.unshift(alphabetChars[input % alphabetChars.length]); + input = Math.floor(input / alphabetChars.length); } while (input > 0); } return id; }; -var fromAlphabet = function fromAlphabet(_ref17, _ref18) { - var _ref19 = _toArray(_ref17), - input = _ref19.slice(0); - - var _ref20 = _toArray(_ref18), - alphabet = _ref20.slice(0); - - return input.map(function (item) { - var index = alphabet.indexOf(item); +var fromAlphabet = function fromAlphabet(inputChars, alphabetChars) { + return inputChars.reduce(function (carry, item) { + var index = alphabetChars.indexOf(item); if (index === -1) { - var inputString = input.join(''); - var alphabetString = alphabet.join(''); - throw new Error("The provided ID (" + inputString + ") is invalid, as it contains characters that do not exist in the alphabet (" + alphabetString + ")"); + throw new Error("The provided ID (" + inputChars.join('') + ") is invalid, as it contains characters that do not exist in the alphabet (" + alphabetChars.join('') + ")"); } - return index; - }).reduce(function (carry, index) { if (typeof carry === 'bigint') { - return carry * BigInt(alphabet.length) + BigInt(index); + return carry * BigInt(alphabetChars.length) + BigInt(index); } - var value = carry * alphabet.length + index; + var value = carry * alphabetChars.length + index; var isSafeValue = Number.isSafeInteger(value); if (isSafeValue) { return value; } else { if (typeof BigInt === 'function') { - return BigInt(carry) * BigInt(alphabet.length) + BigInt(index); + return BigInt(carry) * BigInt(alphabetChars.length) + BigInt(index); } else { // we do not have support for BigInt: throw new Error("Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment"); @@ -404,22 +391,11 @@ var fromAlphabet = function fromAlphabet(_ref17, _ref18) { }, 0); }; -var splitAtMatch = function splitAtMatch(_ref21, match) { - var _ref22 = _toArray(_ref21), - chars = _ref22.slice(0); - - return chars.reduce(function (groups, char) { - return match(char) ? [].concat(_toConsumableArray(groups), ['']) : [].concat(_toConsumableArray(groups.slice(0, -1)), [groups[groups.length - 1] + char]); - }, ['']); -}; - var safeToParseNumberRegExp = /^\+?[0-9]+$/; var safeParseInt10 = function safeParseInt10(str) { return safeToParseNumberRegExp.test(str) ? parseInt(str, 10) : NaN; }; -/** note: this doesn't need to support unicode, since it's used to split hex strings only */ - var splitAtIntervalAndMap = function splitAtIntervalAndMap(str, nth, map) { return Array.from({ @@ -429,4 +405,28 @@ var splitAtIntervalAndMap = function splitAtIntervalAndMap(str, nth, map) { }); }; +var makeAnyCharRegExp = function makeAnyCharRegExp(chars) { + return new RegExp(chars.map(function (char) { + return escapeRegExp(char); + }) // we need to sort these from longest to shortest, + // as they may contain multibyte unicode characters (these should come first) + .sort(function (a, b) { + return b.length - a.length; + }).join('|')); +}; + +var makeEveryCharRegExp = function makeEveryCharRegExp(chars) { + return new RegExp("^[" + chars.map(function (char) { + return escapeRegExp(char); + }) // we need to sort these from longest to shortest, + // as they may contain multibyte unicode characters (these should come first) + .sort(function (a, b) { + return b.length - a.length; + }).join('') + "]+$"); +}; + +var escapeRegExp = function escapeRegExp(text) { + return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); +}; + //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/esm/index.js.map b/esm/index.js.map index 663193c..95e9df6 100644 --- a/esm/index.js.map +++ b/esm/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../lib/hashids.ts"],"names":[],"mappings":";;;;;;;;;;;;;;IAEqB,O;;;AAKnB,mBACU,IADV,EAEU,SAFV,EAGE,QAHF,EAIE,IAJF,EAKE;AAAA,QAJQ,IAIR;AAJQ,MAAA,IAIR,GAJe,EAIf;AAAA;;AAAA,QAHQ,SAGR;AAHQ,MAAA,SAGR,GAHoB,CAGpB;AAAA;;AAAA,QAFA,QAEA;AAFA,MAAA,QAEA,GAFW,gEAEX;AAAA;;AAAA,QADA,IACA;AADA,MAAA,IACA,GADO,gBACP;AAAA;;AAAA,SAJQ,IAIR,GAJQ,IAIR;AAAA,SAHQ,SAGR,GAHQ,SAGR;;AACA,QAAI,OAAO,SAAP,KAAqB,QAAzB,EAAmC;AACjC,YAAM,IAAI,SAAJ,2DACoD,OAAO,SAD3D,OAAN;AAGD;;AACD,QAAI,OAAO,IAAP,KAAgB,QAApB,EAA8B;AAC5B,YAAM,IAAI,SAAJ,sDAC+C,OAAO,IADtD,OAAN;AAGD;;AACD,QAAI,OAAO,QAAP,KAAoB,QAAxB,EAAkC;AAChC,YAAM,IAAI,SAAJ,wDACiD,OAAO,QADxD,OAAN;AAGD;;AAED,QAAM,cAAc,GAAG,eAAe,CAAC,QAAD,CAAtC;;AAEA,QAAI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AAN,CAAqB;AAAC,IAAA,MAAM,EAAE,IAAI,CAAC,IAAL,CAAU,GAAG,CAAC,MAAJ,GAAa,GAAvB;AAAT,GAArB,EAA4D,UAAC,CAAD,EAAI,KAAJ;AAAA,WAC1D,GAAG,CAAC,GAAG,CAAC,KAAJ,CAAU,KAAK,GAAG,GAAlB,EAAuB,CAAC,KAAK,GAAG,CAAT,IAAc,GAArC,CAAD,CADuD;AAAA,GAA5D,CAL4B;AAAA,CAA9B","file":"index.js","sourcesContent":["type NumberLike = number | bigint\n\nexport default class Hashids {\n private alphabet: string\n private seps: string\n private guards: string\n\n public constructor(\n private salt = '',\n private minLength = 0,\n alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',\n seps = 'cfhistuCFHISTU',\n ) {\n if (typeof minLength !== 'number') {\n throw new TypeError(\n `Hashids: Provided 'minLength' has to be a number (is ${typeof minLength})`,\n )\n }\n if (typeof salt !== 'string') {\n throw new TypeError(\n `Hashids: Provided 'salt' has to be a string (is ${typeof salt})`,\n )\n }\n if (typeof alphabet !== 'string') {\n throw new TypeError(\n `Hashids: Provided alphabet has to be a string (is ${typeof alphabet})`,\n )\n }\n\n const uniqueAlphabet = keepUniqueChars(alphabet)\n\n if (uniqueAlphabet.length < minAlphabetLength) {\n throw new Error(\n `Hashids: alphabet must contain at least ${minAlphabetLength} unique characters, provided: ${uniqueAlphabet}`,\n )\n }\n\n /** `alphabet` should not contains `seps` */\n this.alphabet = withoutChars(uniqueAlphabet, seps)\n /** `seps` should contain only characters present in `alphabet` */\n const filteredSeps = onlyChars(seps, uniqueAlphabet)\n this.seps = shuffle(filteredSeps, salt)\n\n let sepsLength\n let diff\n\n if (\n [...this.seps].length === 0 ||\n [...this.alphabet].length / [...this.seps].length > sepDiv\n ) {\n sepsLength = Math.ceil([...this.alphabet].length / sepDiv)\n\n if (sepsLength > [...this.seps].length) {\n diff = sepsLength - [...this.seps].length\n this.seps += unicodeSubstr(this.alphabet, 0, diff)\n this.alphabet = unicodeSubstr(this.alphabet, diff)\n }\n }\n\n this.alphabet = shuffle(this.alphabet, salt)\n const guardCount = Math.ceil([...this.alphabet].length / guardDiv)\n\n if ([...this.alphabet].length < 3) {\n this.guards = unicodeSubstr(this.seps, 0, guardCount)\n this.seps = unicodeSubstr(this.seps, guardCount)\n } else {\n this.guards = unicodeSubstr(this.alphabet, 0, guardCount)\n this.alphabet = unicodeSubstr(this.alphabet, guardCount)\n }\n }\n\n public encode(numbers: string): string\n public encode(numbers: NumberLike[]): string\n public encode(...numbers: NumberLike[]): string\n public encode(numbers: string[]): string\n public encode(...numbers: string[]): string\n public encode(\n first: T[] | T,\n ...numbers: T[]\n ): string {\n const ret = ''\n\n if (Array.isArray(first)) {\n numbers = first\n } else {\n // eslint-disable-next-line eqeqeq\n numbers = [...(first != null ? [first] : []), ...numbers]\n }\n\n if (!numbers.length) {\n return ret\n }\n\n if (!numbers.every(isIntegerNumber)) {\n numbers = numbers.map((n) =>\n typeof n === 'bigint' || typeof n === 'number'\n ? n\n : safeParseInt10(String(n)),\n ) as T[]\n }\n\n if (!(numbers as NumberLike[]).every(isPositiveAndFinite)) {\n return ret\n }\n\n return this._encode(numbers as number[])\n }\n\n public decode(id: string): NumberLike[] {\n if (!id || typeof id !== 'string' || id.length === 0) return []\n return this._decode(id)\n }\n\n /**\n * @description Splits a hex string into groups of 12-digit hexadecimal numbers,\n * then prefixes each with '1' and encodes the resulting array of numbers\n *\n * Encoding '00000000000f00000000000f000f' would be the equivalent of:\n * Hashids.encode([0x100000000000f, 0x100000000000f, 0x1000f])\n *\n * This means that if your environment supports BigInts,\n * you will get different (shorter) results if you provide\n * a BigInt representation of your hex and use `encode` directly, e.g.:\n * Hashids.encode(BigInt(`0x${hex}`))\n *\n * To decode such a representation back to a hex string, use the following snippet:\n * Hashids.decode(id)[0].toString(16)\n */\n public encodeHex(hex: string | bigint): string {\n switch (typeof hex) {\n case 'bigint':\n hex = hex.toString(16)\n break\n case 'string':\n if (!/^[0-9a-fA-F]+$/.test(hex)) return ''\n break\n default:\n throw new Error(\n `Hashids: The provided value is neither a string, nor a BigInt (got: ${typeof hex})`,\n )\n }\n\n const numbers = splitAtIntervalAndMap(hex, 12, (part) =>\n parseInt(`1${part}`, 16),\n )\n return this.encode(numbers)\n }\n\n public decodeHex(id: string) {\n return this.decode(id)\n .map((number) => number.toString(16).slice(1))\n .join('')\n }\n\n private _encode(numbers: NumberLike[]): string {\n let ret: string\n let alphabet = this.alphabet\n\n const numbersIdInt = numbers.reduce(\n (last, number, i) =>\n last +\n (typeof number === 'bigint'\n ? Number(number % BigInt(i + 100))\n : number % (i + 100)),\n 0,\n )\n\n ret = [...alphabet][numbersIdInt % [...alphabet].length]\n const lottery = ret\n\n const seps = [...this.seps]\n const guards = [...this.guards]\n\n numbers.forEach((number, i) => {\n const buffer = lottery + this.salt + alphabet\n\n alphabet = shuffle(alphabet, unicodeSubstr(buffer, 0))\n const last = toAlphabet(number, alphabet)\n\n ret += last\n\n if (i + 1 < numbers.length) {\n const charCode = last.codePointAt(0)! + i\n const extraNumber =\n typeof number === 'bigint'\n ? Number(number % BigInt(charCode))\n : number % charCode\n ret += seps[extraNumber % seps.length]\n }\n })\n\n if ([...ret].length < this.minLength) {\n const prefixGuardIndex =\n (numbersIdInt + [...ret][0].codePointAt(0)!) % guards.length\n ret = guards[prefixGuardIndex] + ret\n\n if ([...ret].length < this.minLength) {\n const suffixGuardIndex =\n (numbersIdInt + [...ret][2].codePointAt(0)!) % guards.length\n ret = ret + guards[suffixGuardIndex]\n }\n }\n\n const halfLength = Math.floor([...alphabet].length / 2)\n while ([...ret].length < this.minLength) {\n alphabet = shuffle(alphabet, alphabet)\n ret =\n unicodeSubstr(alphabet, halfLength) +\n ret +\n unicodeSubstr(alphabet, 0, halfLength)\n\n const excess = [...ret].length - this.minLength\n if (excess > 0) {\n ret = unicodeSubstr(ret, excess / 2, this.minLength)\n }\n }\n\n return ret\n }\n\n public isValidId(id: string): boolean {\n return [...id].every(\n (char) =>\n this.alphabet.includes(char) ||\n this.guards.includes(char) ||\n this.seps.includes(char),\n )\n }\n\n private _decode(id: string): NumberLike[] {\n if (!this.isValidId(id)) {\n throw new Error(\n `The provided ID (${id}) is invalid, as it contains characters that do not exist in the alphabet (${this.guards}${this.seps}${this.alphabet})`,\n )\n }\n const idGuardsArray = splitAtMatch(id, (char) => this.guards.includes(char))\n const splitIndex =\n idGuardsArray.length === 3 || idGuardsArray.length === 2 ? 1 : 0\n\n const idBreakdown = idGuardsArray[splitIndex]\n const idBreakdownArray = [...idBreakdown]\n if (idBreakdownArray.length === 0) return []\n\n const [lotteryChar, ...chars] = idBreakdownArray\n const rest = chars.join('')\n const idArray = splitAtMatch(rest, (char) => this.seps.includes(char))\n\n const {result} = idArray.reduce(\n ({result, lastAlphabet}, subId) => {\n const buffer = lotteryChar + this.salt + lastAlphabet\n const nextAlphabet = shuffle(\n lastAlphabet,\n unicodeSubstr(buffer, 0, [...lastAlphabet].length),\n )\n return {\n result: [...result, fromAlphabet(subId, nextAlphabet)],\n lastAlphabet: nextAlphabet,\n }\n },\n {result: [] as NumberLike[], lastAlphabet: this.alphabet},\n )\n\n if (this._encode(result) !== id) return []\n return result\n }\n}\n\nconst minAlphabetLength = 16\nconst sepDiv = 3.5\nconst guardDiv = 12\n\nexport const keepUniqueChars = (str: string) =>\n Array.from(new Set(str)).join('')\n\nexport const withoutChars = ([...str]: string, [...without]: string) =>\n str.filter((char) => !without.includes(char)).join('')\n\nexport const onlyChars = ([...str]: string, [...only]: string) =>\n str.filter((char) => only.includes(char)).join('')\n\nexport const unicodeSubstr = ([...str]: string, from: number, to?: number) =>\n str.slice(from, to === undefined ? undefined : from + to).join('')\n\nconst isIntegerNumber = (n: NumberLike | string) =>\n typeof n === 'bigint' ||\n (!Number.isNaN(Number(n)) && Math.floor(Number(n)) === n)\n\nconst isPositiveAndFinite = (n: NumberLike) =>\n typeof n === 'bigint' || (n >= 0 && Number.isSafeInteger(n))\n\nfunction shuffle(alphabet: string, [...salt]: string) {\n let integer: number\n\n if (!salt.length) {\n return alphabet\n }\n\n const alphabetChars = [...alphabet]\n\n for (let i = alphabetChars.length - 1, v = 0, p = 0; i > 0; i--, v++) {\n v %= salt.length\n p += integer = salt[v].codePointAt(0)!\n const j = (integer + v + p) % i\n\n // swap characters at positions i and j\n ;[alphabetChars[j], alphabetChars[i]] = [alphabetChars[i], alphabetChars[j]]\n }\n\n return alphabetChars.join('')\n}\n\nconst toAlphabet = (input: NumberLike, [...alphabet]: string) => {\n let id = ''\n\n if (typeof input === 'bigint') {\n const alphabetLength = BigInt(alphabet.length)\n do {\n id = alphabet[Number(input % alphabetLength)] + id\n input = input / alphabetLength\n } while (input > BigInt(0))\n } else {\n do {\n id = alphabet[input % alphabet.length] + id\n input = Math.floor(input / alphabet.length)\n } while (input > 0)\n }\n\n return id\n}\n\nconst fromAlphabet = ([...input]: string, [...alphabet]: string) =>\n input\n .map((item) => {\n const index = alphabet.indexOf(item)\n if (index === -1) {\n const inputString = input.join('')\n const alphabetString = alphabet.join('')\n throw new Error(\n `The provided ID (${inputString}) is invalid, as it contains characters that do not exist in the alphabet (${alphabetString})`,\n )\n }\n return index\n })\n .reduce(\n (carry, index) => {\n if (typeof carry === 'bigint') {\n return carry * BigInt(alphabet.length) + BigInt(index)\n }\n const value = carry * alphabet.length + index\n const isSafeValue = Number.isSafeInteger(value)\n if (isSafeValue) {\n return value\n } else {\n if (typeof BigInt === 'function') {\n return BigInt(carry) * BigInt(alphabet.length) + BigInt(index)\n } else {\n // we do not have support for BigInt:\n throw new Error(\n `Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment`,\n )\n }\n }\n },\n 0 as NumberLike,\n )\n\nconst splitAtMatch = ([...chars]: string, match: (char: string) => boolean) =>\n chars.reduce(\n (groups, char) =>\n match(char)\n ? [...groups, '']\n : [...groups.slice(0, -1), groups[groups.length - 1] + char],\n [''],\n )\n\nconst safeToParseNumberRegExp = /^\\+?[0-9]+$/\nconst safeParseInt10 = (str: string) =>\n safeToParseNumberRegExp.test(str) ? parseInt(str, 10) : NaN\n\n/** note: this doesn't need to support unicode, since it's used to split hex strings only */\nconst splitAtIntervalAndMap = (\n str: string,\n nth: number,\n map: (n: string) => T,\n): T[] =>\n Array.from({length: Math.ceil(str.length / nth)}, (_, index) =>\n map(str.slice(index * nth, (index + 1) * nth)),\n )\n"]} \ No newline at end of file +{"version":3,"sources":["../lib/hashids.ts"],"names":[],"mappings":";;;;;;;;IAEqB,O;;;AASnB,mBACE,IADF,EAEU,SAFV,EAGE,QAHF,EAIE,IAJF,EAKE;AAAA,QAJA,IAIA;AAJA,MAAA,IAIA,GAJO,EAIP;AAAA;;AAAA,QAHQ,SAGR;AAHQ,MAAA,SAGR,GAHoB,CAGpB;AAAA;;AAAA,QAFA,QAEA;AAFA,MAAA,QAEA,GAFW,gEAEX;AAAA;;AAAA,QADA,IACA;AADA,MAAA,IACA,GADO,gBACP;AAAA;;AAAA,SAHQ,SAGR,GAHQ,SAGR;;AACA,QAAI,OAAO,SAAP,KAAqB,QAAzB,EAAmC;AACjC,YAAM,IAAI,SAAJ,2DACoD,OAAO,SAD3D,OAAN;AAGD;;AACD,QAAI,OAAO,IAAP,KAAgB,QAApB,EAA8B;AAC5B,YAAM,IAAI,SAAJ,sDAC+C,OAAO,IADtD,OAAN;AAGD;;AACD,QAAI,OAAO,QAAP,KAAoB,QAAxB,EAAkC;AAChC,YAAM,IAAI,SAAJ,wDACiD,OAAO,QADxD,OAAN;AAGD;;AAED,QAAM,SAAS,sBAAO,IAAP,CAAf;;AACA,QAAM,aAAa,sBAAO,QAAP,CAAnB;;AACA,QAAM,SAAS,sBAAO,IAAP,CAAf;;AAEA,SAAK,IAAL,GAAY,SAAZ;AAEA,QAAM,cAAc,GAAG,UAAU,CAAC,aAAD,CAAjC;;AAEA,QAAI,cAAc,CAAC,MAAf,GAAwB,iBAA5B,EAA+C;AAC7C,YAAM,IAAI,KAAJ,8CACuC,iBADvC,s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Y,GAAG,SAAf,YAAe,CAAC,IAAD;AAAA,SACnB,IAAI,CAAC,OAAL,CAAa,0BAAb,EAAyC,MAAzC,CADmB;AAAA,CAArB","file":"index.js","sourcesContent":["type NumberLike = number | bigint\n\nexport default class Hashids {\n private alphabet: string[]\n private seps: string[]\n private guards: string[]\n private salt: string[]\n private guardsRegExp: RegExp\n private sepsRegExp: RegExp\n private allowedCharsRegExp: RegExp\n\n public constructor(\n salt = '',\n private minLength = 0,\n alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',\n seps = 'cfhistuCFHISTU',\n ) {\n if (typeof minLength !== 'number') {\n throw new TypeError(\n `Hashids: Provided 'minLength' has to be a number (is ${typeof minLength})`,\n )\n }\n if (typeof salt !== 'string') {\n throw new TypeError(\n `Hashids: Provided 'salt' has to be a string (is ${typeof salt})`,\n )\n }\n if (typeof alphabet !== 'string') {\n throw new TypeError(\n `Hashids: Provided alphabet has to be a string (is ${typeof alphabet})`,\n )\n }\n\n const saltChars = [...salt]\n const alphabetChars = [...alphabet]\n const sepsChars = [...seps]\n\n this.salt = saltChars\n\n const uniqueAlphabet = keepUnique(alphabetChars)\n\n if (uniqueAlphabet.length < minAlphabetLength) {\n throw new Error(\n `Hashids: alphabet must contain at least ${minAlphabetLength} unique characters, provided: ${uniqueAlphabet}`,\n )\n }\n\n /** `alphabet` should not contains `seps` */\n this.alphabet = withoutChars(uniqueAlphabet, sepsChars)\n /** `seps` should contain only characters present in `alphabet` */\n const filteredSeps = onlyChars(sepsChars, uniqueAlphabet)\n this.seps = shuffle(filteredSeps, saltChars)\n\n let sepsLength\n let diff\n\n if (\n this.seps.length === 0 ||\n this.alphabet.length / this.seps.length > sepDiv\n ) {\n sepsLength = Math.ceil(this.alphabet.length / sepDiv)\n\n if (sepsLength > this.seps.length) {\n diff = sepsLength - this.seps.length\n this.seps.push(...this.alphabet.slice(0, diff))\n this.alphabet = this.alphabet.slice(diff)\n }\n }\n\n this.alphabet = shuffle(this.alphabet, saltChars)\n const guardCount = Math.ceil(this.alphabet.length / guardDiv)\n\n if (this.alphabet.length < 3) {\n this.guards = this.seps.slice(0, guardCount)\n this.seps = this.seps.slice(guardCount)\n } else {\n this.guards = this.alphabet.slice(0, guardCount)\n this.alphabet = this.alphabet.slice(guardCount)\n }\n\n this.guardsRegExp = makeAnyCharRegExp(this.guards)\n this.sepsRegExp = makeAnyCharRegExp(this.seps)\n this.allowedCharsRegExp = makeEveryCharRegExp([\n ...this.alphabet,\n ...this.guards,\n ...this.seps,\n ])\n }\n\n public encode(numbers: string): string\n public encode(numbers: NumberLike[]): string\n public encode(...numbers: NumberLike[]): string\n public encode(numbers: string[]): string\n public encode(...numbers: string[]): string\n public encode(\n first: T[] | T,\n ...numbers: T[]\n ): string {\n const ret = ''\n\n if (Array.isArray(first)) {\n numbers = first\n } else {\n // eslint-disable-next-line eqeqeq\n numbers = [...(first != null ? [first] : []), ...numbers]\n }\n\n if (!numbers.length) {\n return ret\n }\n\n if (!numbers.every(isIntegerNumber)) {\n numbers = numbers.map((n) =>\n typeof n === 'bigint' || typeof n === 'number'\n ? n\n : safeParseInt10(String(n)),\n ) as T[]\n }\n\n if (!(numbers as NumberLike[]).every(isPositiveAndFinite)) {\n return ret\n }\n\n return this._encode(numbers as number[]).join('')\n }\n\n public decode(id: string): NumberLike[] {\n if (!id || typeof id !== 'string' || id.length === 0) return []\n return this._decode(id)\n }\n\n /**\n * @description Splits a hex string into groups of 12-digit hexadecimal numbers,\n * then prefixes each with '1' and encodes the resulting array of numbers\n *\n * Encoding '00000000000f00000000000f000f' would be the equivalent of:\n * Hashids.encode([0x100000000000f, 0x100000000000f, 0x1000f])\n *\n * This means that if your environment supports BigInts,\n * you will get different (shorter) results if you provide\n * a BigInt representation of your hex and use `encode` directly, e.g.:\n * Hashids.encode(BigInt(`0x${hex}`))\n *\n * To decode such a representation back to a hex string, use the following snippet:\n * Hashids.decode(id)[0].toString(16)\n */\n public encodeHex(hex: string | bigint): string {\n switch (typeof hex) {\n case 'bigint':\n hex = hex.toString(16)\n break\n case 'string':\n if (!/^[0-9a-fA-F]+$/.test(hex)) return ''\n break\n default:\n throw new Error(\n `Hashids: The provided value is neither a string, nor a BigInt (got: ${typeof hex})`,\n )\n }\n\n const numbers = splitAtIntervalAndMap(hex, 12, (part) =>\n parseInt(`1${part}`, 16),\n )\n return this.encode(numbers)\n }\n\n public decodeHex(id: string) {\n return this.decode(id)\n .map((number) => number.toString(16).slice(1))\n .join('')\n }\n\n private _encode(numbers: NumberLike[]): string[] {\n let alphabet = this.alphabet\n\n const numbersIdInt = numbers.reduce(\n (last, number, i) =>\n last +\n (typeof number === 'bigint'\n ? Number(number % BigInt(i + 100))\n : number % (i + 100)),\n 0,\n )\n\n let ret: string[] = [alphabet[numbersIdInt % alphabet.length]]\n const lottery = ret.slice()\n\n const seps = this.seps\n const guards = this.guards\n\n numbers.forEach((number, i) => {\n const buffer = lottery.concat(this.salt, alphabet)\n // const buffer = [...lottery, ...this.salt, ...alphabet]\n\n alphabet = shuffle(alphabet, buffer)\n const last = toAlphabet(number, alphabet)\n\n ret.push(...last)\n\n if (i + 1 < numbers.length) {\n const charCode = last[0].codePointAt(0)! + i\n const extraNumber =\n typeof number === 'bigint'\n ? Number(number % BigInt(charCode))\n : number % charCode\n ret.push(seps[extraNumber % seps.length])\n }\n })\n\n if (ret.length < this.minLength) {\n const prefixGuardIndex =\n (numbersIdInt + ret[0].codePointAt(0)!) % guards.length\n ret.unshift(guards[prefixGuardIndex])\n\n if (ret.length < this.minLength) {\n const suffixGuardIndex =\n (numbersIdInt + ret[2].codePointAt(0)!) % guards.length\n ret.push(guards[suffixGuardIndex])\n }\n }\n\n const halfLength = Math.floor(alphabet.length / 2)\n while (ret.length < this.minLength) {\n alphabet = shuffle(alphabet, alphabet)\n ret.unshift(...alphabet.slice(halfLength))\n ret.push(...alphabet.slice(0, halfLength))\n\n const excess = ret.length - this.minLength\n if (excess > 0) {\n const halfOfExcess = excess / 2\n ret = ret.slice(halfOfExcess, halfOfExcess + this.minLength)\n }\n }\n\n return ret\n }\n\n public isValidId(id: string): boolean {\n return this.allowedCharsRegExp.test(id)\n // return this._isValidId([...id])\n }\n\n // private _isValidId(idChars: string[]): boolean {\n // return idChars.every(\n // (char) =>\n // this.alphabet.includes(char) ||\n // this.guards.includes(char) ||\n // this.seps.includes(char),\n // )\n // }\n\n private _decode(id: string): NumberLike[] {\n if (!this.isValidId(id)) {\n throw new Error(\n `The provided ID (${id}) is invalid, as it contains characters that do not exist in the alphabet (${this.guards.join(\n '',\n )}${this.seps.join('')}${this.alphabet.join('')})`,\n )\n }\n const idGuardsArray = id.split(this.guardsRegExp)\n // splitAtMatch(idChars, (char) =>\n // this.guards.includes(char),\n // )\n const splitIndex =\n idGuardsArray.length === 3 || idGuardsArray.length === 2 ? 1 : 0\n\n const idBreakdown = idGuardsArray[splitIndex]\n if (idBreakdown.length === 0) return []\n\n const lotteryChar = idBreakdown[Symbol.iterator]().next().value as string\n const idArray = idBreakdown.slice(lotteryChar.length).split(this.sepsRegExp)\n\n // const idBreakdownArray = [...idBreakdown]\n // const [lotteryChar, ...rest] = idBreakdownArray\n // const idArray = rest.join('').split(this.sepsRegExp)\n\n let lastAlphabet: string[] = this.alphabet\n const result: NumberLike[] = []\n\n for (const subId of idArray) {\n const buffer = [lotteryChar, ...this.salt, ...lastAlphabet]\n const nextAlphabet = shuffle(\n lastAlphabet,\n buffer.slice(0, lastAlphabet.length),\n )\n result.push(fromAlphabet([...subId], nextAlphabet))\n lastAlphabet = nextAlphabet\n }\n\n // if the result is different from what we'd expect, we return an empty result (malformed input):\n if (this._encode(result).join('') !== id) return []\n // if (this._encode(result).some((char, index) => idChars[index] !== char)) {\n // return []\n // }\n return result\n }\n}\n\nconst minAlphabetLength = 16\nconst sepDiv = 3.5\nconst guardDiv = 12\n\nexport const keepUnique = (content: Iterable): T[] =>\n Array.from(new Set(content))\n\nexport const withoutChars = (\n chars: string[],\n withoutChars: string[],\n): string[] => chars.filter((char) => !withoutChars.includes(char))\n\nexport const onlyChars = (chars: string[], keepChars: string[]): string[] =>\n chars.filter((char) => keepChars.includes(char))\n\nconst isIntegerNumber = (n: NumberLike | string) =>\n typeof n === 'bigint' ||\n (!Number.isNaN(Number(n)) && Math.floor(Number(n)) === n)\n\nconst isPositiveAndFinite = (n: NumberLike) =>\n typeof n === 'bigint' || (n >= 0 && Number.isSafeInteger(n))\n\nfunction shuffle(alphabetChars: string[], saltChars: string[]): string[] {\n if (saltChars.length === 0) {\n return alphabetChars\n }\n\n let integer: number\n const transformed = alphabetChars.slice()\n\n for (let i = transformed.length - 1, v = 0, p = 0; i > 0; i--, v++) {\n v %= saltChars.length\n p += integer = saltChars[v].codePointAt(0)!\n const j = (integer + v + p) % i\n\n // swap characters at positions i and j\n const a = transformed[i]\n const b = transformed[j]\n transformed[j] = a\n transformed[i] = b\n }\n\n return transformed\n}\n\nconst toAlphabet = (input: NumberLike, alphabetChars: string[]): string[] => {\n const id: string[] = []\n\n if (typeof input === 'bigint') {\n const alphabetLength = BigInt(alphabetChars.length)\n do {\n id.unshift(alphabetChars[Number(input % alphabetLength)])\n input = input / alphabetLength\n } while (input > BigInt(0))\n } else {\n do {\n id.unshift(alphabetChars[input % alphabetChars.length])\n input = Math.floor(input / alphabetChars.length)\n } while (input > 0)\n }\n\n return id\n}\n\nconst fromAlphabet = (\n inputChars: string[],\n alphabetChars: string[],\n): NumberLike =>\n inputChars.reduce((carry, item) => {\n const index = alphabetChars.indexOf(item)\n if (index === -1) {\n throw new Error(\n `The provided ID (${inputChars.join(\n '',\n )}) is invalid, as it contains characters that do not exist in the alphabet (${alphabetChars.join(\n '',\n )})`,\n )\n }\n if (typeof carry === 'bigint') {\n return carry * BigInt(alphabetChars.length) + BigInt(index)\n }\n const value = carry * alphabetChars.length + index\n const isSafeValue = Number.isSafeInteger(value)\n if (isSafeValue) {\n return value\n } else {\n if (typeof BigInt === 'function') {\n return BigInt(carry) * BigInt(alphabetChars.length) + BigInt(index)\n } else {\n // we do not have support for BigInt:\n throw new Error(\n `Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment`,\n )\n }\n }\n }, 0 as NumberLike)\n\nconst safeToParseNumberRegExp = /^\\+?[0-9]+$/\nconst safeParseInt10 = (str: string) =>\n safeToParseNumberRegExp.test(str) ? parseInt(str, 10) : NaN\n\nconst splitAtIntervalAndMap = (\n str: string,\n nth: number,\n map: (n: string) => T,\n): T[] =>\n Array.from({length: Math.ceil(str.length / nth)}, (_, index) =>\n map(str.slice(index * nth, (index + 1) * nth)),\n )\n\nconst makeAnyCharRegExp = (chars: string[]) =>\n new RegExp(\n chars\n .map((char) => escapeRegExp(char))\n // we need to sort these from longest to shortest,\n // as they may contain multibyte unicode characters (these should come first)\n .sort((a, b) => b.length - a.length)\n .join('|'),\n )\n\nconst makeEveryCharRegExp = (chars: string[]) =>\n new RegExp(\n `^[${chars\n .map((char) => escapeRegExp(char))\n // we need to sort these from longest to shortest,\n // as they may contain multibyte unicode characters (these should come first)\n .sort((a, b) => b.length - a.length)\n .join('')}]+$`,\n )\n\nconst escapeRegExp = (text: string) =>\n text.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&')\n"]} \ No newline at end of file diff --git a/lib/hashids.ts b/lib/hashids.ts index ba2b19f..10db305 100644 --- a/lib/hashids.ts +++ b/lib/hashids.ts @@ -1,12 +1,16 @@ type NumberLike = number | bigint export default class Hashids { - private alphabet: string - private seps: string - private guards: string + private alphabet: string[] + private seps: string[] + private guards: string[] + private salt: string[] + private guardsRegExp: RegExp + private sepsRegExp: RegExp + private allowedCharsRegExp: RegExp public constructor( - private salt = '', + salt = '', private minLength = 0, alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', seps = 'cfhistuCFHISTU', @@ -27,7 +31,13 @@ export default class Hashids { ) } - const uniqueAlphabet = keepUniqueChars(alphabet) + const saltChars = [...salt] + const alphabetChars = [...alphabet] + const sepsChars = [...seps] + + this.salt = saltChars + + const uniqueAlphabet = keepUnique(alphabetChars) if (uniqueAlphabet.length < minAlphabetLength) { throw new Error( @@ -36,37 +46,45 @@ export default class Hashids { } /** `alphabet` should not contains `seps` */ - this.alphabet = withoutChars(uniqueAlphabet, seps) + this.alphabet = withoutChars(uniqueAlphabet, sepsChars) /** `seps` should contain only characters present in `alphabet` */ - const filteredSeps = onlyChars(seps, uniqueAlphabet) - this.seps = shuffle(filteredSeps, salt) + const filteredSeps = onlyChars(sepsChars, uniqueAlphabet) + this.seps = shuffle(filteredSeps, saltChars) let sepsLength let diff if ( - [...this.seps].length === 0 || - [...this.alphabet].length / [...this.seps].length > sepDiv + this.seps.length === 0 || + this.alphabet.length / this.seps.length > sepDiv ) { - sepsLength = Math.ceil([...this.alphabet].length / sepDiv) + sepsLength = Math.ceil(this.alphabet.length / sepDiv) - if (sepsLength > [...this.seps].length) { - diff = sepsLength - [...this.seps].length - this.seps += unicodeSubstr(this.alphabet, 0, diff) - this.alphabet = unicodeSubstr(this.alphabet, diff) + if (sepsLength > this.seps.length) { + diff = sepsLength - this.seps.length + this.seps.push(...this.alphabet.slice(0, diff)) + this.alphabet = this.alphabet.slice(diff) } } - this.alphabet = shuffle(this.alphabet, salt) - const guardCount = Math.ceil([...this.alphabet].length / guardDiv) + this.alphabet = shuffle(this.alphabet, saltChars) + const guardCount = Math.ceil(this.alphabet.length / guardDiv) - if ([...this.alphabet].length < 3) { - this.guards = unicodeSubstr(this.seps, 0, guardCount) - this.seps = unicodeSubstr(this.seps, guardCount) + if (this.alphabet.length < 3) { + this.guards = this.seps.slice(0, guardCount) + this.seps = this.seps.slice(guardCount) } else { - this.guards = unicodeSubstr(this.alphabet, 0, guardCount) - this.alphabet = unicodeSubstr(this.alphabet, guardCount) + this.guards = this.alphabet.slice(0, guardCount) + this.alphabet = this.alphabet.slice(guardCount) } + + this.guardsRegExp = makeAnyOfCharsRegExp(this.guards) + this.sepsRegExp = makeAnyOfCharsRegExp(this.seps) + this.allowedCharsRegExp = makeAtLeastSomeCharRegExp([ + ...this.alphabet, + ...this.guards, + ...this.seps, + ]) } public encode(numbers: string): string @@ -103,7 +121,7 @@ export default class Hashids { return ret } - return this._encode(numbers as number[]) + return this._encode(numbers as number[]).join('') } public decode(id: string): NumberLike[] { @@ -152,8 +170,7 @@ export default class Hashids { .join('') } - private _encode(numbers: NumberLike[]): string { - let ret: string + private _encode(numbers: NumberLike[]): string[] { let alphabet = this.alphabet const numbersIdInt = numbers.reduce( @@ -165,53 +182,52 @@ export default class Hashids { 0, ) - ret = [...alphabet][numbersIdInt % [...alphabet].length] - const lottery = ret + let ret: string[] = [alphabet[numbersIdInt % alphabet.length]] + const lottery = ret.slice() - const seps = [...this.seps] - const guards = [...this.guards] + const seps = this.seps + const guards = this.guards numbers.forEach((number, i) => { - const buffer = lottery + this.salt + alphabet + const buffer = lottery.concat(this.salt, alphabet) - alphabet = shuffle(alphabet, unicodeSubstr(buffer, 0)) + alphabet = shuffle(alphabet, buffer) const last = toAlphabet(number, alphabet) - ret += last + ret.push(...last) if (i + 1 < numbers.length) { - const charCode = last.codePointAt(0)! + i + const charCode = last[0].codePointAt(0)! + i const extraNumber = typeof number === 'bigint' ? Number(number % BigInt(charCode)) : number % charCode - ret += seps[extraNumber % seps.length] + ret.push(seps[extraNumber % seps.length]) } }) - if ([...ret].length < this.minLength) { + if (ret.length < this.minLength) { const prefixGuardIndex = - (numbersIdInt + [...ret][0].codePointAt(0)!) % guards.length - ret = guards[prefixGuardIndex] + ret + (numbersIdInt + ret[0].codePointAt(0)!) % guards.length + ret.unshift(guards[prefixGuardIndex]) - if ([...ret].length < this.minLength) { + if (ret.length < this.minLength) { const suffixGuardIndex = - (numbersIdInt + [...ret][2].codePointAt(0)!) % guards.length - ret = ret + guards[suffixGuardIndex] + (numbersIdInt + ret[2].codePointAt(0)!) % guards.length + ret.push(guards[suffixGuardIndex]) } } - const halfLength = Math.floor([...alphabet].length / 2) - while ([...ret].length < this.minLength) { + const halfLength = Math.floor(alphabet.length / 2) + while (ret.length < this.minLength) { alphabet = shuffle(alphabet, alphabet) - ret = - unicodeSubstr(alphabet, halfLength) + - ret + - unicodeSubstr(alphabet, 0, halfLength) + ret.unshift(...alphabet.slice(halfLength)) + ret.push(...alphabet.slice(0, halfLength)) - const excess = [...ret].length - this.minLength + const excess = ret.length - this.minLength if (excess > 0) { - ret = unicodeSubstr(ret, excess / 2, this.minLength) + const halfOfExcess = excess / 2 + ret = ret.slice(halfOfExcess, halfOfExcess + this.minLength) } } @@ -219,48 +235,42 @@ export default class Hashids { } public isValidId(id: string): boolean { - return [...id].every( - (char) => - this.alphabet.includes(char) || - this.guards.includes(char) || - this.seps.includes(char), - ) + return this.allowedCharsRegExp.test(id) } private _decode(id: string): NumberLike[] { if (!this.isValidId(id)) { throw new Error( - `The provided ID (${id}) is invalid, as it contains characters that do not exist in the alphabet (${this.guards}${this.seps}${this.alphabet})`, + `The provided ID (${id}) is invalid, as it contains characters that do not exist in the alphabet (${this.guards.join( + '', + )}${this.seps.join('')}${this.alphabet.join('')})`, ) } - const idGuardsArray = splitAtMatch(id, (char) => this.guards.includes(char)) + const idGuardsArray = id.split(this.guardsRegExp) const splitIndex = idGuardsArray.length === 3 || idGuardsArray.length === 2 ? 1 : 0 const idBreakdown = idGuardsArray[splitIndex] - const idBreakdownArray = [...idBreakdown] - if (idBreakdownArray.length === 0) return [] - - const [lotteryChar, ...chars] = idBreakdownArray - const rest = chars.join('') - const idArray = splitAtMatch(rest, (char) => this.seps.includes(char)) - - const {result} = idArray.reduce( - ({result, lastAlphabet}, subId) => { - const buffer = lotteryChar + this.salt + lastAlphabet - const nextAlphabet = shuffle( - lastAlphabet, - unicodeSubstr(buffer, 0, [...lastAlphabet].length), - ) - return { - result: [...result, fromAlphabet(subId, nextAlphabet)], - lastAlphabet: nextAlphabet, - } - }, - {result: [] as NumberLike[], lastAlphabet: this.alphabet}, - ) + if (idBreakdown.length === 0) return [] + + const lotteryChar = idBreakdown[Symbol.iterator]().next().value as string + const idArray = idBreakdown.slice(lotteryChar.length).split(this.sepsRegExp) + + let lastAlphabet: string[] = this.alphabet + const result: NumberLike[] = [] - if (this._encode(result) !== id) return [] + for (const subId of idArray) { + const buffer = [lotteryChar, ...this.salt, ...lastAlphabet] + const nextAlphabet = shuffle( + lastAlphabet, + buffer.slice(0, lastAlphabet.length), + ) + result.push(fromAlphabet([...subId], nextAlphabet)) + lastAlphabet = nextAlphabet + } + + // if the result is different from what we'd expect, we return an empty result (malformed input): + if (this._encode(result).join('') !== id) return [] return result } } @@ -269,17 +279,16 @@ const minAlphabetLength = 16 const sepDiv = 3.5 const guardDiv = 12 -export const keepUniqueChars = (str: string) => - Array.from(new Set(str)).join('') - -export const withoutChars = ([...str]: string, [...without]: string) => - str.filter((char) => !without.includes(char)).join('') +export const keepUnique = (content: Iterable): T[] => + Array.from(new Set(content)) -export const onlyChars = ([...str]: string, [...only]: string) => - str.filter((char) => only.includes(char)).join('') +export const withoutChars = ( + chars: string[], + withoutChars: string[], +): string[] => chars.filter((char) => !withoutChars.includes(char)) -export const unicodeSubstr = ([...str]: string, from: number, to?: number) => - str.slice(from, to === undefined ? undefined : from + to).join('') +export const onlyChars = (chars: string[], keepChars: string[]): string[] => + chars.filter((char) => keepChars.includes(char)) const isIntegerNumber = (n: NumberLike | string) => typeof n === 'bigint' || @@ -288,96 +297,86 @@ const isIntegerNumber = (n: NumberLike | string) => const isPositiveAndFinite = (n: NumberLike) => typeof n === 'bigint' || (n >= 0 && Number.isSafeInteger(n)) -function shuffle(alphabet: string, [...salt]: string) { - let integer: number - - if (!salt.length) { - return alphabet +function shuffle(alphabetChars: string[], saltChars: string[]): string[] { + if (saltChars.length === 0) { + return alphabetChars } - const alphabetChars = [...alphabet] + let integer: number + const transformed = alphabetChars.slice() - for (let i = alphabetChars.length - 1, v = 0, p = 0; i > 0; i--, v++) { - v %= salt.length - p += integer = salt[v].codePointAt(0)! + for (let i = transformed.length - 1, v = 0, p = 0; i > 0; i--, v++) { + v %= saltChars.length + p += integer = saltChars[v].codePointAt(0)! const j = (integer + v + p) % i - // swap characters at positions i and j - ;[alphabetChars[j], alphabetChars[i]] = [alphabetChars[i], alphabetChars[j]] + // swap characters at positions i and j + const a = transformed[i] + const b = transformed[j] + transformed[j] = a + transformed[i] = b } - return alphabetChars.join('') + return transformed } -const toAlphabet = (input: NumberLike, [...alphabet]: string) => { - let id = '' +const toAlphabet = (input: NumberLike, alphabetChars: string[]): string[] => { + const id: string[] = [] if (typeof input === 'bigint') { - const alphabetLength = BigInt(alphabet.length) + const alphabetLength = BigInt(alphabetChars.length) do { - id = alphabet[Number(input % alphabetLength)] + id + id.unshift(alphabetChars[Number(input % alphabetLength)]) input = input / alphabetLength } while (input > BigInt(0)) } else { do { - id = alphabet[input % alphabet.length] + id - input = Math.floor(input / alphabet.length) + id.unshift(alphabetChars[input % alphabetChars.length]) + input = Math.floor(input / alphabetChars.length) } while (input > 0) } return id } -const fromAlphabet = ([...input]: string, [...alphabet]: string) => - input - .map((item) => { - const index = alphabet.indexOf(item) - if (index === -1) { - const inputString = input.join('') - const alphabetString = alphabet.join('') +const fromAlphabet = ( + inputChars: string[], + alphabetChars: string[], +): NumberLike => + inputChars.reduce((carry, item) => { + const index = alphabetChars.indexOf(item) + if (index === -1) { + throw new Error( + `The provided ID (${inputChars.join( + '', + )}) is invalid, as it contains characters that do not exist in the alphabet (${alphabetChars.join( + '', + )})`, + ) + } + if (typeof carry === 'bigint') { + return carry * BigInt(alphabetChars.length) + BigInt(index) + } + const value = carry * alphabetChars.length + index + const isSafeValue = Number.isSafeInteger(value) + if (isSafeValue) { + return value + } else { + if (typeof BigInt === 'function') { + return BigInt(carry) * BigInt(alphabetChars.length) + BigInt(index) + } else { + // we do not have support for BigInt: throw new Error( - `The provided ID (${inputString}) is invalid, as it contains characters that do not exist in the alphabet (${alphabetString})`, + `Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment`, ) } - return index - }) - .reduce( - (carry, index) => { - if (typeof carry === 'bigint') { - return carry * BigInt(alphabet.length) + BigInt(index) - } - const value = carry * alphabet.length + index - const isSafeValue = Number.isSafeInteger(value) - if (isSafeValue) { - return value - } else { - if (typeof BigInt === 'function') { - return BigInt(carry) * BigInt(alphabet.length) + BigInt(index) - } else { - // we do not have support for BigInt: - throw new Error( - `Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment`, - ) - } - } - }, - 0 as NumberLike, - ) - -const splitAtMatch = ([...chars]: string, match: (char: string) => boolean) => - chars.reduce( - (groups, char) => - match(char) - ? [...groups, ''] - : [...groups.slice(0, -1), groups[groups.length - 1] + char], - [''], - ) + } + }, 0 as NumberLike) const safeToParseNumberRegExp = /^\+?[0-9]+$/ const safeParseInt10 = (str: string) => safeToParseNumberRegExp.test(str) ? parseInt(str, 10) : NaN -/** note: this doesn't need to support unicode, since it's used to split hex strings only */ const splitAtIntervalAndMap = ( str: string, nth: number, @@ -386,3 +385,26 @@ const splitAtIntervalAndMap = ( Array.from({length: Math.ceil(str.length / nth)}, (_, index) => map(str.slice(index * nth, (index + 1) * nth)), ) + +const makeAnyOfCharsRegExp = (chars: string[]) => + new RegExp( + chars + .map((char) => escapeRegExp(char)) + // we need to sort these from longest to shortest, + // as they may contain multibyte unicode characters (these should come first) + .sort((a, b) => b.length - a.length) + .join('|'), + ) + +const makeAtLeastSomeCharRegExp = (chars: string[]) => + new RegExp( + `^[${chars + .map((char) => escapeRegExp(char)) + // we need to sort these from longest to shortest, + // as they may contain multibyte unicode characters (these should come first) + .sort((a, b) => b.length - a.length) + .join('')}]+$`, + ) + +const escapeRegExp = (text: string) => + text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') diff --git a/package.json b/package.json index 2f17583..c845c38 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "build": "yarn run build:umd && yarn run build:esm && yarn run minify", "clean": "rm -rf coverage yarn-debug.log", "all": "yarn run lint && yarn run coverage && yarn run build && yarn run clean", - "semantic-release": "semantic-release" + "semantic-release": "semantic-release", + "benchmark": "yarn ts-node -O '{\"module\": \"commonjs\"}' -T tests/benchmark" }, "husky": { "hooks": { @@ -57,30 +58,32 @@ "not dead" ], "devDependencies": { - "@babel/cli": "^7.8.3", - "@babel/core": "^7.8.3", + "@babel/cli": "^7.8.4", + "@babel/core": "^7.8.4", "@babel/plugin-syntax-bigint": "^7.8.3", "@babel/plugin-transform-destructuring": "^7.8.3", "@babel/plugin-transform-spread": "^7.8.3", - "@babel/preset-env": "^7.8.3", + "@babel/preset-env": "^7.8.4", "@babel/preset-typescript": "^7.8.3", "@babel/register": "^7.8.3", - "@types/jest": "^24.9.1", - "@types/node": "^13.5.0", - "@typescript-eslint/eslint-plugin": "^2.17.0", - "@typescript-eslint/parser": "^2.17.0", - "@yarnpkg/pnpify": "^2.0.0-rc.16", + "@types/jest": "^25.1.1", + "@types/node": "^13.7.0", + "@typescript-eslint/eslint-plugin": "^2.19.0", + "@typescript-eslint/parser": "^2.19.0", + "@yarnpkg/pnpify": "^2.0.0-rc.17", "coveralls": "^3.0.9", "eslint": "^6.8.0", - "eslint-config-prettier": "^6.9.0", + "eslint-config-prettier": "^6.10.0", "eslint-import-resolver-node": "^0.3.3", "eslint-plugin-eslint-comments": "^3.1.2", - "eslint-plugin-import": "^2.20.0", + "eslint-plugin-import": "^2.20.1", "eslint-plugin-jest": "^23.6.0", "husky": "^4.2.1", "jest": "^25.1.0", + "nodemark": "^0.3.0", "prettier": "^1.19.1", - "semantic-release": "^16.0.3", + "require-from-web": "^1.1.1", + "semantic-release": "^17.0.2", "terser": "^4.6.3", "ts-node": "^8.6.2", "typescript": "^3.7.5" diff --git a/tests/bad-input.test.ts b/tests/bad-input.test.ts index f53f90e..6b2d12d 100644 --- a/tests/bad-input.test.ts +++ b/tests/bad-input.test.ts @@ -75,6 +75,11 @@ describe('bad input', () => { expect(numbers).toEqual([]) }) + test(`should return an empty array when decoding an empty string`, () => { + const numbers = hashids.decode('') + expect(numbers).toEqual([]) + }) + test(`should return an empty string when encoding non-numeric input`, () => { const id = hashids.encode('z') expect(id).toEqual('') @@ -96,11 +101,20 @@ describe('bad input', () => { }) // reproduction from https://github.com/niieani/hashids.js/issues/126 - test(`should throw an error when an id to be decoded contains chars that do not exist in the alphabet`, () => { + test(`should throw an error when an id to be decoded contains chars that do not exist in the alphabet (multiple)`, () => { const hashids = new Hashids('', 6, 'abcdefghjklmnpqrstuvwxyz23456789') expect(hashids.isValidId('[object Object]')).toBe(false) expect(() => { hashids.decode('[object Object]') }).toThrow(Error) }) + + // reproduction from https://github.com/niieani/hashids.js/issues/126 + test(`should throw an error when an id to be decoded contains chars that do not exist in the alphabet (single)`, () => { + const hashids = new Hashids('', 6, 'abcdefghjklmnpqrstuvwxyz23456789') + expect(hashids.isValidId('a1bcdef')).toBe(false) + expect(() => { + hashids.decode('a1bcdef') + }).toThrow(Error) + }) }) diff --git a/tests/benchmark.ts b/tests/benchmark.ts new file mode 100644 index 0000000..a6dd3fc --- /dev/null +++ b/tests/benchmark.ts @@ -0,0 +1,37 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +/* eslint-disable @typescript-eslint/camelcase */ +/* eslint-disable no-console */ +import benchmark from 'nodemark' +import Hashids from '../lib/hashids' +import requireFromWeb from 'require-from-web' + +type HashidsType = typeof import('../lib/hashids').default + +const benchmarkVersion = (Hashids: HashidsType, version: string) => { + const hashids = new Hashids() + const encoded = '5KoLLVL49RLhYkppOplM6piwWNNANny8N' + const decoded = [9007199254740991, 9007199254740991, 9007199254740991] + + const decoding = benchmark(() => hashids.decode(encoded)) + const encoding = benchmark(() => hashids.encode(decoded)) + + console.log(version, '\tdecoding\t', decoding) + console.log(version, '\tencoding\t', encoding) +} + +async function run() { + const {default: Hashids_v1_2_2} = await requireFromWeb<{ + default: HashidsType + }>('https://unpkg.com/hashids@1.2.2/dist/index.js') + const {default: Hashids_v2_1_0} = await requireFromWeb<{ + default: HashidsType + }>('https://unpkg.com/hashids@2.1.0/dist/hashids.js') + const Hashids_transpiled = require('../cjs') + + benchmarkVersion(Hashids_v1_2_2, '1.2.2') + benchmarkVersion(Hashids_v2_1_0, '2.1.0') + benchmarkVersion(Hashids_transpiled, 'transpiled') + benchmarkVersion(Hashids, 'node') +} + +void run() diff --git a/tests/custom-alphabet.test.ts b/tests/custom-alphabet.test.ts index c661fa7..79ae528 100644 --- a/tests/custom-alphabet.test.ts +++ b/tests/custom-alphabet.test.ts @@ -48,4 +48,9 @@ describe('custom alphabet', () => { test(`should work with an alphabet with complex unicode chars`, () => { testAlphabet('πŸ€ΊπŸ‘©πŸΏβ€πŸ¦³πŸ›πŸ‘©πŸ»πŸ¦·πŸ€¦β€β™‚οΈπŸβ˜πŸΌβœπŸΎπŸ‘‰πŸ½πŸ‡ΈπŸ‡°β€οΈπŸ­') }) + + test(`should work with alphabet that contains emojis that are subsets of each other`, () => { + testAlphabet('πŸ˜πŸ§‘πŸ½β€πŸ¦³πŸ§‘πŸ·πŸ‘©πŸΏβ€πŸ¦°πŸ‘©πŸΎβ€πŸ¦°πŸ‘©πŸ½β€πŸ¦°πŸ‘©πŸ»β€πŸ¦°βœπŸΎπŸ‘‰πŸ½πŸ‘©πŸ»πŸ¦·πŸ€¦β€β™‚οΈ') + testAlphabet('πŸ˜πŸ§‘πŸ§‘πŸ½β€πŸ¦³πŸ·πŸ‘©πŸ»β€πŸ¦°πŸ‘©πŸΏβ€πŸ¦°πŸ‘©πŸ½β€πŸ¦°πŸ‘©πŸΎβ€πŸ¦°βœπŸΎπŸ‘‰πŸ½πŸ‘©πŸ»πŸ¦·πŸ€¦β€β™‚οΈ') + }) }) diff --git a/tests/types.d.ts b/tests/types.d.ts new file mode 100644 index 0000000..bcc37c6 --- /dev/null +++ b/tests/types.d.ts @@ -0,0 +1,79 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +declare module 'nodemark' { + class BenchmarkResult { + /** the average measured time in nanoseconds */ + mean: number + /** the margin of error as a ratio of the mean */ + error: number + /** the fastest measured time in nanoseconds */ + max: number + /** the slowest measured time in nanoseconds */ + min: number + /** the number of times the subject was invoked and measured */ + count: number + + /** + * Returns this.mean, rounded to the nearest whole number + * or the number of decimal places specified by `precision` + */ + nanoseconds(precision?: number): number + /** + * Returns this.mean, rounded to the nearest whole number + * or the number of decimal places specified by `precision` + */ + microseconds(precision?: number): number + /** + * Returns this.mean, rounded to the nearest whole number + * or the number of decimal places specified by `precision` + */ + milliseconds(precision?: number): number + /** + * Returns this.mean, rounded to the nearest whole number + * or the number of decimal places specified by `precision` + */ + seconds(precision?: number): number + /** + * Returns the average number of executions per second, + * rounded to the nearest whole number or the number of decimal places specified by precision. + */ + hz(precision?: number): number + /** + * Returns the standard deviation per second, + * rounded to the nearest whole number or the number of decimal places specified by precision. + */ + sd(precision?: number): number + + /** + * Returns a nicely formatted string describing the result of the benchmark. + * By default, the "hz" format is used, which displays ops/sec, + * but you can optionally specify "nanoseconds", "microseconds", "milliseconds", + * or "seconds" to change the displayed information. + */ + toString( + format?: + | 'hz' + | 'nanoseconds' + | 'microseconds' + | 'milliseconds' + | 'seconds', + ): string + } + const benchmark: { + ( + subject: () => any, + setup?: () => any, + durationMillis?: number, + ): BenchmarkResult + ( + subject: (callback: (...args: Array) => void) => any, + setup?: () => any, + durationMillis?: number, + ): Promise + } + export = benchmark +} + +declare module 'require-from-web' { + function requireFromWeb(url: string): Promise + export = requireFromWeb +} diff --git a/yarn.lock b/yarn.lock index d1e826d..de58433 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4,9 +4,9 @@ __metadata: version: 4 -"@babel/cli@npm:^7.8.3": - version: 7.8.3 - resolution: "@babel/cli@npm:7.8.3" +"@babel/cli@npm:^7.8.4": + version: 7.8.4 + resolution: "@babel/cli@npm:7.8.4" dependencies: chokidar: ^2.1.8 commander: ^4.0.1 @@ -25,7 +25,7 @@ __metadata: bin: babel: ./bin/babel.js babel-external-helpers: ./bin/babel-external-helpers.js - checksum: 1374b708ac4aec8391a62b50117a6ab4d9ed89c20039b26ce30f18cdbf9290933946c811563fa0e3f9a06556e3149c59cc63059a3895ff53d9a45580fd3b1a55 + checksum: 02467836257466d41f18a31002cd1846450be191b0d8e89cbcd60b25fdee6e7e3bb7331c2f576e21a5abbb436d8078cf78f82fd700b3001fc23de7cbcb316f3d languageName: node linkType: hard @@ -38,18 +38,18 @@ __metadata: languageName: node linkType: hard -"@babel/compat-data@npm:^7.8.0, @babel/compat-data@npm:^7.8.1": - version: 7.8.1 - resolution: "@babel/compat-data@npm:7.8.1" +"@babel/compat-data@npm:^7.8.4": + version: 7.8.5 + resolution: "@babel/compat-data@npm:7.8.5" dependencies: - browserslist: ^4.8.2 + browserslist: ^4.8.5 invariant: ^2.2.4 semver: ^5.5.0 - checksum: 1d7dbf52ed4a2446dfe60d8a0f778484e1d9da7ac72357d385815f2d2bae5cf432675d2d2c24eaecda5a1eeeb66844c9bdc73186982441322e732f7e32cdaa48 + checksum: 40f6e2882709b3af9aeb0dd58ded44e7117c105f29cb3eca22eb25f003a1458a833704a333ab77ceebf2517c7cf626d5fc62bd4be061c15fb1127437bb3761a6 languageName: node linkType: hard -"@babel/core@npm:^7.1.0, @babel/core@npm:^7.7.5, @babel/core@npm:^7.8.3": +"@babel/core@npm:^7.1.0, @babel/core@npm:^7.7.5": version: 7.8.3 resolution: "@babel/core@npm:7.8.3" dependencies: @@ -72,6 +72,29 @@ __metadata: languageName: node linkType: hard +"@babel/core@npm:^7.8.4": + version: 7.8.4 + resolution: "@babel/core@npm:7.8.4" + dependencies: + "@babel/code-frame": ^7.8.3 + "@babel/generator": ^7.8.4 + "@babel/helpers": ^7.8.4 + "@babel/parser": ^7.8.4 + "@babel/template": ^7.8.3 + "@babel/traverse": ^7.8.4 + "@babel/types": ^7.8.3 + convert-source-map: ^1.7.0 + debug: ^4.1.0 + gensync: ^1.0.0-beta.1 + json5: ^2.1.0 + lodash: ^4.17.13 + resolve: ^1.3.2 + semver: ^5.4.1 + source-map: ^0.5.0 + checksum: 6a4b0f2b9343982fe4e9902c2a61484341b8b0db5623e492ef6240e54875b2c7054e4dd6c273c94ba439176872c8ae05a60f62a4aaea39d8d2acbf01fc11cb2a + languageName: node + linkType: hard + "@babel/generator@npm:^7.8.3": version: 7.8.3 resolution: "@babel/generator@npm:7.8.3" @@ -84,6 +107,18 @@ __metadata: languageName: node linkType: hard +"@babel/generator@npm:^7.8.4": + version: 7.8.4 + resolution: "@babel/generator@npm:7.8.4" + dependencies: + "@babel/types": ^7.8.3 + jsesc: ^2.5.1 + lodash: ^4.17.13 + source-map: ^0.5.0 + checksum: 986f510234d883953f13126feaef439e67147fb9cae58a08db2cd6652410041736af3ee6b2f80151b79ceeb918c3718cfc23ef245e6c4bc6f44df8a28fdfb8ca + languageName: node + linkType: hard + "@babel/helper-annotate-as-pure@npm:^7.8.3": version: 7.8.3 resolution: "@babel/helper-annotate-as-pure@npm:7.8.3" @@ -114,18 +149,18 @@ __metadata: languageName: node linkType: hard -"@babel/helper-compilation-targets@npm:^7.8.3": - version: 7.8.3 - resolution: "@babel/helper-compilation-targets@npm:7.8.3" +"@babel/helper-compilation-targets@npm:^7.8.4": + version: 7.8.4 + resolution: "@babel/helper-compilation-targets@npm:7.8.4" dependencies: - "@babel/compat-data": ^7.8.1 - browserslist: ^4.8.2 + "@babel/compat-data": ^7.8.4 + browserslist: ^4.8.5 invariant: ^2.2.4 - levenary: ^1.1.0 + levenary: ^1.1.1 semver: ^5.5.0 peerDependencies: "@babel/core": ^7.0.0 - checksum: 195bb2de84e04878f7c3bfb268e6db2b00bd70615726d9d0fa81bff1119eaf623e3e16ae2844116f15fb85c9434a0cc101d11babbe353e2327b83f6bf31748fa + checksum: 8320794f9abdfee062739759dde574bfe97b110ecc91a9210f247fcf03e279f7b6d18974e766853d7c3a5e8058d50a62438ee718d2d8289b121bf1f5e98f16dc languageName: node linkType: hard @@ -331,6 +366,17 @@ __metadata: languageName: node linkType: hard +"@babel/helpers@npm:^7.8.4": + version: 7.8.4 + resolution: "@babel/helpers@npm:7.8.4" + dependencies: + "@babel/template": ^7.8.3 + "@babel/traverse": ^7.8.4 + "@babel/types": ^7.8.3 + checksum: 6debb608626dcf94bc37f89b6f8851c5dd2fe969dbda2f24a7c5f41fcd17d49d223823cd6ace6eb2b9a9df1b049f42295d9c65f40a452e5d53ea2038fdc8ee88 + languageName: node + linkType: hard + "@babel/highlight@npm:^7.8.3": version: 7.8.3 resolution: "@babel/highlight@npm:7.8.3" @@ -351,6 +397,15 @@ __metadata: languageName: node linkType: hard +"@babel/parser@npm:^7.8.4": + version: 7.8.4 + resolution: "@babel/parser@npm:7.8.4" + bin: + parser: ./bin/babel-parser.js + checksum: 95a27d5c49d26576ac092da2c8e4ccbbd560dc0a198d0888411124ccd834535459ec35f0c33f50f3e8b189df392cf4e5e974243cdda884f4812b6537b419d309 + languageName: node + linkType: hard + "@babel/plugin-proposal-async-generator-functions@npm:^7.8.3": version: 7.8.3 resolution: "@babel/plugin-proposal-async-generator-functions@npm:7.8.3" @@ -680,14 +735,14 @@ __metadata: languageName: node linkType: hard -"@babel/plugin-transform-for-of@npm:^7.8.3": - version: 7.8.3 - resolution: "@babel/plugin-transform-for-of@npm:7.8.3" +"@babel/plugin-transform-for-of@npm:^7.8.4": + version: 7.8.4 + resolution: "@babel/plugin-transform-for-of@npm:7.8.4" dependencies: "@babel/helper-plugin-utils": ^7.8.3 peerDependencies: "@babel/core": ^7.0.0-0 - checksum: 489a6d03489f1b7617594ba0f1e42920fde14bfc2d10cb45d990f1c089e9a67cd9d7206745694d925aca66493fa594ca30c945a4d968ccb90df7c0fc4228fcc6 + checksum: 9d8d84c063f5e0127530e3c77e15b40b6f34bdfa133e4a5e514b4200a1c4285ec9a8ef197b9bc5294a3e458bcfc6fc81ec1cdbe01182f1803a9cbad29d23321e languageName: node linkType: hard @@ -812,16 +867,16 @@ __metadata: languageName: node linkType: hard -"@babel/plugin-transform-parameters@npm:^7.8.3": - version: 7.8.3 - resolution: "@babel/plugin-transform-parameters@npm:7.8.3" +"@babel/plugin-transform-parameters@npm:^7.8.4": + version: 7.8.4 + resolution: "@babel/plugin-transform-parameters@npm:7.8.4" dependencies: "@babel/helper-call-delegate": ^7.8.3 "@babel/helper-get-function-arity": ^7.8.3 "@babel/helper-plugin-utils": ^7.8.3 peerDependencies: "@babel/core": ^7.0.0-0 - checksum: bf5c84a7c5637d84eb94e13ae8af5349450f4c34eadc3939210df592f7e7a977fcf234a3c9a01900c17b8393195e5f9dfd52d6d0c1e01fbc6e7c0bc6778fb473 + checksum: af4a2a5060e7902222aab79fb5cd0369bab5a07a5d882a84ebd81a11f7e433010b9ea70f1c4d1a8561c160611f66c39a757bc946dd5120565206bb3e10be3243 languageName: node linkType: hard @@ -904,14 +959,14 @@ __metadata: languageName: node linkType: hard -"@babel/plugin-transform-typeof-symbol@npm:^7.8.3": - version: 7.8.3 - resolution: "@babel/plugin-transform-typeof-symbol@npm:7.8.3" +"@babel/plugin-transform-typeof-symbol@npm:^7.8.4": + version: 7.8.4 + resolution: "@babel/plugin-transform-typeof-symbol@npm:7.8.4" dependencies: "@babel/helper-plugin-utils": ^7.8.3 peerDependencies: "@babel/core": ^7.0.0-0 - checksum: 2b1912af70b08f032bcccd257566abacc1c88e429077bafb3e494518683b26bebeaa732edaf6f027a4699b007ee7ba9d240552d6718a93b5948614004fa3ab1d + checksum: a87a2b5681aac78b29b8442b3f12d822ef9b5badfa1ed4e4ca20a1767f821667e5858e7bc2cbec67b99e5d69103af4c8905e0293b28d8f8c0422e6088a60c768 languageName: node linkType: hard @@ -940,12 +995,12 @@ __metadata: languageName: node linkType: hard -"@babel/preset-env@npm:^7.8.3": - version: 7.8.3 - resolution: "@babel/preset-env@npm:7.8.3" +"@babel/preset-env@npm:^7.8.4": + version: 7.8.4 + resolution: "@babel/preset-env@npm:7.8.4" dependencies: - "@babel/compat-data": ^7.8.0 - "@babel/helper-compilation-targets": ^7.8.3 + "@babel/compat-data": ^7.8.4 + "@babel/helper-compilation-targets": ^7.8.4 "@babel/helper-module-imports": ^7.8.3 "@babel/helper-plugin-utils": ^7.8.3 "@babel/plugin-proposal-async-generator-functions": ^7.8.3 @@ -974,7 +1029,7 @@ __metadata: "@babel/plugin-transform-dotall-regex": ^7.8.3 "@babel/plugin-transform-duplicate-keys": ^7.8.3 "@babel/plugin-transform-exponentiation-operator": ^7.8.3 - "@babel/plugin-transform-for-of": ^7.8.3 + "@babel/plugin-transform-for-of": ^7.8.4 "@babel/plugin-transform-function-name": ^7.8.3 "@babel/plugin-transform-literals": ^7.8.3 "@babel/plugin-transform-member-expression-literals": ^7.8.3 @@ -985,7 +1040,7 @@ __metadata: "@babel/plugin-transform-named-capturing-groups-regex": ^7.8.3 "@babel/plugin-transform-new-target": ^7.8.3 "@babel/plugin-transform-object-super": ^7.8.3 - "@babel/plugin-transform-parameters": ^7.8.3 + "@babel/plugin-transform-parameters": ^7.8.4 "@babel/plugin-transform-property-literals": ^7.8.3 "@babel/plugin-transform-regenerator": ^7.8.3 "@babel/plugin-transform-reserved-words": ^7.8.3 @@ -993,17 +1048,17 @@ __metadata: "@babel/plugin-transform-spread": ^7.8.3 "@babel/plugin-transform-sticky-regex": ^7.8.3 "@babel/plugin-transform-template-literals": ^7.8.3 - "@babel/plugin-transform-typeof-symbol": ^7.8.3 + "@babel/plugin-transform-typeof-symbol": ^7.8.4 "@babel/plugin-transform-unicode-regex": ^7.8.3 "@babel/types": ^7.8.3 - browserslist: ^4.8.2 + browserslist: ^4.8.5 core-js-compat: ^3.6.2 invariant: ^2.2.2 - levenary: ^1.1.0 + levenary: ^1.1.1 semver: ^5.5.0 peerDependencies: "@babel/core": ^7.0.0-0 - checksum: 6c93ebb7a46bdef86a0d78aa73627a134cc792b82cfa577f15bd89e937173cb79025ba5de227c333502366b2f534daa57bd8773b4d8829e26b90d69bbb03b84b + checksum: 85e1f9877cd8162195f11a88a998e74494a71e1fd0d4968fe56e88444bdc6ece519e9d22068aa2cced0c08d2410e9b8bbc5260e05414ed9876d721197629ead5 languageName: node linkType: hard @@ -1071,6 +1126,23 @@ __metadata: languageName: node linkType: hard +"@babel/traverse@npm:^7.8.4": + version: 7.8.4 + resolution: "@babel/traverse@npm:7.8.4" + dependencies: + "@babel/code-frame": ^7.8.3 + "@babel/generator": ^7.8.4 + "@babel/helper-function-name": ^7.8.3 + "@babel/helper-split-export-declaration": ^7.8.3 + "@babel/parser": ^7.8.4 + "@babel/types": ^7.8.3 + debug: ^4.1.0 + globals: ^11.1.0 + lodash: ^4.17.13 + checksum: aefa5d2e9e82bf1500b9935dc3c18c63557f4ecd6a4d8d79b27307016b3e5c8a8c6c8a9489a81a331036be63459beba6601067378c3a58985c3dfd1d228c5853 + languageName: node + linkType: hard + "@babel/types@npm:^7.0.0, @babel/types@npm:^7.3.0, @babel/types@npm:^7.8.3": version: 7.8.3 resolution: "@babel/types@npm:7.8.3" @@ -1289,17 +1361,6 @@ __metadata: languageName: node linkType: hard -"@jest/types@npm:^24.9.0": - version: 24.9.0 - resolution: "@jest/types@npm:24.9.0" - dependencies: - "@types/istanbul-lib-coverage": ^2.0.0 - "@types/istanbul-reports": ^1.1.1 - "@types/yargs": ^13.0.0 - checksum: 8b9206216a7770f636d69b2738581affed268891defc767770e55018984167ce2e37d31b8945de57485444452a2986b018db5fc32adf15d2f702b69c540ec559 - languageName: node - linkType: hard - "@jest/types@npm:^25.1.0": version: 25.1.0 resolution: "@jest/types@npm:25.1.0" @@ -1359,6 +1420,32 @@ __metadata: languageName: node linkType: hard +"@octokit/plugin-paginate-rest@npm:^1.1.1": + version: 1.1.2 + resolution: "@octokit/plugin-paginate-rest@npm:1.1.2" + dependencies: + "@octokit/types": ^2.0.1 + checksum: 3fa9449be6f0afc57bcd44b885c903d262147381c7f7c61e5c1950d60b6f8634c71a45f140f2c357acfca2d103afbc75fd6d410e245c25760221c08b24c426ee + languageName: node + linkType: hard + +"@octokit/plugin-request-log@npm:^1.0.0": + version: 1.0.0 + resolution: "@octokit/plugin-request-log@npm:1.0.0" + checksum: 0e7fdd83406e041fa65532a9682379dc7641ab6885b956040bd958e5819b07b7c45afdf9bfd1983126b6f1df6914dccd6b4bb277f36acaa293839528a3e900d0 + languageName: node + linkType: hard + +"@octokit/plugin-rest-endpoint-methods@npm:2.4.0": + version: 2.4.0 + resolution: "@octokit/plugin-rest-endpoint-methods@npm:2.4.0" + dependencies: + "@octokit/types": ^2.0.1 + deprecation: ^2.3.1 + checksum: 81d013b479d7db8fd2ecaca2377a2baf80fae1034eb166831e72506f3fb68e9bea2d55700089b149e334ae6f0b89e7c4724a52246db56909e1d5e22efe3a09de + languageName: node + linkType: hard + "@octokit/request-error@npm:^1.0.1, @octokit/request-error@npm:^1.0.2": version: 1.2.0 resolution: "@octokit/request-error@npm:1.2.0" @@ -1386,11 +1473,14 @@ __metadata: languageName: node linkType: hard -"@octokit/rest@npm:^16.27.0": - version: 16.38.2 - resolution: "@octokit/rest@npm:16.38.2" +"@octokit/rest@npm:^16.43.0": + version: 16.43.0 + resolution: "@octokit/rest@npm:16.43.0" dependencies: "@octokit/auth-token": ^2.4.0 + "@octokit/plugin-paginate-rest": ^1.1.1 + "@octokit/plugin-request-log": ^1.0.0 + "@octokit/plugin-rest-endpoint-methods": 2.4.0 "@octokit/request": ^5.2.0 "@octokit/request-error": ^1.0.2 atob-lite: ^2.0.0 @@ -1403,11 +1493,11 @@ __metadata: octokit-pagination-methods: ^1.1.0 once: ^1.4.0 universal-user-agent: ^4.0.0 - checksum: 5110c311b5c1694ee8417ba78eb63f6989aca9084a7f2f4d83d2a96ea495bd1864f73a9e20ee5026d60bcc033b1ca435ae01fb5fb1734c978695033cd23813e6 + checksum: 911605e34ff0bcf2e3336d931ae022f261c6d245d5a260e2248526f43070b37676a7470ca5de12ca3d5732ab5331353d68c0762d415aaa533105a72abe413b80 languageName: node linkType: hard -"@octokit/types@npm:^2.0.0": +"@octokit/types@npm:^2.0.0, @octokit/types@npm:^2.0.1": version: 2.1.1 resolution: "@octokit/types@npm:2.1.1" dependencies: @@ -1416,9 +1506,9 @@ __metadata: languageName: node linkType: hard -"@semantic-release/commit-analyzer@npm:^7.0.0": - version: 7.0.0 - resolution: "@semantic-release/commit-analyzer@npm:7.0.0" +"@semantic-release/commit-analyzer@npm:^8.0.0": + version: 8.0.1 + resolution: "@semantic-release/commit-analyzer@npm:8.0.1" dependencies: conventional-changelog-angular: ^5.0.0 conventional-commits-filter: ^2.0.0 @@ -1426,10 +1516,10 @@ __metadata: debug: ^4.0.0 import-from: ^3.0.0 lodash: ^4.17.4 - micromatch: ^3.1.10 + micromatch: ^4.0.2 peerDependencies: - semantic-release: ">=16.0.0-beta <17.0.0" - checksum: 2a8a3a901c488823983b9ad9dae6845274d14a72f66d714388879d438f89140d20b36c6aa4ad9ec7e6d915443c38ba724b7e837da4e11eb5f7f5d465672603ca + semantic-release: ">=16.0.0 <18.0.0" + checksum: 69f0f484be5d7a6402d15fe4d16a7b9cf7cddafe87864fa2c0c110c4539ca7ab42a32983a25b0497ecdf4681d58ae4ed2b62247594df23dcdb225977a65d05bf languageName: node linkType: hard @@ -1440,18 +1530,18 @@ __metadata: languageName: node linkType: hard -"@semantic-release/github@npm:^6.0.0": - version: 6.0.2 - resolution: "@semantic-release/github@npm:6.0.2" +"@semantic-release/github@npm:^7.0.0": + version: 7.0.2 + resolution: "@semantic-release/github@npm:7.0.2" dependencies: - "@octokit/rest": ^16.27.0 + "@octokit/rest": ^16.43.0 "@semantic-release/error": ^2.2.0 aggregate-error: ^3.0.0 bottleneck: ^2.18.1 debug: ^4.0.0 dir-glob: ^3.0.0 fs-extra: ^8.0.0 - globby: ^10.0.0 + globby: ^11.0.0 http-proxy-agent: ^4.0.0 https-proxy-agent: ^4.0.0 issue-parser: ^6.0.0 @@ -1461,14 +1551,14 @@ __metadata: p-retry: ^4.0.0 url-join: ^4.0.0 peerDependencies: - semantic-release: ">=16.0.0 <17.0.0" - checksum: 7bdf4fe97b9744cfde94db4c62e6c7560f481823be0a70506d2b4d5de3c673f2375e8ae2bcd5e656e9aad862bef4a26c7dc180c50b5312db9099d5836d0ed473 + semantic-release: ">=16.0.0 <18.0.0" + checksum: 9333273de71bc84461ed831181636a8420b1a2002bbc3bbbe840625da4c01e5b79712a956d5a3169c6c14b69258a03bd1e63a3843d662da6d40aa1d5897cf361 languageName: node linkType: hard -"@semantic-release/npm@npm:^6.0.0": - version: 6.0.0 - resolution: "@semantic-release/npm@npm:6.0.0" +"@semantic-release/npm@npm:^7.0.0": + version: 7.0.2 + resolution: "@semantic-release/npm@npm:7.0.2" dependencies: "@semantic-release/error": ^2.2.0 aggregate-error: ^3.0.0 @@ -1476,22 +1566,22 @@ __metadata: fs-extra: ^8.0.0 lodash: ^4.17.15 nerf-dart: ^1.0.0 - normalize-url: ^4.0.0 + normalize-url: ^5.0.0 npm: ^6.10.3 rc: ^1.2.8 read-pkg: ^5.0.0 registry-auth-token: ^4.0.0 - semver: ^6.3.0 + semver: ^7.1.2 tempy: ^0.3.0 peerDependencies: - semantic-release: ">=16.0.0-beta <17.0.0" - checksum: d19d4691fc12a14156790952f6e6130c2c0f3e4ba22b64fe18817ad9b102667d29b5d978c62f17f1b85b4b7a0ecd73b60941d1a0dd7646009b2a654e83ad17c8 + semantic-release: ">=16.0.0 <18.0.0" + checksum: dabfad7df812ca54253febbf94c747fa55545180ba8bfd8cd0bd9338e2e332f2d0e6532240ef4c557cfc53d4dfbe02af951517263c1ea2ebb317eee459489354 languageName: node linkType: hard -"@semantic-release/release-notes-generator@npm:^7.1.2": - version: 7.3.5 - resolution: "@semantic-release/release-notes-generator@npm:7.3.5" +"@semantic-release/release-notes-generator@npm:^9.0.0": + version: 9.0.0 + resolution: "@semantic-release/release-notes-generator@npm:9.0.0" dependencies: conventional-changelog-angular: ^5.0.0 conventional-changelog-writer: ^4.0.0 @@ -1504,8 +1594,8 @@ __metadata: lodash: ^4.17.4 read-pkg-up: ^7.0.0 peerDependencies: - semantic-release: ">=15.8.0 <16.0.0 || >=16.0.0-beta <17.0.0" - checksum: 90a600174483961ad05f25e4ec09a9ce0c17df6d0ae67ca1a3aad30b131b9d8001e841d14e5d894777cbcf9b1f5d6638677edd976ab88ce6ce08aeb3a8881f96 + semantic-release: ">=15.8.0 <18.0.0" + checksum: c4dfc1180264c3e94698348108c8513506cdc541a83d05fe28c40e0956d3e043c86e69b4d6a3efacfe950d74628ac7a6e3d672c6e2408f0d3053a39cf08794a1 languageName: node linkType: hard @@ -1573,24 +1663,6 @@ __metadata: languageName: node linkType: hard -"@types/events@npm:*": - version: 3.0.0 - resolution: "@types/events@npm:3.0.0" - checksum: 1fe4d45b4a29064c761efb988a111e9f46f3507c08311ff888edb792780ef1bdc2d988f34d2e03563e7fd3592e18c21032c21fdd608948028f0faeb3584adf3f - languageName: node - linkType: hard - -"@types/glob@npm:^7.1.1": - version: 7.1.1 - resolution: "@types/glob@npm:7.1.1" - dependencies: - "@types/events": "*" - "@types/minimatch": "*" - "@types/node": "*" - checksum: 6b33e589a6d9ca47da1571ba153b41b055697af1a5849f6d13b527fbf4a05f82b3c5ddaae435bf6cb57b8e6db31ee45c05004f4f50c561a1f50bd87daf546e60 - languageName: node - linkType: hard - "@types/istanbul-lib-coverage@npm:*, @types/istanbul-lib-coverage@npm:^2.0.0, @types/istanbul-lib-coverage@npm:^2.0.1": version: 2.0.1 resolution: "@types/istanbul-lib-coverage@npm:2.0.1" @@ -1617,12 +1689,13 @@ __metadata: languageName: node linkType: hard -"@types/jest@npm:^24.9.1": - version: 24.9.1 - resolution: "@types/jest@npm:24.9.1" +"@types/jest@npm:^25.1.1": + version: 25.1.1 + resolution: "@types/jest@npm:25.1.1" dependencies: - jest-diff: ^24.3.0 - checksum: 2ea56fbadd5b2c8d4fa9a30ae4fec89a408b70c9f18cebe436fdde76707e253fa61016a42c55b4d866d6b9b15f859f479e1e8bab9c584a34160ea56b62c632c2 + jest-diff: ^25.1.0 + pretty-format: ^25.1.0 + checksum: 5f2ee853d37cecd957bdfd86abd5c2a88b0f2aaceee272ffd8c357b876b51ea64fe8fb0e93e0f2e10b1152083a772ef788e3059d8e5cdc39f242de93696c52b6 languageName: node linkType: hard @@ -1633,20 +1706,20 @@ __metadata: languageName: node linkType: hard -"@types/minimatch@npm:*": - version: 3.0.3 - resolution: "@types/minimatch@npm:3.0.3" - checksum: c0a07410b9723d53260b5c471a0036204115b0a7866380142e6882c5a2a3521a5e6c9152a756696946daa422d6986dad00c3b8f5c883e0cb11412199b0612b9b - languageName: node - linkType: hard - -"@types/node@npm:*, @types/node@npm:>= 8, @types/node@npm:^13.5.0": +"@types/node@npm:>= 8": version: 13.5.0 resolution: "@types/node@npm:13.5.0" checksum: c168b6228f3a0845fa7530169b5c25dfce069f5cd315ebaade02875eaadbea8eca8dc1337b6b1996ee268b1d649aaef89c2aafa452b2b24f4235eaecf83b4941 languageName: node linkType: hard +"@types/node@npm:^13.7.0": + version: 13.7.0 + resolution: "@types/node@npm:13.7.0" + checksum: 3ee505198cb714c56ce20fca902fcbd05643badc22c2f25917a2544b1a1d905b9086b90147e79bd977a9c8bb912db60240d11152827ad779e9373cdd5864e5c2 + languageName: node + linkType: hard + "@types/normalize-package-data@npm:^2.4.0": version: 2.4.0 resolution: "@types/normalize-package-data@npm:2.4.0" @@ -1682,15 +1755,6 @@ __metadata: languageName: node linkType: hard -"@types/yargs@npm:^13.0.0": - version: 13.0.6 - resolution: "@types/yargs@npm:13.0.6" - dependencies: - "@types/yargs-parser": "*" - checksum: e5968bc29e4817ca345f13cbbb8db1b943d3a4aed902c844cd97cca94e7e48da1989424fa5b3352e9ab2752b64c0d029f2893f65e5f2f552ad0fdec3deb6c2fd - languageName: node - linkType: hard - "@types/yargs@npm:^15.0.0": version: 15.0.1 resolution: "@types/yargs@npm:15.0.1" @@ -1700,11 +1764,11 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/eslint-plugin@npm:^2.17.0": - version: 2.17.0 - resolution: "@typescript-eslint/eslint-plugin@npm:2.17.0" +"@typescript-eslint/eslint-plugin@npm:^2.19.0": + version: 2.19.0 + resolution: "@typescript-eslint/eslint-plugin@npm:2.19.0" dependencies: - "@typescript-eslint/experimental-utils": 2.17.0 + "@typescript-eslint/experimental-utils": 2.19.0 eslint-utils: ^1.4.3 functional-red-black-tree: ^1.0.1 regexpp: ^3.0.0 @@ -1716,11 +1780,24 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 71985376c35579129a5af8d867e5bafe933132d9406e2680b3b85874f35d2e8928c6a4e7f27cef28794dedd60dabe9df5848f4ca8a44ee69dc063e615e5b98d2 + checksum: 4afd111f5d1e9aa6f65780e64d61722b04de715936d480180a71e119ff26bb2d955a1bbac50aa29586fc4f408152ba9a5ea064024608370ff37f55c35c38e65d languageName: node linkType: hard -"@typescript-eslint/experimental-utils@npm:2.17.0, @typescript-eslint/experimental-utils@npm:^2.5.0": +"@typescript-eslint/experimental-utils@npm:2.19.0": + version: 2.19.0 + resolution: "@typescript-eslint/experimental-utils@npm:2.19.0" + dependencies: + "@types/json-schema": ^7.0.3 + "@typescript-eslint/typescript-estree": 2.19.0 + eslint-scope: ^5.0.0 + peerDependencies: + eslint: "*" + checksum: 555694eceabe6105d1e796dd504d6230782d9a4025874ec6dbc2834427046f7a63259559c19db5e975a845b81ee26658830e6b48a93ba05be8281e35f93bdf9f + languageName: node + linkType: hard + +"@typescript-eslint/experimental-utils@npm:^2.5.0": version: 2.17.0 resolution: "@typescript-eslint/experimental-utils@npm:2.17.0" dependencies: @@ -1733,13 +1810,13 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/parser@npm:^2.17.0": - version: 2.17.0 - resolution: "@typescript-eslint/parser@npm:2.17.0" +"@typescript-eslint/parser@npm:^2.19.0": + version: 2.19.0 + resolution: "@typescript-eslint/parser@npm:2.19.0" dependencies: "@types/eslint-visitor-keys": ^1.0.0 - "@typescript-eslint/experimental-utils": 2.17.0 - "@typescript-eslint/typescript-estree": 2.17.0 + "@typescript-eslint/experimental-utils": 2.19.0 + "@typescript-eslint/typescript-estree": 2.19.0 eslint-visitor-keys: ^1.1.0 peerDependencies: eslint: ^5.0.0 || ^6.0.0 @@ -1747,7 +1824,7 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 817960ccc88fd0eebeabf83e6df5a9ed7125bdc2252d5a2a39bc5fdd2aceeba723841b71926a246ccf0c462a1156a8606a5ef31adb177d994c08945d07bf0f88 + checksum: 09c74d054552b4bb219b31294cf4d1a6db89413fbaef816a669052bc18b7a8801b91dac2876493a2868e9faca05e4ee04e47c6f2abe2a2cf9a97a006cc8fb6fe languageName: node linkType: hard @@ -1771,6 +1848,26 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/typescript-estree@npm:2.19.0": + version: 2.19.0 + resolution: "@typescript-eslint/typescript-estree@npm:2.19.0" + dependencies: + debug: ^4.1.1 + eslint-visitor-keys: ^1.1.0 + glob: ^7.1.6 + is-glob: ^4.0.1 + lodash: ^4.17.15 + semver: ^6.3.0 + tsutils: ^3.17.1 + peerDependencies: + typescript: "*" + peerDependenciesMeta: + typescript: + optional: true + checksum: 7df785ddb1211943f205dc840e0f6c7a78640e592cfdc5b976dc13fda268e287581de47f068d850e5985d854a236b0e16e50d1b0dd6cd885bf0a4b1e8817aa9d + languageName: node + linkType: hard + "@yarnpkg/fslib@npm:^2.0.0-rc.15": version: 2.0.0-rc.15 resolution: "@yarnpkg/fslib@npm:2.0.0-rc.15" @@ -1788,13 +1885,13 @@ __metadata: languageName: node linkType: hard -"@yarnpkg/pnpify@npm:^2.0.0-rc.16": - version: 2.0.0-rc.16 - resolution: "@yarnpkg/pnpify@npm:2.0.0-rc.16" +"@yarnpkg/pnpify@npm:^2.0.0-rc.17": + version: 2.0.0-rc.17 + resolution: "@yarnpkg/pnpify@npm:2.0.0-rc.17" dependencies: "@yarnpkg/fslib": ^2.0.0-rc.15 comment-json: ^2.2.0 - cross-spawn: ^6.0.5 + cross-spawn: 6.0.5 peerDependencies: eslint: "*" typescript: "*" @@ -1805,7 +1902,7 @@ __metadata: optional: true bin: pnpify: ./lib/cli.js - checksum: 32b4f7f440317d5e35306f308e63f64dba89e869784f505346c2f0ca0c4f5815b48de0deda83472bd2d7f7bc25334e5db48ad3468b63f6a2b1052c52b2b80651 + checksum: 2c475d35a82fa71f27ed7f8f4751606cd28fcea6b89fbcfec18eaa4684cc956130c7349c58870c667dbcf320a30ab9b14a56a6b7d8b3c30c63d4f5b92a9b9d06 languageName: node linkType: hard @@ -1953,14 +2050,7 @@ __metadata: languageName: node linkType: hard -"ansi-escapes@npm:^3.1.0": - version: 3.2.0 - resolution: "ansi-escapes@npm:3.2.0" - checksum: b83171596ee4875dabfbbfd3adc2570a57720fb034c5239120c81176be3b58081cb5c624cb661b95109ad4677e23c9da1a0e13fde2bd83d72149d1dde68f0192 - languageName: node - linkType: hard - -"ansi-escapes@npm:^4.2.1": +"ansi-escapes@npm:^4.2.1, ansi-escapes@npm:^4.3.0": version: 4.3.0 resolution: "ansi-escapes@npm:4.3.0" dependencies: @@ -1983,7 +2073,7 @@ __metadata: languageName: node linkType: hard -"ansi-regex@npm:^4.0.0, ansi-regex@npm:^4.1.0": +"ansi-regex@npm:^4.1.0": version: 4.1.0 resolution: "ansi-regex@npm:4.1.0" checksum: 9de38b55c876c42f26000de67fc4c8735998f79679ba93bda3854a9cbcf27abfcb2c4e2041125497ceabdb75f3a9147a40471de5e33b4dcff2125513b6d94d32 @@ -2269,6 +2359,16 @@ __metadata: languageName: node linkType: hard +"axios@npm:^0.18.1": + version: 0.18.1 + resolution: "axios@npm:0.18.1" + dependencies: + follow-redirects: 1.5.10 + is-buffer: ^2.0.2 + checksum: 39769c37794bc56fa5e24626da48d933f876378800e2a2409b5e023b9eeb2e3fd8eced174c1dcef659a031a30ad5a505f719d26f0177705120380decbf1f08d0 + languageName: node + linkType: hard + "babel-jest@npm:^25.1.0": version: 25.1.0 resolution: "babel-jest@npm:25.1.0" @@ -2480,7 +2580,7 @@ __metadata: languageName: node linkType: hard -"browserslist@npm:^4.8.2, browserslist@npm:^4.8.3": +"browserslist@npm:^4.8.3": version: 4.8.5 resolution: "browserslist@npm:4.8.5" dependencies: @@ -2493,6 +2593,19 @@ __metadata: languageName: node linkType: hard +"browserslist@npm:^4.8.5": + version: 4.8.6 + resolution: "browserslist@npm:4.8.6" + dependencies: + caniuse-lite: ^1.0.30001023 + electron-to-chromium: ^1.3.341 + node-releases: ^1.1.47 + bin: + browserslist: cli.js + checksum: bb0b6edab1fe66911cb07f0fdfa119ea425394cbb7a8a17918c9f814dbb34415302beaca0e7bfaf4cfd2923e538d9e619a43827e8eb0ec412bed58c453fcba96 + languageName: node + linkType: hard + "bser@npm:2.1.1": version: 2.1.1 resolution: "bser@npm:2.1.1" @@ -2616,7 +2729,7 @@ __metadata: languageName: node linkType: hard -"caniuse-lite@npm:^1.0.30001022": +"caniuse-lite@npm:^1.0.30001022, caniuse-lite@npm:^1.0.30001023": version: 1.0.30001023 resolution: "caniuse-lite@npm:1.0.30001023" checksum: fc3969b39405bc503065f5272c0b4bb63f368ec53f3e0929a08bdc1b891fd5b455ecb55c7ca79b876bbc21b3b02880f6725a3d532c14f046e048bf368c6ac1b6 @@ -2658,7 +2771,7 @@ __metadata: languageName: node linkType: hard -"chalk@npm:^2.0.0, chalk@npm:^2.0.1, chalk@npm:^2.1.0, chalk@npm:^2.3.2, chalk@npm:^2.4.1, chalk@npm:^2.4.2": +"chalk@npm:^2.0.0, chalk@npm:^2.0.1, chalk@npm:^2.1.0, chalk@npm:^2.3.2, chalk@npm:^2.4.2": version: 2.4.2 resolution: "chalk@npm:2.4.2" dependencies: @@ -3204,18 +3317,7 @@ __metadata: languageName: node linkType: hard -"cross-spawn@npm:^5.0.1": - version: 5.1.0 - resolution: "cross-spawn@npm:5.1.0" - dependencies: - lru-cache: ^4.0.1 - shebang-command: ^1.2.0 - which: ^1.2.9 - checksum: 86ed15a14b2c256004f2545d95ccdbeeec1017314b83ca39100f19b99ba29ca10f8fc03fcff93db749c20aec923aba498635dc8898c0a96cd15baa7dafc98898 - languageName: node - linkType: hard - -"cross-spawn@npm:^6.0.0, cross-spawn@npm:^6.0.5": +"cross-spawn@npm:6.0.5, cross-spawn@npm:^6.0.0, cross-spawn@npm:^6.0.5": version: 6.0.5 resolution: "cross-spawn@npm:6.0.5" dependencies: @@ -3228,6 +3330,17 @@ __metadata: languageName: node linkType: hard +"cross-spawn@npm:^5.0.1": + version: 5.1.0 + resolution: "cross-spawn@npm:5.1.0" + dependencies: + lru-cache: ^4.0.1 + shebang-command: ^1.2.0 + which: ^1.2.9 + checksum: 86ed15a14b2c256004f2545d95ccdbeeec1017314b83ca39100f19b99ba29ca10f8fc03fcff93db749c20aec923aba498635dc8898c0a96cd15baa7dafc98898 + languageName: node + linkType: hard + "cross-spawn@npm:^7.0.0": version: 7.0.1 resolution: "cross-spawn@npm:7.0.1" @@ -3312,7 +3425,7 @@ __metadata: languageName: node linkType: hard -"debug@npm:3.1.0": +"debug@npm:3.1.0, debug@npm:=3.1.0": version: 3.1.0 resolution: "debug@npm:3.1.0" dependencies: @@ -3453,7 +3566,7 @@ __metadata: languageName: node linkType: hard -"deprecation@npm:^2.0.0": +"deprecation@npm:^2.0.0, deprecation@npm:^2.3.1": version: 2.3.1 resolution: "deprecation@npm:2.3.1" checksum: 5197d8f4426eb3e25f1a002146eac3450f09a350f12b7a53b07ce8ec74e138e955c5420010cd30e2cd230f33e42c957112950e2e9fb341b2dac678fad08828ec @@ -3500,13 +3613,6 @@ __metadata: languageName: node linkType: hard -"diff-sequences@npm:^24.9.0": - version: 24.9.0 - resolution: "diff-sequences@npm:24.9.0" - checksum: 30499a611e33fc33f1ce67434681bfb201a63a9be804b8302f9f541f5e0bd23a8409a671be479525f644a9fb7ac2d9e3936050e6b5a8cdbd786b3274c24ee200 - languageName: node - linkType: hard - "diff-sequences@npm:^25.1.0": version: 25.1.0 resolution: "diff-sequences@npm:25.1.0" @@ -3635,6 +3741,13 @@ __metadata: languageName: node linkType: hard +"electron-to-chromium@npm:^1.3.341": + version: 1.3.344 + resolution: "electron-to-chromium@npm:1.3.344" + checksum: 4faedf5c878290091aba23d5fd2d92486549be5f5e8165c6e5b03c25b88aaec0776169d5d83d548f14d37ec92f1d4ad7c1a3a20457a887668ac1759f8a0640e6 + languageName: node + linkType: hard + "emoji-regex@npm:^7.0.1": version: 7.0.3 resolution: "emoji-regex@npm:7.0.3" @@ -3783,16 +3896,16 @@ __metadata: languageName: node linkType: hard -"eslint-config-prettier@npm:^6.9.0": - version: 6.9.0 - resolution: "eslint-config-prettier@npm:6.9.0" +"eslint-config-prettier@npm:^6.10.0": + version: 6.10.0 + resolution: "eslint-config-prettier@npm:6.10.0" dependencies: get-stdin: ^6.0.0 peerDependencies: eslint: ">=3.14.1" bin: eslint-config-prettier-check: bin/cli.js - checksum: 7e4f4f6e2750062ae6e7a6a72fd989ca391d1140668242b0f736d6baa1e214b064a96ca13dce2fa796ce94983a47325ac3f20472e2e6855407034752ba1e359f + checksum: f666dfc83a45dd548d55431692eb47b89df59068188036e2bbed55a4da11ef1320c4282e20ab8615f55553df8271e41189e0fb0155cc98b7c9b563eb5339fe61 languageName: node linkType: hard @@ -3828,9 +3941,9 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-import@npm:^2.20.0": - version: 2.20.0 - resolution: "eslint-plugin-import@npm:2.20.0" +"eslint-plugin-import@npm:^2.20.1": + version: 2.20.1 + resolution: "eslint-plugin-import@npm:2.20.1" dependencies: array-includes: ^3.0.3 array.prototype.flat: ^1.2.1 @@ -3846,7 +3959,7 @@ __metadata: resolve: ^1.12.0 peerDependencies: eslint: 2.x - 6.x - checksum: b76920ea8ac0846e211b9885058f2d5af53cdd601296b5bcf12fc5aa989deb0ae4f4a6592d79fb66a32806f783f284d2919396974ab311e7b68e5a1e032e44d9 + checksum: 226c98abbd17e8892245387abaa87147832dcd95e181a3bf0f10ad1e1b146270a7b5ab3914837cda36dfdfc619aba58355cbff83e78b60b82bda64f0a96fe0d1 languageName: node linkType: hard @@ -4170,7 +4283,7 @@ __metadata: languageName: node linkType: hard -"fast-glob@npm:^3.0.3": +"fast-glob@npm:^3.1.1": version: 3.1.1 resolution: "fast-glob@npm:3.1.1" dependencies: @@ -4360,6 +4473,15 @@ __metadata: languageName: node linkType: hard +"follow-redirects@npm:1.5.10": + version: 1.5.10 + resolution: "follow-redirects@npm:1.5.10" + dependencies: + debug: =3.1.0 + checksum: 23c6333d60b73b899f9495d67b3dd5b2b99c26cd76278d03def3c39c715f0eed53cbfe1eb1e342a7281041961fe2c69c03daa97279df66a552ab6fb3d22059fc + languageName: node + linkType: hard + "for-in@npm:^1.0.2": version: 1.0.2 resolution: "for-in@npm:1.0.2" @@ -4710,19 +4832,17 @@ fsevents@^2.1.2: languageName: node linkType: hard -"globby@npm:^10.0.0": - version: 10.0.2 - resolution: "globby@npm:10.0.2" +"globby@npm:^11.0.0": + version: 11.0.0 + resolution: "globby@npm:11.0.0" dependencies: - "@types/glob": ^7.1.1 array-union: ^2.1.0 dir-glob: ^3.0.1 - fast-glob: ^3.0.3 - glob: ^7.1.3 - ignore: ^5.1.1 - merge2: ^1.2.3 + fast-glob: ^3.1.1 + ignore: ^5.1.4 + merge2: ^1.3.0 slash: ^3.0.0 - checksum: 6f5fe47a0893f9903dc6956c93078718a2804047cef2e288e382b3e7ce4c9341b6b893408d90c576160055ded9d71c54f576b5cfb89023350b5365073e53276b + checksum: 9000e7b0004557ed8918a85278528336f2c4ad1e337e400208bc9d4aeba8d3c42f72bf3031e7ecc7467c770499430fffab5a2ab29d763e23ef776c0f2191e07b languageName: node linkType: hard @@ -4793,13 +4913,6 @@ fsevents@^2.1.2: languageName: node linkType: hard -"has-flag@npm:^2.0.0": - version: 2.0.0 - resolution: "has-flag@npm:2.0.0" - checksum: 9ddcbc7c7cb705deccc71226c547f8c9faf9d8e634d2ef7dab5d65dd45ad38918439ddbd917059a0995a89805b525b47523d5561727d1e0271c9ce89c10bca96 - languageName: node - linkType: hard - "has-flag@npm:^3.0.0": version: 3.0.0 resolution: "has-flag@npm:3.0.0" @@ -4887,30 +5000,32 @@ fsevents@^2.1.2: version: 0.0.0-use.local resolution: "hashids@workspace:." dependencies: - "@babel/cli": ^7.8.3 - "@babel/core": ^7.8.3 + "@babel/cli": ^7.8.4 + "@babel/core": ^7.8.4 "@babel/plugin-syntax-bigint": ^7.8.3 "@babel/plugin-transform-destructuring": ^7.8.3 "@babel/plugin-transform-spread": ^7.8.3 - "@babel/preset-env": ^7.8.3 + "@babel/preset-env": ^7.8.4 "@babel/preset-typescript": ^7.8.3 "@babel/register": ^7.8.3 - "@types/jest": ^24.9.1 - "@types/node": ^13.5.0 - "@typescript-eslint/eslint-plugin": ^2.17.0 - "@typescript-eslint/parser": ^2.17.0 - "@yarnpkg/pnpify": ^2.0.0-rc.16 + "@types/jest": ^25.1.1 + "@types/node": ^13.7.0 + "@typescript-eslint/eslint-plugin": ^2.19.0 + "@typescript-eslint/parser": ^2.19.0 + "@yarnpkg/pnpify": ^2.0.0-rc.17 coveralls: ^3.0.9 eslint: ^6.8.0 - eslint-config-prettier: ^6.9.0 + eslint-config-prettier: ^6.10.0 eslint-import-resolver-node: ^0.3.3 eslint-plugin-eslint-comments: ^3.1.2 - eslint-plugin-import: ^2.20.0 + eslint-plugin-import: ^2.20.1 eslint-plugin-jest: ^23.6.0 husky: ^4.2.1 jest: ^25.1.0 + nodemark: ^0.3.0 prettier: ^1.19.1 - semantic-release: ^16.0.3 + require-from-web: ^1.1.1 + semantic-release: ^17.0.2 terser: ^4.6.3 ts-node: ^8.6.2 typescript: ^3.7.5 @@ -5090,7 +5205,7 @@ fsevents@^2.1.2: languageName: node linkType: hard -"ignore@npm:^5.0.5, ignore@npm:^5.1.1": +"ignore@npm:^5.0.5, ignore@npm:^5.1.4": version: 5.1.4 resolution: "ignore@npm:5.1.4" checksum: fede475966a10c234369ac949144d7256b38ad197c54b13e8bc1ba6235f6522999af65bc271896e141c6321089389262cdf518f9cdfe3dfc3b2f2c800879660c @@ -5305,6 +5420,13 @@ fsevents@^2.1.2: languageName: node linkType: hard +"is-buffer@npm:^2.0.2": + version: 2.0.4 + resolution: "is-buffer@npm:2.0.4" + checksum: e576d6a92dea50fa7a74024f6d4b3ea30d9e9c7db85ad721ab4ac7fcb4c8a1e681c5f7951bae6a8a16e33b76c36f8be1a601f3dd82378e8e71eaf4fa1c45e906 + languageName: node + linkType: hard + "is-callable@npm:^1.1.4, is-callable@npm:^1.1.5": version: 1.1.5 resolution: "is-callable@npm:1.1.5" @@ -5809,18 +5931,6 @@ fsevents@^2.1.2: languageName: node linkType: hard -"jest-diff@npm:^24.3.0": - version: 24.9.0 - resolution: "jest-diff@npm:24.9.0" - dependencies: - chalk: ^2.0.1 - diff-sequences: ^24.9.0 - jest-get-type: ^24.9.0 - pretty-format: ^24.9.0 - checksum: 21af26d51986b493ae5962381d5375d93720da8d6521300da633148247f509ec9a5899e397dd8d2990b0e6482757e6be259cc5a670c4aac54259d4f0493ee1b4 - languageName: node - linkType: hard - "jest-diff@npm:^25.1.0": version: 25.1.0 resolution: "jest-diff@npm:25.1.0" @@ -5882,13 +5992,6 @@ fsevents@^2.1.2: languageName: node linkType: hard -"jest-get-type@npm:^24.9.0": - version: 24.9.0 - resolution: "jest-get-type@npm:24.9.0" - checksum: 08c3eb9be138a9af358c6fbcc28c313ec770f7e165ab4984989027ee8c1a2d0402d347b53ca50bd5653cc69676207becc3d8eba481b74c793dbfc1b887d4f315 - languageName: node - linkType: hard - "jest-get-type@npm:^25.1.0": version: 25.1.0 resolution: "jest-get-type@npm:25.1.0" @@ -6426,12 +6529,12 @@ fsevents@^2.1.2: languageName: node linkType: hard -"levenary@npm:^1.1.0": - version: 1.1.0 - resolution: "levenary@npm:1.1.0" +"levenary@npm:^1.1.1": + version: 1.1.1 + resolution: "levenary@npm:1.1.1" dependencies: leven: ^3.1.0 - checksum: 78ad83969695f4cd18752c921fd67a9b58ad45e5d53f5d2987b6664ab9974a7eff0e3c23e4f5cb7f5e92329ab0eb073d10a26d4b090161411e00324f52faa47f + checksum: 5f3227f9de37823cedfc348c76845c8b175a3e11301553b698b9169e895407079a560799907ad09aa94b0d695f932c64560f1bc0406b2b265b285d1568f52983 languageName: node linkType: hard @@ -7023,19 +7126,19 @@ fsevents@^2.1.2: languageName: node linkType: hard -"marked-terminal@npm:^3.2.0": - version: 3.3.0 - resolution: "marked-terminal@npm:3.3.0" +"marked-terminal@npm:^4.0.0": + version: 4.0.0 + resolution: "marked-terminal@npm:4.0.0" dependencies: - ansi-escapes: ^3.1.0 + ansi-escapes: ^4.3.0 cardinal: ^2.1.1 - chalk: ^2.4.1 + chalk: ^3.0.0 cli-table: ^0.3.1 - node-emoji: ^1.4.1 - supports-hyperlinks: ^1.0.1 + node-emoji: ^1.10.0 + supports-hyperlinks: ^2.0.0 peerDependencies: - marked: ^0.4.0 || ^0.5.0 || ^0.6.0 || ^0.7.0 - checksum: 43919db6898d0e11b250c7f10c2c2ebc872642d3016e782ed9e1e665a3d1d1cd709f4fc0086e513112ca719adb48657dac10df04dec0f8f342007a6a92f0d71a + marked: ^0.4.0 || ^0.5.0 || ^0.6.0 || ^0.7.0 || ^0.8.0 + checksum: bebea7b01decb2614025f61d354a86ea7f3c36869ba57f2493665a91fcbf4def471e6a4bc1515f623e59b7515dcd70cd90dfc8ed97d710edaca44cafb90af609 languageName: node linkType: hard @@ -7090,7 +7193,7 @@ fsevents@^2.1.2: languageName: node linkType: hard -"merge2@npm:^1.2.3, merge2@npm:^1.3.0": +"merge2@npm:^1.3.0": version: 1.3.0 resolution: "merge2@npm:1.3.0" checksum: dbcb0fa83b00cab318e82b8c370d13291a7583d2432521959246fc8048549a3d9c4fec3a7f52d17a2c071499b56dcaacceb9f543c08475235cf99d6b9ff9109f @@ -7369,7 +7472,7 @@ fsevents@^2.1.2: languageName: node linkType: hard -"node-emoji@npm:^1.4.1": +"node-emoji@npm:^1.10.0": version: 1.10.0 resolution: "node-emoji@npm:1.10.0" dependencies: @@ -7485,7 +7588,7 @@ fsevents@^2.1.2: languageName: node linkType: hard -"node-releases@npm:^1.1.46": +"node-releases@npm:^1.1.46, node-releases@npm:^1.1.47": version: 1.1.47 resolution: "node-releases@npm:1.1.47" dependencies: @@ -7494,6 +7597,13 @@ fsevents@^2.1.2: languageName: node linkType: hard +"nodemark@npm:^0.3.0": + version: 0.3.0 + resolution: "nodemark@npm:0.3.0" + checksum: f31a502a81b6d972e8b49f70120f7f0ac05d7c86a9c2df697bf8b1ecc6e1103ece911f800f4c076deaa12dd8feb8e259d20f4a65f1a50cdb74d39814b41c76d5 + languageName: node + linkType: hard + "nopt@npm:^4.0.1, nopt@npm:~4.0.1": version: 4.0.1 resolution: "nopt@npm:4.0.1" @@ -7534,10 +7644,10 @@ fsevents@^2.1.2: languageName: node linkType: hard -"normalize-url@npm:^4.0.0": - version: 4.5.0 - resolution: "normalize-url@npm:4.5.0" - checksum: 8226018faed2d0e82f61f957cd3ac02c383359a726362548de51fbad72190af52777b6a2e5daa59a083b7ede6ba2746a877d76b29a2e1485be02912bdd22740e +"normalize-url@npm:^5.0.0": + version: 5.0.0 + resolution: "normalize-url@npm:5.0.0" + checksum: e5ef4339c60d1b568a178b1139c40a6ce47cacc8b1c20d6c3e92d5c96233ce980f07a4cd98053ae6f57efe15337db3c74827a9dc26c60102e2c60f8b2e835da0 languageName: node linkType: hard @@ -8511,18 +8621,6 @@ fsevents@^2.1.2: languageName: node linkType: hard -"pretty-format@npm:^24.9.0": - version: 24.9.0 - resolution: "pretty-format@npm:24.9.0" - dependencies: - "@jest/types": ^24.9.0 - ansi-regex: ^4.0.0 - ansi-styles: ^3.2.0 - react-is: ^16.8.4 - checksum: 2a55ef0189e1c0251c3af70c6d88cd4bf330ddc353855d42839cfac6111856bdf46e997da5664bea507e021c3c8d02314a75f9a6df3c71f8a0a1c8aa41a73fcc - languageName: node - linkType: hard - "pretty-format@npm:^25.1.0": version: 25.1.0 resolution: "pretty-format@npm:25.1.0" @@ -8736,7 +8834,7 @@ fsevents@^2.1.2: languageName: node linkType: hard -"react-is@npm:^16.12.0, react-is@npm:^16.8.4": +"react-is@npm:^16.12.0": version: 16.12.0 resolution: "react-is@npm:16.12.0" checksum: 1cc13815109812213f5f1e15718551c2c4b3c164b447bd35ceba920dc268c5f0710617f12076d9b8100edd4a7e935f76bf19abe745068e387ff2670b3a3fdb0d @@ -9156,6 +9254,15 @@ fsevents@^2.1.2: languageName: node linkType: hard +"require-from-web@npm:^1.1.1": + version: 1.1.1 + resolution: "require-from-web@npm:1.1.1" + dependencies: + axios: ^0.18.1 + checksum: a40a92c1180d2ccfb8057f72d9d88382a0f4d228f2df7b2763b288f2314bcedce848d6162a25b6df87ecb0b684b9861e82c6992c79609bef1ab154b570bb847e + languageName: node + linkType: hard + "require-main-filename@npm:^1.0.1": version: 1.0.1 resolution: "require-main-filename@npm:1.0.1" @@ -9409,15 +9516,15 @@ resolve@1.1.7: languageName: node linkType: hard -"semantic-release@npm:16.0.3, semantic-release@npm:^16.0.3": - version: 16.0.3 - resolution: "semantic-release@npm:16.0.3" +"semantic-release@npm:17.0.2, semantic-release@npm:^17.0.2": + version: 17.0.2 + resolution: "semantic-release@npm:17.0.2" dependencies: - "@semantic-release/commit-analyzer": ^7.0.0 + "@semantic-release/commit-analyzer": ^8.0.0 "@semantic-release/error": ^2.2.0 - "@semantic-release/github": ^6.0.0 - "@semantic-release/npm": ^6.0.0 - "@semantic-release/release-notes-generator": ^7.1.2 + "@semantic-release/github": ^7.0.0 + "@semantic-release/npm": ^7.0.0 + "@semantic-release/release-notes-generator": ^9.0.0 aggregate-error: ^3.0.0 cosmiconfig: ^6.0.0 debug: ^4.0.0 @@ -9431,7 +9538,7 @@ resolve@1.1.7: hosted-git-info: ^3.0.0 lodash: ^4.17.15 marked: ^0.8.0 - marked-terminal: ^3.2.0 + marked-terminal: ^4.0.0 micromatch: ^4.0.2 p-each-series: ^2.1.0 p-reduce: ^2.0.0 @@ -9443,7 +9550,7 @@ resolve@1.1.7: yargs: ^15.0.1 bin: semantic-release: bin/semantic-release.js - checksum: c91962f485eaa49da297e7b026b4e3801163abca1fbfdf1e3cb3f858a33f3539692902ce1e0b8e6d6d11a990bab136ca4e4c0475adf5566886415e14b682db97 + checksum: 72e2c0de763d9cbcc8c2ecf48931cbf04caa11dd078001aaff2eb3524def03796260328d44755cd3877da6bc9aca86a2ad689d8511cdecb15333d9a461875846 languageName: node linkType: hard @@ -9515,6 +9622,15 @@ resolve@1.1.7: languageName: node linkType: hard +"semver@npm:^7.1.2": + version: 7.1.2 + resolution: "semver@npm:7.1.2" + bin: + semver: bin/semver.js + checksum: df72f36e0c32e7952ebfb24dd2745de120aea69305b46db1c24b2f1410a16a40a3772f36788fdc9cc4af8fbf3f643ab97e510c49b524a95cf598eb8884ca6706 + languageName: node + linkType: hard + "set-blocking@npm:^2.0.0, set-blocking@npm:~2.0.0": version: 2.0.0 resolution: "set-blocking@npm:2.0.0" @@ -10149,7 +10265,7 @@ resolve@1.1.7: languageName: node linkType: hard -"supports-color@npm:^5.0.0, supports-color@npm:^5.3.0": +"supports-color@npm:^5.3.0": version: 5.5.0 resolution: "supports-color@npm:5.5.0" dependencies: @@ -10167,16 +10283,6 @@ resolve@1.1.7: languageName: node linkType: hard -"supports-hyperlinks@npm:^1.0.1": - version: 1.0.1 - resolution: "supports-hyperlinks@npm:1.0.1" - dependencies: - has-flag: ^2.0.0 - supports-color: ^5.0.0 - checksum: c6faa21647e8adf445ba31f1a41baaf6f194271a1269a33e758d7cfcdc0bc369cb7dc98a4b5b202df4fa2674aa07210bccaf6a3b7c4001f68cbf4488aadb6d1b - languageName: node - linkType: hard - "supports-hyperlinks@npm:^2.0.0": version: 2.0.0 resolution: "supports-hyperlinks@npm:2.0.0"