@arcmantle/library
    Preparing search index...

    Function customRandom

    • Generate unique ID with custom random generator and alphabet.

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

      import { customRandom } from 'nanoid/format'

      const nanoid = customRandom('abcdef', 5, size => {
      const random = []
      for (let i = 0; i < size; i++) {
      random.push(randomByte())
      }
      return random
      })

      nanoid() //=> "fbaef"

      Type Parameters

      • Type extends string

      Parameters

      • alphabet: string

        Alphabet used to generate a random string.

      • size: number

        Size of the random string.

      • random: (bytes: number) => Uint8Array

        A random bytes generator.

      Returns () => Type

      A random string generator.

      Type The ID type to replace string with some opaque type.