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.

33 lines
983 B

2 years ago
  1. /**
  2. * Generate URL-friendly unique ID. This method uses the non-secure
  3. * predictable random generator with bigger collision probability.
  4. *
  5. * ```js
  6. * import { nanoid } from 'nanoid/non-secure'
  7. * model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"
  8. * ```
  9. *
  10. * @param size Size of the ID. The default size is 21.
  11. * @returns A random string.
  12. */
  13. export function nanoid(size?: number): string
  14. /**
  15. * Generate a unique ID based on a custom alphabet.
  16. * This method uses the non-secure predictable random generator
  17. * with bigger collision probability.
  18. *
  19. * @param alphabet Alphabet used to generate the ID.
  20. * @param defaultSize Size of the ID. The default size is 21.
  21. * @returns A random string generator.
  22. *
  23. * ```js
  24. * import { customAlphabet } from 'nanoid/non-secure'
  25. * const nanoid = customAlphabet('0123456789абвгдеё', 5)
  26. * model.id = //=> "8ё56а"
  27. * ```
  28. */
  29. export function customAlphabet(
  30. alphabet: string,
  31. defaultSize?: number
  32. ): (size?: number) => string