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" Copy
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"
Alphabet used to generate a random string.
Size of the random string.
A random bytes generator.
A random string generator.
Type The ID type to replace string with some opaque type.
string
Generate unique ID with custom random generator and alphabet.
Alphabet must contain 256 symbols or less. Otherwise, the generator will not be secure.