Function customAlphabet

  • Generate secure unique ID with custom alphabet.

    Alphabet must contain 256 symbols or less. Otherwise, the generator will not be secure.


    • alphabet: string

      Alphabet used to generate the ID.

    • Optional defaultSize: number

      Size of the ID. The default size is 21.

    Returns ((size?) => string)

    A random string generator.

    const { customAlphabet } = require('nanoid')
    const nanoid = customAlphabet('0123456789абвгдеё', 5)
    nanoid() //=> "8ё56а"
      • (size?): string
      • Parameters

        • Optional size: number

        Returns string

Generated using TypeDoc