-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdc2ee0
commit 4835ad2
Showing
7 changed files
with
498 additions
and
985 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const urlAlphabet = | ||
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict' | ||
|
||
/** | ||
* nano 唯一id生成器 | ||
* 比传统 uuid 生成快 60% | ||
* | ||
* https://github.com/ai/nanoid | ||
* | ||
* 默认设置size为21,每秒生成一亿份id,连续工作四个世纪产生一次冲突的概率为 1%。 | ||
* html标签的id属性不能以数字作为前缀,所以以字母作为前缀 | ||
*/ | ||
export function nanoid(size = 21, prefix = 'T'): string { | ||
let id = '' | ||
let i = size | ||
while (i-- != 0) { | ||
id += urlAlphabet[(Math.random() * 64) | 0] | ||
|
||
} | ||
return prefix + id | ||
} |
Oops, something went wrong.