Navigate:
All Reposnanoid
~$NANOID0.0%

Nano ID: Secure URL-friendly unique string ID generator

Compact 21-character cryptographic IDs with URL-safe encoding.

LIVE RANKINGS • 06:51 AM • STEADY
OVERALL
#252
22
DEVELOPER TOOLS
#50
2
30 DAY RANKING TREND
ovr#252
·Devel#50
STARS
26.5K
FORKS
827
DOWNLOADS
63.5M
7D STARS
+3
7D FORKS
0
See Repo:
Share:

Learn more about nanoid

Nano ID is a JavaScript library that generates unique string identifiers using cryptographic random number generation. It uses the Web Crypto API in browsers and the crypto module in Node.js to ensure unpredictability, with a custom algorithm that maintains uniform distribution across its alphabet. The library produces 21-character IDs with 126 random bits, comparable to UUID v4's 122 bits but in a more compact format. It is commonly used for database record IDs, session tokens, and other applications requiring collision-resistant unique identifiers.

nanoid

1

Compact size

The library is 118 bytes when minified and brotli-compressed with no external dependencies. This is approximately 3 times smaller than the uuid/v4 package.

2

Larger alphabet encoding

Uses 64 characters (A-Za-z0-9_-) instead of UUID's hexadecimal format, reducing ID length from 36 to 21 characters while maintaining similar collision probability.

3

Uniform distribution algorithm

Implements a custom algorithm to ensure even distribution of characters across generated IDs, avoiding the bias that occurs with naive modulo-based approaches.


import { nanoid } from 'nanoid'
const id = nanoid() // => "V1StGXR8_Z5jdHi6B-myT"

v5.1.6

Fixes an infinite loop bug when customAlphabet is called with a size of 0.

  • Upgrade to avoid infinite loops if your code passes 0 as the size parameter to customAlphabet.
  • No breaking changes or new requirements are documented in this patch release.
v5.1.5

Patch release correcting npm's latest tag after an accidental 3.x publish; no functional changes to the library.

  • Update to 5.1.5 to ensure you receive the correct latest version from npm's default tag.
  • Release notes do not specify any code changes, breaking changes, or new features in this version.
v3.3.11

Patch release restoring React Native compatibility after a regression.

  • Upgrade if using React Native; previous version broke compatibility with the runtime.
  • Release notes do not specify the root cause or affected React Native versions.


[ EXPLORE MORE ]

Related Repositories

Discover similar tools and frameworks used by developers