Skip to content
/ uuniq Public

Unique Snowflake IDs and Symbolic IDs that can be generated for thousands of years.

License

Notifications You must be signed in to change notification settings

keift/uuniq

Repository files navigation




Contents

About

Unique Snowflake IDs and Symbolic IDs that can be generated for thousands of years.

Features

  • The possibility of collision is impossible
  • Suitable for distributed systems
  • Suitable for sorting and database indexes
  • Snowflake IDs developed by Twitter (X) can be generated
  • Shorter IDs can be generated like YouTube's video IDs

Installation

NPM

npm install uuniq

PNPM

pnpm install uuniq

Yarn

yarn add uuniq

Bun

bun add uuniq

Deno

deno install npm:uuniq

Usage

Briefly as follows.

const Uuniq = require("uuniq");
const Snowflake = new Uuniq.Snowflake();
const Symbolic = new Uuniq.Symbolic();

Snowflake.generate(); // "102604921389056"
Snowflake.generate(); // "102604921389057"

Snowflake.resolve("102604921389056");
/*
  {
    created_at: "2025-03-14T11:35:07.409Z",
    place_id: 0,
    sequence: 0
  }
*/

Symbolic.generate(); // "T8Qu56ki"
Symbolic.generate(); // "T8Qu56kj"

Symbolic.resolve("T8Qu56ki");
/*
  {
    created_at: "2025-03-14T11:36:05.528Z",
    place_id: 0,
    sequence: 0
  }
*/

Documentation

Constructors

new Snowflake(options?)

Generate Snowflake IDs developed by Twitter (X) in 2010. This can generate IDs for approximately 4,463 years according to the specified epoch. Unique IDs can be generated in distributed systems by specifying Place IDs.

Parameter Default Description
options Object (optional)
Constructor's options.
options.epoch "2025-01-01T00:00:00.000Z" String | Number | Date (optional)
Date of epoch.
options.place_id 0 Number (optional)
Place ID for distributed systems.

returns Object

Example:

const Snowflake = new Uuniq.Snowflake({
  epoch: "2025-01-01T00:00:00.000Z",
  place_id: 0
});

new Symbolic(options?)

Generate unique IDs like YouTube's video IDs. This can generate IDs for approximately 4,463 years according to the specified epoch. Unique IDs can be generated in distributed systems by specifying Place IDs.

Parameter Default Description
options Object (optional)
Constructor's options.
options.epoch "2025-01-01T00:00:00.000Z" String | Number | Date (optional)
Date of epoch.
options.place_id 0 Number (optional)
Place ID for distributed systems.
options.charset "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" String (optional)
Character set of IDs.

returns Object

Example:

const Symbolic = new Uuniq.Symbolic({
  epoch: "2025-01-01T00:00:00.000Z",
  place_id: 0,
  charset: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
});

Methods

Snowflake.generate()

Generate Snowflake IDs developed by Twitter (X) in 2010. This can generate IDs for approximately 4,463 years according to the specified epoch.

Parameter Default Description

returns String

Example:

Snowflake.generate(); // "102604921389056"
Snowflake.generate(); // "102604921389057"

Snowflake.resolve(id)

Resolve the previously created ID. For this, the epoch and place_id values ​​in the Constructor must be correct.

Parameter Default Description
id String
ID to be resolved.

returns Object

Example:

Snowflake.resolve("102604921389056");
/*
  {
    created_at: "2025-03-14T11:35:07.409Z",
    place_id: 0,
    sequence: 0
  }
*/

Symbolic.generate()

Generate unique IDs like YouTube's video IDs. This can generate IDs for approximately 4,463 years according to the specified epoch.

Parameter Default Description

returns String

Example:

Symbolic.generate(); // "T8Qu56ki"
Symbolic.generate(); // "T8Qu56kj"

Symbolic.resolve(id)

Resolve the previously created ID. For this, the epoch and place_id values ​​in the Constructor must be correct.

Parameter Default Description
id String
ID to be resolved.

returns Object

Example:

Symbolic.resolve("T8Qu56ki");
/*
  {
    created_at: "2025-03-14T11:36:05.528Z",
    place_id: 0,
    sequence: 0
  }
*/

Links

License

MIT