提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
513 B

3 weeks ago
3 weeks ago
3 weeks ago
  1. /* @ts-self-types="./index.d.ts" */
  2. let urlAlphabet =
  3. 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
  4. export let customAlphabet = (alphabet, defaultSize = 21) => {
  5. return (size = defaultSize) => {
  6. let id = ''
  7. let i = size | 0
  8. while (i--) {
  9. id += alphabet[(Math.random() * alphabet.length) | 0]
  10. }
  11. return id
  12. }
  13. }
  14. export let nanoid = (size = 21) => {
  15. let id = ''
  16. let i = size | 0
  17. while (i--) {
  18. id += urlAlphabet[(Math.random() * 64) | 0]
  19. }
  20. return id
  21. }