Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nuid

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuid

NUID - A highly performant unique identifier generator.

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
39K
decreased by-15.18%
Maintainers
1
Weekly downloads
 
Created
Source

NODE NUID

license npm npm npm

A highly performant unique identifier generator.

Installation

Import the library for node/bun:

npm install nuid

For web and deno you can also:

npx jsr add @nats-io/nuid

Basic Usage

Reference the library in your code. If using you can import or require the npm nuid library supports both Common JS and ESM:

const { nuid, Nuid } = require("nuid");
// or
import { next, Nuid } from "nuid";

// `nuid` is a global instance of nuid, you can use it directly
// `Nuid` is the actual class implementing the nuids, so you can also
// `new Nuid()`.
// To generate a bunch of nuids:
let id = nuid.next();
id = nuid.next();
//

// To generate a new prefix:
nuid.reset();
// note that prefixes are automatically rolled whenever all
// the nuids for the specific prefix have been used.
id = nuid.next();

Performance

NUID needs to be very fast to generate and be truly unique, all while being entropy pool friendly. NUID uses 12 bytes of crypto generated data (entropy draining), and 10 bytes of pseudo-random sequential data that increments with a pseudo-random increment.

Total length of a NUID string is 22 bytes of base 36 ascii text, so 36^22 or 17324272922341479351919144385642496 possibilities.

Migration

The 2.x version of the npm module support both CJS and ESM modules, an ESM only version of the module is available via jsr @nats-io/nuid

If you are migrating from the 1.x.x series, note that getGlobalNuid(), next() and reset() and version property have been removed. Instead, access the exported constant nuid and call next() or reset() on it as shown in the examples above. For version information please refer to your installed module's version information.

If you are migrating from the js-nuid module in npm, there should be no changes except to the location of the import in the npm bundle:

import { nuid } from "./node_modules/esm/index.js";

Supported Node Versions

Support policy for Nodejs versions follows Nodejs release support. We will support and build nuid on even Nodejs versions that are current or in maintenance.

License

Unless otherwise noted, the NATS source files are distributed under the Apache Version 2.0 license found in the LICENSE file.

Keywords

FAQs

Package last updated on 23 May 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc