
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Date-relative (and relatively universally unique) UUID generation.
$ npm install druuid
Druuid generates 64-bit, time-sortable IDs inspired by Snowflake and Instagram.
A druuid comprises:
A 41-bit timestamp (which has millisecond precision for over 69 years after a defined epoch); and
23 random bits.
For example, a druuid generated at midnight on February 4, 2012, may look something like 11142943683383068069. In binary:
Timestamp | Randomness |
---|---|
10011010101000111011000000111110000000000 | 01110110000010110100101 |
This ID can be displayed compactly in base 36: 2cnpvvfkm56ed.
64-bit IDs can be stored in BIGINT database columns, which are generally more efficient to index (and index uniquely) than VARCHAR.
The timestamp component allows for efficient date-based queries and easy cursor-based pagination.
23 bits of randomness contains much less entropy than traditional, 128-bit UUIDs, so precautions must be taken to avoid collisions between druuids generated in the same millisecond (e.g., a database constraint). The probability, within a millisecond, can be calculated with the Birthday problem (where n is the number of IDs generated per millisecond and 23 represents the number of random bits):
IDs generated in different milliseconds cannot collide, but at a rate of 10 IDs per millisecond (10,000 IDs per second), the probability a collision will occur within any given millisecond approaches 0.000596%, which is about once every few minutes if that rate is constant.
var druuid = require('druuid');
// druuid.epoch = Date.UTC(1970, 0); // change the default (Unix) epoch
var uuid = druuid.gen();
// => <BigInt 11142943683383068069>
druuid.time(uuid);
// => Sat Feb 04 2012 00:00:00 GMT-0800 (PST)
MIT
FAQs
Date-relative UUIDs
We found that druuid demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
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.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.