anano

Search:
  Source   Edit

NanoID is unique ID generator that are URL friendly and have a small chance of collision.

The alphabet used and size of the ID can be controlled with -d:nanoIDSize=<yourSize> and -d:nanoAlphabet=<yourAlphabet> respectively

Example:

import anano
let id = genNanoID()
echo id # Will be some string like opPOmFDJz4m1k01OTUks_

Types

NanoID = array[nanoIDSize, char]
  Source   Edit

Consts

nanoAlphabet = "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Alphabet used for the IDs   Source   Edit
nanoIDSize = 21
The size to use for nano IDs   Source   Edit

Procs

func `$`(id: NanoID): string {....raises: [], tags: [].}
Converts ID into a string   Source   Edit
proc genNanoID(): NanoID {....raises: [OSError], tags: [].}
Generates a random ID. Uses std/sysrand for RNG   Source   Edit
proc parseNanoID(id: openArray[char]): NanoID {....raises: [], tags: [].}
Parses a nanoID from a string like parameter

Example:

let id = genNanoID()
# ID has been sent to client, then client is sending it
# back but in string form
let strID = $id
assert parseNanoID(strID) == id

Example: cmd: -d:nanoIDSize=4

assert parseNanoID(['a', 'b', 'c', 'd']) == parseNanoID("abcd")
  Source   Edit