@antdv/pro-utils
Version:
@antdv/pro-utils
42 lines (41 loc) • 1.53 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
nanoid: () => nanoid
});
module.exports = __toCommonJS(stdin_exports);
let index = 0;
let genNanoid = (t = 21) => {
if (typeof window === "undefined") return (index += 1).toFixed(0);
if (!window.crypto) return (index += 1).toFixed(0);
let e = "";
let r = crypto.getRandomValues(new Uint8Array(t));
for (; t--; ) {
let n = 63 & r[t];
e += n < 36 ? n.toString(36) : n < 62 ? (n - 26).toString(36).toUpperCase() : n < 63 ? "_" : "-";
}
return e;
};
function nanoid() {
if (typeof window === "undefined") return genNanoid();
if (window.crypto && window.crypto.randomUUID && typeof crypto.randomUUID == "function") {
return crypto.randomUUID();
}
return genNanoid();
}