mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-06 02:50:13 +08:00
22 lines
497 B
JavaScript
22 lines
497 B
JavaScript
|
|
let urlAlphabet =
|
||
|
|
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
|
||
|
|
let customAlphabet = (alphabet, defaultSize = 21) => {
|
||
|
|
return (size = defaultSize) => {
|
||
|
|
let id = ''
|
||
|
|
let i = size | 0
|
||
|
|
while (i--) {
|
||
|
|
id += alphabet[(Math.random() * alphabet.length) | 0]
|
||
|
|
}
|
||
|
|
return id
|
||
|
|
}
|
||
|
|
}
|
||
|
|
let nanoid = (size = 21) => {
|
||
|
|
let id = ''
|
||
|
|
let i = size | 0
|
||
|
|
while (i--) {
|
||
|
|
id += urlAlphabet[(Math.random() * 64) | 0]
|
||
|
|
}
|
||
|
|
return id
|
||
|
|
}
|
||
|
|
export { nanoid, customAlphabet }
|