Files
copilot-toolbox-sdfdsfds/node_modules/@ant-design/pro-utils/es/nanoid/index.js
2026-01-16 01:51:36 +00:00

31 lines
945 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* eslint-disable prefer-const */
var index = 0;
var genNanoid = function genNanoid() {
var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 21;
if (typeof window === 'undefined') return (index += 1).toFixed(0);
if (!window.crypto) return (index += 1).toFixed(0);
var e = '',
r = crypto.getRandomValues(new Uint8Array(t));
// eslint-disable-next-line no-param-reassign
for (; t--;) {
var n = 63 & r[t];
e += n < 36 ? n.toString(36) : n < 62 ? (n - 26).toString(36).toUpperCase() : n < 63 ? '_' : '-';
}
return e;
};
/**
* 生成uuid如果不支持 randomUUID就用 genNanoid
*
* @returns string
*/
export var nanoid = function nanoid() {
if (typeof window === 'undefined') return genNanoid();
// @ts-ignore
if (window.crypto && window.crypto.randomUUID && typeof crypto.randomUUID == 'function') {
// @ts-ignore
return crypto.randomUUID();
}
return genNanoid();
};