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 🙏

© 2026 – Pkg Stats / Ryan Hefner

next-id

v2.2.0

Published

Short unique ID generator

Downloads

95

Readme

next-id

This package generates unique, short and random-looking IDs based on timestamp, shardId and some sequence.

Installation

npm install next-id
# or
yarn add next-id

Algorithm

NextId in the nutshell is a 64 bit positive number. We take first 41 bit for timestamp, which is the difference between the current time and EPOCH. Then we take next 13 bits for shardId, so that we can later identify what shard the ID belongs to. And finally, the rest 10 bits we reserve for some sequential number from 0 to 1023.

With all of that it gives us an ability to generate up to 1024 IDs x shard x millisecond and they all guaranteed to be unique.

In order to make it looking as random Pseudo encrypt algorithm is being used.

ID Formats

NextId supports multiple representation formats:

  • id (default): Base62-encoded string (characters 0-9, A-Z, a-z), most compact form
  • alphanumericId: Base36-encoded string (characters 0-9, A-Z), useful when case matters
  • numericId: string representation of 64-bit number (only digits 0-9)
  • pseudoId: string representation of pseudo-encrypted number

Usage Examples

CommonJS

const nextId = require('next-id');
nextId(); //=> '4DTZX5Q7czS'

Alternative Import Methods

If you use ES modules:

// Using require with destructuring
const { generate, setShardId, inspect } = require('next-id');

// Using dynamic import
const nextId = await import('next-id').then(m => m.default);

You can also use a more explicit approach:

nextId.generate();

Both examples will generate an id with the default shard id (that equal to process.env.NEXT_ID_SHARD_ID or 0 if not set). If you want to change shard id, you have to specify it by calling setShardId method in advance, like so:

nextId.setShardId(345);
nextId.generate();
nextId();

You also can have it generated in numeric ([0-9]) or alphanumeric ([0-9A-Z]) formats:

nextId({ format: 'numeric' }); //=> '734552048796001285'
nextId({ format: 'alphanumeric' }); //=> '5KWP1K35NMRQ'

Keep in mind that numeric format represented as a string because JavaScript's MAX_SAFE_INTEGER is a 53 bit number and we need 64 bit for our IDs.

Options Structure

The ID generation function accepts an options object:

nextId({
  format: 'alphanumeric' // or 'numeric', default is standard Base62 format
});

Inspecting IDs

You can inspect any previously generated ID to get all information about it:

nextId.setShardId(7534);
nextId.inspect(nextId());
// result:
{
  id: '5tFJamllKR3',
  alphanumericId: '5KWR97F01ZWP',
  pseudoId: '4598183344642370425',
  numericId: '734558498015524873',
  shardId: 7534,
  issuedAt: 2020-06-17T19:26:36.681Z
}

You can inspect an ID in numeric or alphanumeric format as well:

nextId.inspect('734558498015524873');
nextId.inspect('5KWR97F01ZWP');
// the result will be the same as in the previous example

Return Data Structure

The inspect() method returns an object with the following fields:

  • id: ID in standard Base62 format
  • alphanumericId: ID in Base36 format (only digits and uppercase letters)
  • pseudoId: string representation of ID after pseudo-encryption
  • numericId: string representation of ID as a number
  • shardId: numeric value of the shard ID
  • issuedAt: Date object representing the time when ID was created

Limitations and Features

  • Timestamp is calculated from January 1, 2025 (EPOCH)
  • Maximum shardId value: 8191 (2^13 - 1)
  • Maximum number of IDs per millisecond per shard: 1024 (2^10)
  • The library uses BigInt to work with 64-bit numbers