Socket
Socket
Sign inDemoInstall

scru64

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    scru64

SCRU64: Sortable, Clock-based, Realm-specifically Unique identifier


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
60.1 kB
Created
Weekly downloads
 

Changelog

Source

v1.0.0 - 2023-09-28

  • Initial stable release

Readme

Source

SCRU64: Sortable, Clock-based, Realm-specifically Unique identifier

npm License

SCRU64 ID offers compact, time-ordered unique identifiers generated by distributed nodes. SCRU64 has the following features:

  • 63-bit non-negative integer storable as signed/unsigned 64-bit integer
  • Sortable by generation time (as integer and as text)
  • 12-digit case-insensitive textual representation (Base36)
  • ~38-bit Unix epoch-based timestamp that ensures useful life until year 4261
  • Variable-length node/machine ID and counter fields that share 24 bits
// pass node ID through global variable
globalThis.SCRU64_NODE_SPEC = "42/8";

import { scru64Sync, scru64StringSync } from "scru64";
// or on browsers:
// import { scru64Sync, scru64StringSync } from "https://unpkg.com/scru64@^1";

// generate a new identifier object
const x = scru64Sync();
console.log(String(x)); // e.g., "0u2r85hm2pt3"
console.log(x.toBigInt()); // as a 64-bit unsigned integer

// generate a textual representation directly
console.log(scru64StringSync()); // e.g., "0u2r85hm2pt4"

See SCRU64 Specification for details.

SCRU64's uniqueness is realm-specific, i.e., dependent on the centralized assignment of node ID to each generator. If you need decentralized, globally unique time-ordered identifiers, consider SCRU128.

Command-line interface

$ SCRU64_NODE_SPEC=42/8 npx scru64
0uc3xnefo50h
$ SCRU64_NODE_SPEC=42/8 npx scru64 -n 4
0uc3xnl3eas9
0uc3xnl3easa
0uc3xnl3easb
0uc3xnl3easc

License

Licensed under the Apache License, Version 2.0.

See also

FAQs

Last updated on 28 Sep 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc