Comparing version 2.2.8 to 2.2.9
@@ -1,3 +0,2 @@ | ||
import Hashids from '../lib/hashids' | ||
import Hashids from './hashids' | ||
export = Hashids |
@@ -1,1 +0,1 @@ | ||
module.exports = require('../dist/hashids.js').default | ||
module.exports = require('./hashids.js').default |
@@ -1,434 +0,2 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define("Hashids", ["exports"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports); | ||
global.Hashids = mod.exports.default; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) { | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports.onlyChars = _exports.withoutChars = _exports.keepUnique = _exports.default = void 0; | ||
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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
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 _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); } | ||
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 = ''; | ||
} | ||
if (minLength === void 0) { | ||
minLength = 0; | ||
} | ||
if (alphabet === void 0) { | ||
alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; | ||
} | ||
if (seps === void 0) { | ||
seps = 'cfhistuCFHISTU'; | ||
} | ||
this.minLength = minLength; | ||
if (typeof minLength !== 'number') { | ||
throw new TypeError("Hashids: Provided 'minLength' has to be a number (is " + typeof minLength + ")"); | ||
} | ||
if (typeof salt !== 'string') { | ||
throw new TypeError("Hashids: Provided 'salt' has to be a string (is " + typeof salt + ")"); | ||
} | ||
if (typeof alphabet !== 'string') { | ||
throw new TypeError("Hashids: Provided alphabet has to be a string (is " + typeof alphabet + ")"); | ||
} | ||
var saltChars = Array.from(salt); | ||
var alphabetChars = Array.from(alphabet); | ||
var sepsChars = Array.from(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.join('')); | ||
} | ||
/** `alphabet` should not contains `seps` */ | ||
this.alphabet = withoutChars(uniqueAlphabet, sepsChars); | ||
/** `seps` should contain only characters present in `alphabet` */ | ||
var filteredSeps = onlyChars(sepsChars, uniqueAlphabet); | ||
this.seps = shuffle(filteredSeps, saltChars); | ||
var sepsLength; | ||
var diff; | ||
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; | ||
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, saltChars); | ||
var guardCount = Math.ceil(this.alphabet.length / guardDiv); | ||
if (this.alphabet.length < 3) { | ||
this.guards = this.seps.slice(0, guardCount); | ||
this.seps = this.seps.slice(guardCount); | ||
} else { | ||
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([].concat(_toConsumableArray(this.alphabet), _toConsumableArray(this.guards), _toConsumableArray(this.seps))); | ||
} | ||
var _proto = Hashids.prototype; | ||
_proto.encode = function encode(first) { | ||
for (var _len = arguments.length, numbers = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
numbers[_key - 1] = arguments[_key]; | ||
} | ||
var ret = ''; | ||
if (Array.isArray(first)) { | ||
numbers = first; | ||
} else { | ||
// eslint-disable-next-line eqeqeq | ||
numbers = [].concat(_toConsumableArray(first != null ? [first] : []), _toConsumableArray(numbers)); | ||
} | ||
if (!numbers.length) { | ||
return ret; | ||
} | ||
if (!numbers.every(isIntegerNumber)) { | ||
numbers = numbers.map(function (n) { | ||
return typeof n === 'bigint' || typeof n === 'number' ? n : safeParseInt10(String(n)); | ||
}); | ||
} | ||
if (!numbers.every(isPositiveAndFinite)) { | ||
return ret; | ||
} | ||
return this._encode(numbers).join(''); | ||
}; | ||
_proto.decode = function decode(id) { | ||
if (!id || typeof id !== 'string' || id.length === 0) return []; | ||
return this._decode(id); | ||
} | ||
/** | ||
* @description Splits a hex string into groups of 12-digit hexadecimal numbers, | ||
* then prefixes each with '1' and encodes the resulting array of numbers | ||
* | ||
* Encoding '00000000000f00000000000f000f' would be the equivalent of: | ||
* Hashids.encode([0x100000000000f, 0x100000000000f, 0x1000f]) | ||
* | ||
* This means that if your environment supports BigInts, | ||
* you will get different (shorter) results if you provide | ||
* a BigInt representation of your hex and use `encode` directly, e.g.: | ||
* Hashids.encode(BigInt(`0x${hex}`)) | ||
* | ||
* To decode such a representation back to a hex string, use the following snippet: | ||
* Hashids.decode(id)[0].toString(16) | ||
*/ | ||
; | ||
_proto.encodeHex = function encodeHex(hex) { | ||
switch (typeof hex) { | ||
case 'bigint': | ||
hex = hex.toString(16); | ||
break; | ||
case 'string': | ||
if (!/^[0-9a-fA-F]+$/.test(hex)) return ''; | ||
break; | ||
default: | ||
throw new Error("Hashids: The provided value is neither a string, nor a BigInt (got: " + typeof hex + ")"); | ||
} | ||
var numbers = splitAtIntervalAndMap(hex, 12, function (part) { | ||
return parseInt("1" + part, 16); | ||
}); | ||
return this.encode(numbers); | ||
}; | ||
_proto.decodeHex = function decodeHex(id) { | ||
return this.decode(id).map(function (number) { | ||
return number.toString(16).slice(1); | ||
}).join(''); | ||
}; | ||
_proto._encode = function _encode(numbers) { | ||
var _this = this; | ||
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); | ||
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 buffer = lottery.concat(_this.salt, alphabet); | ||
alphabet = shuffle(alphabet, buffer); | ||
var last = toAlphabet(number, alphabet); | ||
(_ret = ret).push.apply(_ret, _toConsumableArray(last)); | ||
if (i + 1 < numbers.length) { | ||
var charCode = last[0].codePointAt(0) + i; | ||
var extraNumber = typeof number === 'bigint' ? Number(number % BigInt(charCode)) : number % charCode; | ||
ret.push(seps[extraNumber % seps.length]); | ||
} | ||
}); | ||
if (ret.length < this.minLength) { | ||
var prefixGuardIndex = (numbersIdInt + ret[0].codePointAt(0)) % guards.length; | ||
ret.unshift(guards[prefixGuardIndex]); | ||
if (ret.length < this.minLength) { | ||
var suffixGuardIndex = (numbersIdInt + ret[2].codePointAt(0)) % guards.length; | ||
ret.push(guards[suffixGuardIndex]); | ||
} | ||
} | ||
var halfLength = Math.floor(alphabet.length / 2); | ||
while (ret.length < this.minLength) { | ||
var _ret2, _ret3; | ||
alphabet = shuffle(alphabet, alphabet); | ||
(_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) { | ||
var halfOfExcess = excess / 2; | ||
ret = ret.slice(halfOfExcess, halfOfExcess + this.minLength); | ||
} | ||
} | ||
return ret; | ||
}; | ||
_proto.isValidId = function isValidId(id) { | ||
return this.allowedCharsRegExp.test(id); | ||
}; | ||
_proto._decode = function _decode(id) { | ||
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.join('') + this.seps.join('') + this.alphabet.join('') + ")"); | ||
} | ||
var idGuardsArray = id.split(this.guardsRegExp); | ||
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); | ||
var lastAlphabet = this.alphabet; | ||
var result = []; | ||
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)); | ||
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; | ||
}; | ||
return Hashids; | ||
}(); | ||
_exports.default = Hashids; | ||
var minAlphabetLength = 16; | ||
var sepDiv = 3.5; | ||
var guardDiv = 12; | ||
var keepUnique = function keepUnique(content) { | ||
return Array.from(new Set(content)); | ||
}; | ||
_exports.keepUnique = keepUnique; | ||
var withoutChars = function withoutChars(chars, _withoutChars) { | ||
return chars.filter(function (char) { | ||
return !_withoutChars.includes(char); | ||
}); | ||
}; | ||
_exports.withoutChars = withoutChars; | ||
var onlyChars = function onlyChars(chars, keepChars) { | ||
return chars.filter(function (char) { | ||
return keepChars.includes(char); | ||
}); | ||
}; | ||
_exports.onlyChars = onlyChars; | ||
var isIntegerNumber = function isIntegerNumber(n) { | ||
return typeof n === 'bigint' || !Number.isNaN(Number(n)) && Math.floor(Number(n)) === n; | ||
}; | ||
var isPositiveAndFinite = function isPositiveAndFinite(n) { | ||
return typeof n === 'bigint' || n >= 0 && Number.isSafeInteger(n); | ||
}; | ||
function shuffle(alphabetChars, saltChars) { | ||
if (saltChars.length === 0) { | ||
return alphabetChars; | ||
} | ||
var integer; | ||
var transformed = alphabetChars.slice(); | ||
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 | ||
var a = transformed[i]; | ||
var b = transformed[j]; | ||
transformed[j] = a; | ||
transformed[i] = b; | ||
} | ||
return transformed; | ||
} | ||
var toAlphabet = function toAlphabet(input, alphabetChars) { | ||
var id = []; | ||
if (typeof input === 'bigint') { | ||
var alphabetLength = BigInt(alphabetChars.length); | ||
do { | ||
id.unshift(alphabetChars[Number(input % alphabetLength)]); | ||
input = input / alphabetLength; | ||
} while (input > BigInt(0)); | ||
} else { | ||
do { | ||
id.unshift(alphabetChars[input % alphabetChars.length]); | ||
input = Math.floor(input / alphabetChars.length); | ||
} while (input > 0); | ||
} | ||
return id; | ||
}; | ||
var fromAlphabet = function fromAlphabet(inputChars, alphabetChars) { | ||
return inputChars.reduce(function (carry, item) { | ||
var 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); | ||
} | ||
var value = carry * alphabetChars.length + index; | ||
var 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("Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment"); | ||
} | ||
} | ||
}, 0); | ||
}; | ||
var safeToParseNumberRegExp = /^\+?[0-9]+$/; | ||
var safeParseInt10 = function safeParseInt10(str) { | ||
return safeToParseNumberRegExp.test(str) ? parseInt(str, 10) : NaN; | ||
}; | ||
var splitAtIntervalAndMap = function splitAtIntervalAndMap(str, nth, map) { | ||
return Array.from({ | ||
length: Math.ceil(str.length / nth) | ||
}, function (_, index) { | ||
return map(str.slice(index * nth, (index + 1) * nth)); | ||
}); | ||
}; | ||
var makeAnyOfCharsRegExp = function makeAnyOfCharsRegExp(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 makeAtLeastSomeCharRegExp = function makeAtLeastSomeCharRegExp(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, '\\$&'); | ||
}; | ||
}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Hashids",[],e):"object"==typeof exports?exports.Hashids=e():t.Hashids=e()}(self,(function(){return(()=>{"use strict";var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{default:()=>l});const s=t=>"bigint"==typeof t||!Number.isNaN(Number(t))&&Math.floor(Number(t))===t,i=t=>"bigint"==typeof t||t>=0&&Number.isSafeInteger(t);function n(t,e){if(0===e.length)return t;let s;const i=[...t];for(let t=i.length-1,n=0,r=0;t>0;t--,n++){n%=e.length,r+=s=e[n].codePointAt(0);const h=(s+n+r)%t,o=i[t],a=i[h];i[h]=o,i[t]=a}return i}const r=(t,e)=>t.reduce(((s,i)=>{const n=e.indexOf(i);if(-1===n)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 s)return s*BigInt(e.length)+BigInt(n);const r=s*e.length+n;if(Number.isSafeInteger(r))return r;if("function"==typeof BigInt)return BigInt(s)*BigInt(e.length)+BigInt(n);throw new Error("Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment")}),0),h=/^\+?\d+$/,o=t=>new RegExp(t.map((t=>a(t))).sort(((t,e)=>e.length-t.length)).join("|")),a=t=>t.replace(/[\s#$()*+,.?[\\\]^{|}-]/g,"\\$&");class l{constructor(t="",e=0,s="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",i="cfhistuCFHISTU"){if(this.minLength=e,"number"!=typeof e)throw new TypeError(`Hashids: Provided 'minLength' has to be a number (is ${typeof e})`);if("string"!=typeof t)throw new TypeError(`Hashids: Provided 'salt' has to be a string (is ${typeof t})`);if("string"!=typeof s)throw new TypeError(`Hashids: Provided alphabet has to be a string (is ${typeof s})`);const r=Array.from(t),h=Array.from(s),l=Array.from(i);this.salt=r;const g=[...new Set(h)];var p;if(g.length<16)throw new Error(`Hashids: alphabet must contain at least 16 unique characters, provided: ${g.join("")}`);this.alphabet=(p=l,g.filter((t=>!p.includes(t))));const c=(d=g,l.filter((t=>d.includes(t))));var d;let f,u;this.seps=n(c,r),(0===this.seps.length||this.alphabet.length/this.seps.length>3.5)&&(f=Math.ceil(this.alphabet.length/3.5),f>this.seps.length&&(u=f-this.seps.length,this.seps.push(...this.alphabet.slice(0,u)),this.alphabet=this.alphabet.slice(u))),this.alphabet=n(this.alphabet,r);const b=Math.ceil(this.alphabet.length/12);this.alphabet.length<3?(this.guards=this.seps.slice(0,b),this.seps=this.seps.slice(b)):(this.guards=this.alphabet.slice(0,b),this.alphabet=this.alphabet.slice(b)),this.guardsRegExp=o(this.guards),this.sepsRegExp=o(this.seps),this.allowedCharsRegExp=(t=>new RegExp(`^[${t.map((t=>a(t))).sort(((t,e)=>e.length-t.length)).join("")}]+$`))([...this.alphabet,...this.guards,...this.seps])}encode(t,...e){let n=Array.isArray(t)?t:[...null!=t?[t]:[],...e];return 0===n.length?"":(n.every(s)||(n=n.map((t=>{return"bigint"==typeof t||"number"==typeof t?t:(e=String(t),h.test(e)?Number.parseInt(e,10):Number.NaN);var e}))),n.every(i)?this._encode(n).join(""):"")}decode(t){return t&&"string"==typeof t&&0!==t.length?this._decode(t):[]}encodeHex(t){let e=t;switch(typeof e){case"bigint":e=e.toString(16);break;case"string":if(!/^[\dA-Fa-f]+$/.test(e))return"";break;default:throw new Error(`Hashids: The provided value is neither a string, nor a BigInt (got: ${typeof e})`)}const s=(i=e,12,n=t=>Number.parseInt(`1${t}`,16),Array.from({length:Math.ceil(i.length/12)},((t,e)=>n(i.slice(12*e,12*(e+1))))));var i,n;return this.encode(s)}decodeHex(t){return this.decode(t).map((t=>t.toString(16).slice(1))).join("")}isValidId(t){return this.allowedCharsRegExp.test(t)}_encode(t){let{alphabet:e}=this;const s=t.reduce(((t,e,s)=>t+("bigint"==typeof e?Number(e%BigInt(s+100)):e%(s+100))),0);let i=[e[s%e.length]];const r=[...i],{seps:h}=this,{guards:o}=this;if(t.forEach(((s,o)=>{const a=r.concat(this.salt,e);e=n(e,a);const l=((t,e)=>{const s=[];let i=t;if("bigint"==typeof i){const t=BigInt(e.length);do{s.unshift(e[Number(i%t)]),i/=t}while(i>BigInt(0))}else do{s.unshift(e[i%e.length]),i=Math.floor(i/e.length)}while(i>0);return s})(s,e);if(i.push(...l),o+1<t.length){const t=l[0].codePointAt(0)+o,e="bigint"==typeof s?Number(s%BigInt(t)):s%t;i.push(h[e%h.length])}})),i.length<this.minLength){const t=(s+i[0].codePointAt(0))%o.length;if(i.unshift(o[t]),i.length<this.minLength){const t=(s+i[2].codePointAt(0))%o.length;i.push(o[t])}}const a=Math.floor(e.length/2);for(;i.length<this.minLength;){e=n(e,e),i.unshift(...e.slice(a)),i.push(...e.slice(0,a));const t=i.length-this.minLength;if(t>0){const e=t/2;i=i.slice(e,e+this.minLength)}}return i}_decode(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("")})`);const e=t.split(this.guardsRegExp),s=e[3===e.length||2===e.length?1:0];if(0===s.length)return[];const i=s[Symbol.iterator]().next().value,h=s.slice(i.length).split(this.sepsRegExp);let o=this.alphabet;const a=[];for(const t of h){const e=n(o,[i,...this.salt,...o].slice(0,o.length));a.push(r(Array.from(t),e)),o=e}return this._encode(a).join("")!==t?[]:a}}return e.default})()})); | ||
//# sourceMappingURL=hashids.js.map |
{ | ||
"name": "hashids-esm", | ||
"type": "module", | ||
"main": "index.js" | ||
"main": "hashids.js" | ||
} |
178
package.json
{ | ||
"author": "hashids.org <npm@invent.life> (https://github.com/hashids)", | ||
"name": "hashids", | ||
"description": "Generate YouTube-like ids from numbers. Use Hashids when you do not want to expose your database ids to the user.", | ||
"keywords": [ | ||
"hashids", | ||
"hashid", | ||
"hash", | ||
"ids", | ||
"youtube", | ||
"bitly", | ||
"obfuscate", | ||
"encode", | ||
"decode", | ||
"encrypt", | ||
"decrypt" | ||
], | ||
"homepage": "http://hashids.org/javascript", | ||
"bugs": { | ||
"url": "https://github.com/niieani/hashids.js/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/niieani/hashids.js.git" | ||
}, | ||
"license": "MIT", | ||
"author": "hashids.org <npm@invent.life> (https://github.com/hashids)", | ||
"contributors": [ | ||
@@ -17,56 +39,49 @@ { | ||
], | ||
"version": "2.2.8", | ||
"homepage": "http://hashids.org/javascript", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/niieani/hashids.js.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/niieani/hashids.js/issues" | ||
}, | ||
"files": [ | ||
"cjs", | ||
"esm", | ||
"dist", | ||
"lib" | ||
], | ||
"main": "cjs/index.js", | ||
"module": "esm/index.js", | ||
"exports": { | ||
".": { | ||
"import": "./esm/index.js", | ||
"import": "./esm/hashids.js", | ||
"require": "./cjs/index.js" | ||
}, | ||
"./*": { | ||
"import": "./esm/*.js", | ||
"require": "./cjs/*.js" | ||
}, | ||
"./cjs": { | ||
"require": "./cjs/index.js" | ||
}, | ||
"./cjs/": { | ||
"require": "./cjs/" | ||
"./cjs/*": { | ||
"require": "./cjs/*.js" | ||
}, | ||
"./esm/": { | ||
"import": "./esm/" | ||
"./esm/*": { | ||
"import": "./esm/*.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "cjs/index.js", | ||
"unpkg": "dist/hashids.js", | ||
"module": "esm/hashids.js", | ||
"source": "src/hashids.ts", | ||
"files": [ | ||
"cjs", | ||
"esm", | ||
"dist", | ||
"lib" | ||
], | ||
"scripts": { | ||
"lint": "eslint lib/* tests/*", | ||
"prettier:check": "prettier --check lib/* tests*/*", | ||
"prettier:write": "prettier --write lib/* tests*/*", | ||
"test": "yarn prettier:check && yarn lint && yarn jest", | ||
"coverage": "jest --coverage && cat coverage/lcov.info | coveralls", | ||
"build:umd": "babel lib/hashids.ts --source-maps -o dist/hashids.js && replace-in-files --string='global.Hashids = mod.exports;' --replacement='global.Hashids = mod.exports.default;' dist/hashids.js", | ||
"build:esm": "BABEL_MODULES=1 babel lib/hashids.ts --source-maps -o esm/index.js", | ||
"minify": "cd dist && terser hashids.js -o hashids.min.js --source-map \"url=hashids.min.js.map\" --compress --mangle", | ||
"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", | ||
"release": "./release.sh", | ||
"semantic-release": "semantic-release", | ||
"benchmark": "yarn ts-node -O '{\"module\": \"commonjs\"}' -T tests/benchmark" | ||
"benchmark": "yarn ts-node -O '{\"module\": \"commonjs\"}' -T tests/benchmark", | ||
"postinstallDev": "yarn prepare", | ||
"prepare": "rrun husky install .config/husky && yarn beemo create-config", | ||
"build": "yarn build:cjs && yarn build:esm && yarn build:umd", | ||
"release": "beemo run-script release", | ||
"build:cjs": "yarn rrun tsc --outDir cjs --module commonjs --target es6 -p tsconfig.build.json", | ||
"build:esm": "yarn rrun tsc --outDir esm --module esnext --target es6 -p tsconfig.build.json && ./add-extension.sh", | ||
"build:umd": "beemo webpack --entry=./src/hashids.ts --env 'outDir=dist' --env 'moduleTarget=umd' --env 'engineTarget=web' --env 'codeTarget=es6' --env 'name=Hashids' --env 'export=default' --env 'filename=hashids.js'", | ||
"clean": "git clean -dfX --exclude=node_modules src && beemo typescript:sync-project-refs", | ||
"test:lint": "rrun eslint 'src/**'", | ||
"test:code": "beemo jest", | ||
"test:types": "yarn rrun tsc --noEmit", | ||
"test:format": "yarn rrun prettier --check \"./{src,tests}/**/*[!.d].{.js,jsx,ts,tsx,json,md}\"", | ||
"test": "yarn test:format && yarn test:types && yarn test:lint && yarn test:code", | ||
"format": "yarn rrun prettier --write \"./{src,tests}/**/!(*.d).{.js,jsx,ts,tsx,json,md}\"" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "yarn run lint && yarn run test" | ||
} | ||
}, | ||
"browserslist": [ | ||
@@ -79,62 +94,27 @@ "last 2 version", | ||
"devDependencies": { | ||
"@babel/cli": "^7.12.10", | ||
"@babel/core": "^7.12.10", | ||
"@babel/helper-plugin-utils": "^7.10.4", | ||
"@babel/plugin-syntax-bigint": "^7.8.3", | ||
"@babel/plugin-transform-destructuring": "^7.12.1", | ||
"@babel/plugin-transform-modules-umd": "^7.12.1", | ||
"@babel/plugin-transform-spread": "^7.12.1", | ||
"@babel/preset-env": "^7.12.11", | ||
"@babel/preset-typescript": "^7.12.7", | ||
"@babel/register": "^7.12.10", | ||
"@types/jest": "^26.0.19", | ||
"@types/node": "^14.14.14", | ||
"@typescript-eslint/eslint-plugin": "^4.10.0", | ||
"@typescript-eslint/parser": "^4.10.0", | ||
"@yarnpkg/pnpify": "^2.4.0", | ||
"coveralls": "^3.1.0", | ||
"eslint": "^7.15.0", | ||
"eslint-config-prettier": "^7.0.0", | ||
"eslint-import-resolver-node": "^0.3.4", | ||
"eslint-plugin-eslint-comments": "^3.2.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-jest": "^24.1.3", | ||
"husky": "^4.3.6", | ||
"jest": "^26.6.3", | ||
"nodemark": "^0.3.0", | ||
"prettier": "^2.2.1", | ||
"replace-in-files-cli": "^1.0.0", | ||
"require-from-web": "^1.2.0", | ||
"semantic-release": "^17.3.0", | ||
"terser": "^5.5.1", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.1.3" | ||
"@niieani/scaffold": "^1.3.4" | ||
}, | ||
"license": "MIT", | ||
"keywords": [ | ||
"hashids", | ||
"hashid", | ||
"hash", | ||
"ids", | ||
"youtube", | ||
"bitly", | ||
"obfuscate", | ||
"encode", | ||
"decode", | ||
"encrypt", | ||
"decrypt" | ||
], | ||
"prettier": { | ||
"semi": false, | ||
"tabWidth": 2, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"arrowParens": "always", | ||
"bracketSpacing": false | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"jest": { | ||
"collectCoverageFrom": [ | ||
"lib/**/*.ts" | ||
"release": { | ||
"branches": [ | ||
"+([0-9])?(.{+([0-9]),x}).x", | ||
"master", | ||
{ | ||
"name": "main", | ||
"channel": false | ||
}, | ||
"next", | ||
{ | ||
"name": "beta", | ||
"prerelease": true | ||
}, | ||
{ | ||
"name": "alpha", | ||
"prerelease": true | ||
} | ||
] | ||
} | ||
}, | ||
"version": "2.2.9" | ||
} |
@@ -58,4 +58,17 @@ [![hashids](http://hashids.org/public/img/hashids.gif 'Hashids')](http://hashids.org/) | ||
Import or require based on the environment (see above). | ||
Import or require based on the environment (see above). If you want to use the CommonJS module syntax (`require`), you'll need to install the Node.js types from the `DefinitelyTyped` repository. | ||
``` | ||
npm install @types/node | ||
``` | ||
If you want to use the ESM syntax (`import`), you will need to include the following options in your `tsconfig.json`. | ||
```json | ||
{ | ||
"allowSyntheticDefaultImports": true, | ||
"esModuleInterop": true | ||
} | ||
``` | ||
If you get errors stating: `Cannot find name 'BigInt'`, add [`"esnext.bigint"`](https://github.com/microsoft/TypeScript/blob/master/src/lib/esnext.bigint.d.ts) or [`"esnext"`](https://github.com/microsoft/TypeScript/blob/master/src/lib/esnext.d.ts) to your `tsconfig.json` file, under `"lib"`: | ||
@@ -62,0 +75,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
20
261
95699
686
1