npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nats-io/nuid

v2.0.1-2

Published

NUID - A highly performant unique identifier generator.

Downloads

19,201

Readme

Nuid.js

license npm npm npm

A highly performant unique identifier generator for JavaScript.

Installation

For web and deno you can use the JSR bundle:

npx jsr add @nats-io/nuid
// or
deno add @nats-io/nuid
import { next, Nuid } from "jsr:@nats-io/nuid";

import { next

In node/bun:

npm install nuid
const { next, 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()`.

Basic Usage

// 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.