Skip to content

0xca551e/glanoid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

gleam port of nanoid

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages