Thanks to visit codestin.com
Credit goes to hexdocs.pm

glanoid

Package Version Hex Docs

Gleam port of nanoid.

Installation

gleam add glanoid

Usage

Default alphabet

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"
}

Custom alphabet

import glanoid
import gleam/io

pub fn main() {
  let assert Ok(nanoid) = glanoid.make_generator("lucy")
  nanoid(18)
  |> io.debug() // "lluucyuyulycyucucy"
}

Collision probability

You can use the ID collision probability calculator to check the safety of your ID size and alphabet.

Codestin Search App Codestin Search App