dsrw / nanoid.nim

:id: the Nim implementation of NanoID

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nanoid.nim

the Nim implementation of NanoID

Build Status

What even?

NanoID is a tiny, secure URL-friendly unique string ID generator.
It's safe. It uses cryptographically strong random APIs that guarantees proper distribution of symbols.
And it's compact. It uses a larger alphabet than the standard UUID (A-Za-z0-9_-), and has a similar number of unique IDs in just 21 symbols instead of 36.

Installation

nimble install nanoid

Optionally, run the test suite (after cloning this repo) using

nimble test

Usage

Simple

Uses the default alphabet set (A-Za-z0-9_-) and a size of 21 symbols.

import nanoid

echo generate()  # RKF2A0-pGhJfpm6-rSi5C

Non-secure

import nanoid

echo generateNonSecure()  # SL8Zh8Lfw9TIRbaQI-DxB

Custom alphabet/size

import nanoid

let
  a = "abcdef12345"
  s = 10

echo generate(alphabet=a, size=10)  # 15aa1d2b3a

That’s it, really.

TODO

  • Async API

Contributing

Bad code? New feature in mind? Open an issue. Better still, learn Nim and shoot a PR ✨

License

MIT © Anirudh Oppiliappan

About

:id: the Nim implementation of NanoID

License:MIT License


Languages

Language:Nim 100.0%