Skip to content

StackyzDev/nanoid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nano ID (Roblox)

A tiny, URL-friendly, unique string ID generator for Roblox (Luau).

This package is a Roblox implementation of Nano ID, the original project by Andrey Sitnik: https://github.com/ai/nanoid

Why Nano ID

  • Short IDs: uses the URL-safe alphabet (A-Za-z0-9_-) style with a compact default size.
  • Simple API: one function to generate IDs.
  • Customizable: supports custom size and custom alphabet.

How It Works

Like the original Nano ID approach, this implementation generates IDs by:

  1. Choosing an alphabet (default: URL-friendly symbols).
  2. Picking random characters from that alphabet.
  3. Repeating until the target length is reached (default: 21).

Security

The original Nano ID emphasizes cryptographic randomness. In this Roblox version, randomness comes from Random.new(). If you need strict cryptographic guarantees, review your platform constraints and threat model before using generated IDs for security-sensitive use cases.

Defaults

  • Default ID size: 21
  • Default alphabet: URL-friendly Nano ID alphabet

Collision Notes

Collision probability depends on:

  • Alphabet length
  • ID size
  • Total number of generated IDs

Larger alphabets and longer IDs reduce collision risk.

Usage

Wally

[dependencies]
nanoid = "stackyzdev/nanoid@0.1.0"

Luau

local nanoid = require(path.to.nanoid)

local id = nanoid()
print(id) -- e.g. V1StGXR8_Z5jdHi6B-myT

local shortId = nanoid(10)
print(shortId)

local custom = nanoid(12, "1234567890abcdef")
print(custom)

API

generate(size: number?, alphabet: string?) -> string
  • size (optional): target length of the ID (default: 21)
  • alphabet (optional): characters used to build the ID

Credits

About

A tiny (118 bytes), secure, URL-friendly, unique string ID generator for JavaScript

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages