~statianzo/janet-nanoid

Nanoid in Janet

clone

read-only
https://git.sr.ht/~statianzo/janet-nanoid
read/write
git@git.sr.ht:~statianzo/janet-nanoid

You can also use your local clone with git send-email.

#janet-nanoid

builds.sr.ht status License: Unlicense

A library for generating random IDs.

Ported implementation of nanoid in Janet.

#Install

jpm install https://git.sr.ht/~statianzo/janet-nanoid

#Usage

nanoid comes with two variants gen and gen-non-secure.

gen relies on Janet's os/cryptorand to obtain cryptographically secure random bytes.

gen-non-secure uses the math/rng pseudorandom generator.

#Options

  • :size - Length of the output string (default 21)
  • :alphabet - Alphabet of characters to use (defaults alphanumeric and -_)
  • :rng - math/rng instance to generate (gen-non-secure only)

#Example

(import nanoid)

(nanoid/gen)
# "xo25OEhGZ7yoHYbfPpmZE"

(nanoid/gen :size 5)
# "U5bBu"

(nanoid/gen :alphabet "abcd1234")
# "24234a13a4ddddc3dbb4a"

(nanoid/gen-non-secure :size 5)
# "vWgzu"

goatcounter