Socket
Socket
Sign inDemoInstall

nanoid

Package Overview
Dependencies
0
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

nanoid

A tiny (116 bytes), secure URL-friendly unique string ID generator


Version published
Maintainers
1
Weekly downloads
35,386,922
decreased by-6.54%

Weekly downloads

Package description

What is nanoid?

The nanoid npm package is a small, secure, URL-friendly, unique string ID generator for JavaScript applications. It is designed to be fast and efficient, producing random or custom ID strings suitable for a variety of applications, including database keys, session identifiers, and more.

What are nanoid's main functionalities?

Simple ID Generation

Generate a unique, URL-friendly ID. The default ID length is 21 characters, which provides a good balance of speed and uniqueness.

const { nanoid } = require('nanoid');
console.log(nanoid()); // Example output: 'V1StGXR8_Z5jdHi6B-myT'

Custom Length ID Generation

Generate a unique ID with a custom length. This allows for shorter or longer IDs depending on the level of uniqueness required.

const { nanoid } = require('nanoid');
console.log(nanoid(10)); // Example output: 'IRFa-VaY2b'

Non-secure ID Generation

Generate a non-secure ID with a custom alphabet and length. This is useful for cases where unique IDs are needed without the cryptographic strength.

const { customAlphabet } = require('nanoid');
const nanoid = customAlphabet('1234567890abcdef', 10);
console.log(nanoid()); // Example output: '4f90d13a42'

Custom Alphabet ID Generation

Generate a unique ID using a custom alphabet. This is useful when you need to avoid certain characters or use a specific set of characters for IDs.

const { customAlphabet } = require('nanoid');
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const nanoid = customAlphabet(alphabet, 10);
console.log(nanoid()); // Example output: '4f90d13a42'

Other packages similar to nanoid

Readme

Source

Nano ID

Nano ID logo by Anton Lovchikov

English | Русский | 简体中文 | Bahasa Indonesia

A tiny, secure, URL-friendly, unique string ID generator for JavaScript.

“An amazing level of senseless perfectionism, which is simply impossible not to respect.”

  • Small. 116 bytes (minified and brotlied). No dependencies. Size Limit controls the size.
  • Safe. It uses hardware random generator. Can be used in clusters.
  • Short IDs. It uses a larger alphabet than UUID (A-Za-z0-9_-). So ID size was reduced from 36 to 21 symbols.
  • Portable. Nano ID was ported to over 20 programming languages.
import { nanoid } from 'nanoid'
model.id = nanoid() //=> "V1StGXR8_Z5jdHi6B-myT"

  Made in Evil Martians, product consulting for developer tools.


Docs

Read full docs here.

Keywords

FAQs

Last updated on 20 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc