Gleam port of nanoid.
gleam add glanoid
Use the following to generate IDs with the default alphabet (A-Za-z0-9_-
).
Generate the nanoid function with glanoid.make_generator(glanoid.default_alphabet)
.
Then call the function with the desired ID length as an argument.
import glanoid
import gleam/io
pub fn main() {
let assert Ok(nanoid) = glanoid.make_generator(glanoid.default_alphabet)
nanoid(18)
|> io.debug() // "bppqBa-4eNFW_yPzib"
}
import glanoid
import gleam/io
pub fn main() {
let assert Ok(nanoid) = glanoid.make_generator("lucy")
nanoid(18)
|> io.debug() // "lluucyuyulycyucucy"
}
You can use the ID collision probability calculator to check the safety of your ID size and alphabet.