diff --git a/dist/hashids.js b/dist/hashids.js index 183999e..aa46d43 100644 --- a/dist/hashids.js +++ b/dist/hashids.js @@ -8,25 +8,31 @@ exports: {} }; factory(mod.exports); - global.Hashids = mod.exports; + global.Hashids = mod.exports.default; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) { "use strict"; - _exports.__esModule = true; + Object.defineProperty(_exports, "__esModule", { + value: true + }); _exports.onlyChars = _exports.withoutChars = _exports.keepUnique = _exports.default = void 0; - function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } + function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } it = o[Symbol.iterator](); return it.next.bind(it); } - function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } + function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } - function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } + function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } - function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } + function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - var Hashids = - /*#__PURE__*/ - function () { + function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } + + function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } + + function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + + var Hashids = /*#__PURE__*/function () { function Hashids(salt, minLength, alphabet, seps) { if (salt === void 0) { salt = ''; @@ -65,7 +71,7 @@ var uniqueAlphabet = keepUnique(alphabetChars); if (uniqueAlphabet.length < minAlphabetLength) { - throw new Error("Hashids: alphabet must contain at least " + minAlphabetLength + " unique characters, provided: " + uniqueAlphabet); + throw new Error("Hashids: alphabet must contain at least " + minAlphabetLength + " unique characters, provided: " + uniqueAlphabet.join('')); } /** `alphabet` should not contains `seps` */ @@ -265,19 +271,8 @@ var lastAlphabet = this.alphabet; var result = []; - for (var _iterator = idArray, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - var _ref; - - if (_isArray) { - if (_i >= _iterator.length) break; - _ref = _iterator[_i++]; - } else { - _i = _iterator.next(); - if (_i.done) break; - _ref = _i.value; - } - - var subId = _ref; + for (var _iterator = _createForOfIteratorHelperLoose(idArray), _step; !(_step = _iterator()).done;) { + var subId = _step.value; var buffer = [lotteryChar].concat(_toConsumableArray(this.salt), _toConsumableArray(lastAlphabet)); var nextAlphabet = shuffle(lastAlphabet, buffer.slice(0, lastAlphabet.length)); result.push(fromAlphabet(Array.from(subId), nextAlphabet)); diff --git a/dist/hashids.js.map b/dist/hashids.js.map index 512bb6e..48decf3 100644 --- a/dist/hashids.js.map +++ b/dist/hashids.js.map @@ -1 +1 @@ -{"version":3,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AU,GAAG,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,oBAAoB,GAAG,SAAvB,oBAAuB,CAAC,KAAD;AAAA,WAC3B,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,CAD2B;AAAA,GAA7B;;AAUA,MAAM,yBAAyB,GAAG,SAA5B,yBAA4B,CAAC,KAAD;AAAA,WAChC,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,SADgC;AAAA,GAAlC;;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 = Array.from(salt)\n const alphabetChars = Array.from(alphabet)\n const sepsChars = Array.from(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 = makeAnyOfCharsRegExp(this.guards)\n this.sepsRegExp = makeAnyOfCharsRegExp(this.seps)\n this.allowedCharsRegExp = makeAtLeastSomeCharRegExp([\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\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 }\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 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 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(Array.from(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 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 makeAnyOfCharsRegExp = (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 makeAtLeastSomeCharRegExp = (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 +{"version":3,"sources":["../lib/hashids.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAEqB,O;AASnB,qBACE,IADF,EAEU,SAFV,EAGE,QAHF,EAIE,IAJF,EAKE;AAAA,UAJA,IAIA;AAJA,QAAA,IAIA,GAJO,EAIP;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,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,SAAS,GAAG,KAAK,CAAC,IAAN,CAAW,IAAX,CAAlB;AACA,UAAM,aAAa,GAAG,KAAK,CAAC,IAAN,CAAW,QAAX,CAAtB;AACA,UAAM,SAAS,GAAG,KAAK,CAAC,IAAN,CAAW,IAAX,CAAlB;AAEA,WAAK,IAAL,GAAY,SAAZ;AAEA,UAAM,cAAc,GAAG,UAAU,CAAC,aAAD,CAAjC;;AAEA,UAAI,cAAc,CAAC,MAAf,GAAwB,iBAA5B,EAA+C;AAC7C,cAAM,IAAI,KAAJ,8CAC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,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 = Array.from(salt)\n const alphabetChars = Array.from(alphabet)\n const sepsChars = Array.from(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.join(\n '',\n )}`,\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 = makeAnyOfCharsRegExp(this.guards)\n this.sepsRegExp = makeAnyOfCharsRegExp(this.seps)\n this.allowedCharsRegExp = makeAtLeastSomeCharRegExp([\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): 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\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 }\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 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 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(Array.from(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 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 makeAnyOfCharsRegExp = (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 makeAtLeastSomeCharRegExp = (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 b5a1320..b3391af 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}}("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);ei)&&((b=Math.ceil(this.alphabet.length/i))>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,r=new Array(n>1?n-1:0),i=1;i0){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),r=n[3===n.length||2===n.length?1:0];if(0===r.length)return[];var i=r[Symbol.iterator]().next().value,s=r.slice(i.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,[i].concat(e(this.salt),e(o)).slice(0,o.length));a.push(c(Array.from(g),d)),o=d}return this._encode(a).join("")!==t?[]:a},t}();t.default=n;var r=16,i=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,r=t.slice(),i=r.length-1,s=0,o=0;i>0;i--,s++){o+=n=e[s%=e.length].codePointAt(0);var a=(n+s+o)%i,h=r[i],l=r[a];r[a]=h,r[i]=l}return r}var p=function(t,e){var n=[];if("bigint"==typeof t){var r=BigInt(e.length);do{n.unshift(e[Number(t%r)]),t/=r}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,r){var i=e.indexOf(r);if(-1===i)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(i);var s=n*e.length+i;if(Number.isSafeInteger(s))return s;if("function"==typeof BigInt)return BigInt(n)*BigInt(e.length)+BigInt(i);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(r,i){return n(t.slice(i*e,(i+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,"\\$&")}})); +!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.default}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(t){"use strict";function e(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||n(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(t,e){if(t){if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);ns)&&((b=Math.ceil(this.alphabet.length/s))>this.seps.length&&(y=b-this.seps.length,(v=this.seps).push.apply(v,e(this.alphabet.slice(0,y))),this.alphabet=this.alphabet.slice(y)));this.alphabet=p(this.alphabet,f);var A=Math.ceil(this.alphabet.length/a);this.alphabet.length<3?(this.guards=this.seps.slice(0,A),this.seps=this.seps.slice(A)):(this.guards=this.alphabet.slice(0,A),this.alphabet=this.alphabet.slice(A)),this.guardsRegExp=m(this.guards),this.sepsRegExp=m(this.seps),this.allowedCharsRegExp=w([].concat(e(this.alphabet),e(this.guards),e(this.seps)))}var r=t.prototype;return r.encode=function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i0){var y=b/2;o=o.slice(y,y+this.minLength)}}return o},r.isValidId=function(t){return this.allowedCharsRegExp.test(t)},r._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 r=t.split(this.guardsRegExp),i=r[3===r.length||2===r.length?1:0];if(0===i.length)return[];for(var o,s=i[Symbol.iterator]().next().value,a=i.slice(s.length).split(this.sepsRegExp),h=this.alphabet,u=[],l=function(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=n(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=t[Symbol.iterator]()).next.bind(r)}(a);!(o=l()).done;){var f=o.value,c=p(h,[s].concat(e(this.salt),e(h)).slice(0,h.length));u.push(g(Array.from(f),c)),h=c}return this._encode(u).join("")!==t?[]:u},t}();t.default=i;var o=16,s=3.5,a=12,h=function(t){return Array.from(new Set(t))};t.keepUnique=h;var u=function(t,e){return t.filter((function(t){return!e.includes(t)}))};t.withoutChars=u;var l=function(t,e){return t.filter((function(t){return e.includes(t)}))};t.onlyChars=l;var f=function(t){return"bigint"==typeof t||!Number.isNaN(Number(t))&&Math.floor(Number(t))===t},c=function(t){return"bigint"==typeof t||t>=0&&Number.isSafeInteger(t)};function p(t,e){if(0===e.length)return t;for(var n,r=t.slice(),i=r.length-1,o=0,s=0;i>0;i--,o++){s+=n=e[o%=e.length].codePointAt(0);var a=(n+o+s)%i,h=r[i],u=r[a];r[a]=h,r[i]=u}return r}var d=function(t,e){var n=[];if("bigint"==typeof t){var r=BigInt(e.length);do{n.unshift(e[Number(t%r)]),t/=r}while(t>BigInt(0))}else do{n.unshift(e[t%e.length]),t=Math.floor(t/e.length)}while(t>0);return n},g=function(t,e){return t.reduce((function(n,r){var i=e.indexOf(r);if(-1===i)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(i);var o=n*e.length+i;if(Number.isSafeInteger(o))return o;if("function"==typeof BigInt)return BigInt(n)*BigInt(e.length)+BigInt(i);throw new Error("Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment")}),0)},b=/^\+?[0-9]+$/,y=function(t){return b.test(t)?parseInt(t,10):NaN},v=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))}))},m=function(t){return new RegExp(t.map((function(t){return I(t)})).sort((function(t,e){return e.length-t.length})).join("|"))},w=function(t){return new RegExp("^["+t.map((function(t){return I(t)})).sort((function(t,e){return e.length-t.length})).join("")+"]+$")},I=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 0669751..a76c520 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","_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","makeAnyOfCharsRegExp","sepsRegExp","allowedCharsRegExp","makeAtLeastSomeCharRegExp","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,KAAK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vD,IAAIlC,EAAQgC,EAAQlH,EAAcvB,OAAS2I,EAG3C,GAFkB3D,OAAO8C,cAAcrB,GAGrC,OAAOA,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,EAAuB,SAA8B4E,GACvD,OAAO,IAAI2B,OAAO3B,EAAM7D,KAAI,SAAUgE,GACpC,OAAOyB,EAAazB,MAGrB0B,MAAK,SAAUhB,EAAGC,GACjB,OAAOA,EAAErI,OAASoI,EAAEpI,UACnBgE,KAAK,OAGNlB,EAA4B,SAAmCyE,GACjE,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 +{"version":3,"sources":["hashids.js"],"names":["global","factory","define","amd","exports","mod","Hashids","default","globalThis","self","this","_exports","_toConsumableArray","arr","Array","isArray","_arrayLikeToArray","_arrayWithoutHoles","iter","Symbol","iterator","Object","from","_iterableToArray","_unsupportedIterableToArray","TypeError","_nonIterableSpread","o","minLen","n","prototype","toString","call","slice","constructor","name","test","len","length","i","arr2","defineProperty","value","onlyChars","withoutChars","keepUnique","salt","minLength","alphabet","seps","saltChars","alphabetChars","sepsChars","uniqueAlphabet","minAlphabetLength","Error","join","sepsLength","diff","_this$seps","filteredSeps","shuffle","sepDiv","Math","ceil","push","apply","guardCount","guardDiv","guards","guardsRegExp","makeAnyOfCharsRegExp","sepsRegExp","allowedCharsRegExp","makeAtLeastSomeCharRegExp","concat","_proto","encode","first","_len","arguments","numbers","_key","ret","every","isIntegerNumber","map","safeParseInt10","String","isPositiveAndFinite","_encode","decode","id","_decode","encodeHex","hex","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","_step","lotteryChar","next","idArray","lastAlphabet","result","_iterator","allowArrayLike","it","done","bind","_createForOfIteratorHelperLoose","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,QAAQG,SAVjC,CAYyB,oBAAfC,WAA6BA,WAA6B,oBAATC,KAAuBA,KAAOC,MAAM,SAAUC,GACvG,aASA,SAASC,EAAmBC,GAAO,OAQnC,SAA4BA,GAAO,GAAIC,MAAMC,QAAQF,GAAM,OAAOG,EAAkBH,GAR1CI,CAAmBJ,IAM7D,SAA0BK,GAAQ,GAAsB,oBAAXC,QAA0BA,OAA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,EAAK,IAAMC,KAG7DzE,EAAwB,SAA+BwE,EAAKE,EAAKpF,GACnE,OAAOxE,MAAMQ,KAAK,CAChBgB,OAAQyB,KAAKC,KAAKwG,EAAIlI,OAASoI,KAC9B,SAAUC,EAAGN,GACd,OAAO/E,EAAIkF,EAAIvI,MAAMoI,EAAQK,GAAML,EAAQ,GAAKK,QAIhDnG,EAAuB,SAA8B0E,GACvD,OAAO,IAAI2B,OAAO3B,EAAM3D,KAAI,SAAU8D,GACpC,OAAOyB,EAAazB,MAGrB0B,MAAK,SAAUhB,EAAGC,GACjB,OAAOA,EAAEzH,OAASwH,EAAExH,UACnBkB,KAAK,OAGNkB,EAA4B,SAAmCuE,GACjE,OAAO,IAAI2B,OAAO,KAAO3B,EAAM3D,KAAI,SAAU8D,GAC3C,OAAOyB,EAAazB,MAGrB0B,MAAK,SAAUhB,EAAGC,GACjB,OAAOA,EAAEzH,OAASwH,EAAExH,UACnBkB,KAAK,IAAM,QAGZqH,EAAe,SAAsBE,GACvC,OAAOA,EAAKC,QAAQ,2BAA4B"} \ No newline at end of file diff --git a/esm/index.js b/esm/index.js index 7b318e6..9951023 100644 --- a/esm/index.js +++ b/esm/index.js @@ -1,14 +1,18 @@ -function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } +function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } it = o[Symbol.iterator](); return it.next.bind(it); } -function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } -function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } +function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } -function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } -var Hashids = -/*#__PURE__*/ -function () { +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } + +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +var Hashids = /*#__PURE__*/function () { function Hashids(salt, minLength, alphabet, seps) { if (salt === void 0) { salt = ''; @@ -47,7 +51,7 @@ function () { var uniqueAlphabet = keepUnique(alphabetChars); if (uniqueAlphabet.length < minAlphabetLength) { - throw new Error("Hashids: alphabet must contain at least " + minAlphabetLength + " unique characters, provided: " + uniqueAlphabet); + throw new Error("Hashids: alphabet must contain at least " + minAlphabetLength + " unique characters, provided: " + uniqueAlphabet.join('')); } /** `alphabet` should not contains `seps` */ @@ -247,19 +251,8 @@ function () { var lastAlphabet = this.alphabet; var result = []; - for (var _iterator = idArray, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - var _ref; - - if (_isArray) { - if (_i >= _iterator.length) break; - _ref = _iterator[_i++]; - } else { - _i = _iterator.next(); - if (_i.done) break; - _ref = _i.value; - } - - var subId = _ref; + for (var _iterator = _createForOfIteratorHelperLoose(idArray), _step; !(_step = _iterator()).done;) { + var subId = _step.value; var buffer = [lotteryChar].concat(_toConsumableArray(this.salt), _toConsumableArray(lastAlphabet)); var nextAlphabet = shuffle(lastAlphabet, buffer.slice(0, lastAlphabet.length)); result.push(fromAlphabet(Array.from(subId), nextAlphabet)); diff --git a/esm/index.js.map b/esm/index.js.map index f6dfbc0..9b95401 100644 --- a/esm/index.js.map +++ b/esm/index.js.map @@ -1 +1 @@ -{"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,GAAG,KAAK,CAAC,IAAN,CAAW,IAAX,CAAlB;AACA,QAAM,aAAa,GAAG,KAAK,CAAC,IAAN,CAAW,QAAX,C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AAJ;AAAA,WAAU,CAAC,CAAC,MAAF,GAAW,CAAC,CAAC,MAAvB;AAAA,GAJH,EAKF,IALE,CAKG,EALH,CADP,SADgC;AAAA,CAAlC;;AAUA,IAAM,YAAY,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 = Array.from(salt)\n const alphabetChars = Array.from(alphabet)\n const sepsChars = Array.from(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 = makeAnyOfCharsRegExp(this.guards)\n this.sepsRegExp = makeAnyOfCharsRegExp(this.seps)\n this.allowedCharsRegExp = makeAtLeastSomeCharRegExp([\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\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 }\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 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 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(Array.from(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 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 makeAnyOfCharsRegExp = (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 makeAtLeastSomeCharRegExp = (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 +{"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;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AG,SAA5B,yBAA4B,CAAC,KAAD;AAAA,SAChC,IAAI,MAAJ,QACO,KAAK,CACP,GADE,CACE,UAAC,IAAD;AAAA,WAAU,YAAY,CAAC,IAAD,CAAtB;AAAA,GADF,EAEH;AACA;AAHG,GAIF,IAJE,CAIG,UAAC,CAAD,EAAI,CAAJ;AAAA,WAAU,CAAC,CAAC,MAAF,GAAW,CAAC,CAAC,MAAvB;AAAA,GAJH,EAKF,IALE,CAKG,EALH,CADP,SADgC;AAAA,CAAlC;;AAUA,IAAM,YAAY,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 = Array.from(salt)\n const alphabetChars = Array.from(alphabet)\n const sepsChars = Array.from(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.join(\n '',\n )}`,\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 = makeAnyOfCharsRegExp(this.guards)\n this.sepsRegExp = makeAnyOfCharsRegExp(this.seps)\n this.allowedCharsRegExp = makeAtLeastSomeCharRegExp([\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): 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\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 }\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 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 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(Array.from(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 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 makeAnyOfCharsRegExp = (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 makeAtLeastSomeCharRegExp = (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