Skip to main content

Built and signed on GitHub Actions

A highly performant unique identifier generator.

This package works with Bun, Node.js, Deno, BrowsersIt is unknown whether this package works with Cloudflare Workers
JSR Score
100%
Published
4 weeks ago (2.0.0)
class Nuid

Nuid is a class that generates unique identifiers.

Constructors

new
Nuid()

Properties

Methods

private
fillSeq(): void

Fills the sequence part of the nuid as base36 from this.seq.

private
init(): void

Initializes a nuid with a crypto random prefix, and pseudo-random sequence and increment. This function is only called if any api on a nuid is called.

private
initSeqAndInc(): void

Initializes the pseudo random sequence number and the increment range.

Returns the next nuid.

reset(): void

Resets the prefix and counter for the nuid. This is typically called automatically from within next() if the current sequence exceeds the resolution of the nuid.

private
setPre(): void

Sets the prefix from crypto random bytes. Converts them to base36.

Add Package

deno add @nats-io/nuid

Import symbol

import { Nuid } from "@nats-io/nuid";

Add Package

npx jsr add @nats-io/nuid

Import symbol

import { Nuid } from "@nats-io/nuid";

Add Package

yarn dlx jsr add @nats-io/nuid

Import symbol

import { Nuid } from "@nats-io/nuid";

Add Package

pnpm dlx jsr add @nats-io/nuid

Import symbol

import { Nuid } from "@nats-io/nuid";

Add Package

bunx jsr add @nats-io/nuid

Import symbol

import { Nuid } from "@nats-io/nuid";