mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-06-10 20:29:28 +08:00
16 lines
434 B
JavaScript
16 lines
434 B
JavaScript
|
|
/**
|
|
* 生成指定长度的uuid
|
|
* @param {number} = 长度
|
|
*/
|
|
export function generateUUID(length = 36) {
|
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
let result = '';
|
|
|
|
const validLength = Math.max(1, Math.floor(Number(length)) || 36);
|
|
for (let i = 0; i < validLength; i++) {
|
|
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
|
}
|
|
|
|
return result;
|
|
} |