uuidv7 is a JavaScript library providing a robust implementation of Universally Unique Identifiers (UUID) version 7, as defined by RFC 9562. UUIDv7 introduces a time-ordered component, making the generated IDs monotonically increasing and thus highly suitable for database primary keys or indexed fields where sequential writes and improved locality are beneficial, unlike traditional UUIDv4. The current stable version is 1.2.1. It also includes support for UUIDv4 generation and offers an object representation for UUIDs, allowing programmatic inspection and comparison. The library is designed to handle clock rollbacks and counter overflows gracefully to maintain monotonicity, with a large 42-bit counter and mechanisms to increment the internal timestamp if the counter overflows within a millisecond.
npm install uuidv7Verified import paths — ran on the pinned version, not inferred.
Demonstrates generating UUIDv7 and UUIDv4 strings, and creating a UUIDv7 object for inspection and comparison.
Be aware of system clock stability in environments where strict monotonicity is paramount. Consider using NTP synchronization or monitoring clock drift if this is a critical concern.
This behavior is by design to ensure monotonic IDs. In most practical applications, the large counter (up to ~4.4 trillion IDs per millisecond) prevents this from being a frequent concern.
Ensure the runtime environment provides `crypto.getRandomValues` (browsers) or `crypto.randomFillSync` (Node.js) for optimal security and uniqueness of the random components.
Ensure you are using `import { uuidv7 } from 'uuidv7';` if your environment supports ESM. If strictly using CommonJS, try `const { uuidv7 } = require('uuidv7');` or check your build setup.Confirm you are using named imports as shown in the documentation: `import { uuidv7 } from 'uuidv7';`. If you are importing from an unpkg URL in the browser, ensure the version matches and it's the correct path.No dependency data recorded yet.