UNPKG

js-uploader

Version:
48 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.nanoid = exports.customAlphabet = exports.customRandom = exports.random = exports.urlAlphabet = void 0; exports.urlAlphabet = 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'; exports.random = function (bytes) { return crypto.getRandomValues(new Uint8Array(bytes)); }; exports.customRandom = function (alphabet, defaultSize, getRandom) { var mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1; var step = -~((1.6 * mask * defaultSize) / alphabet.length); return function (size) { if (size === void 0) { size = defaultSize; } var id = ''; while (true) { var bytes = getRandom(step); var j = step; while (j--) { id += alphabet[bytes[j] & mask] || ''; if (id.length === size) return id; } } }; }; exports.customAlphabet = function (alphabet, size) { if (size === void 0) { size = 21; } return exports.customRandom(alphabet, size, exports.random); }; exports.nanoid = function (size) { if (size === void 0) { size = 21; } return crypto.getRandomValues(new Uint8Array(size)).reduce(function (id, byte) { byte &= 63; if (byte < 36) { // `0-9a-z` id += byte.toString(36); } else if (byte < 62) { // `A-Z` id += (byte - 26).toString(36).toUpperCase(); } else if (byte > 62) { id += '-'; } else { id += '_'; } return id; }, ''); }; //# sourceMappingURL=nanoid.js.map