Détail du package

@kripod/uuidv7

kripod15.9kMIT0.3.4

UUIDv7 generator with millisecond precision

id-generator, k-sortable, collision-resistance

readme

UUIDv7

UUIDv7 generator based on the RFC4122 update proposal (draft-04)

npm (scoped) npm bundle size (scoped) GitHub Workflow Status (branch) Contributor Covenant

Usage

import { uuidv7 } from "@kripod/uuidv7";

let id = uuidv7();
console.log(id); // Example: 00ccebbc-13e0-7000-8b18-6150ad2d0c05

Key features

  • K-sortable with 1ms precision (Safari disallows sub-ms timing to defend against Spectre)
  • Time-ordered when sorted lexicographically
  • Collision-resistant with distributed systems in mind
  • Works until the year 10889, after which timestamps would overflow

Compatibility

Chrome Safari Firefox IE Node.js Deno
≥57 ≥10 ≥48 No (polyfillable) ≥8 ≥1

Supporting additional runtimes

Binary structure

  • unix_ts_ms: Milliseconds elapsed since the Unix epoch – 48 bits
  • ver: UUID version (7) – 4 bits
  • rand_a: Monotonic sequence counter for more precise sorting – 12 bits
  • var: UUID variant (0b10) – 2 bits
  • rand_b: Cryptographically strong random data – 62 bits
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ┌─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┐ │ unix_ts_ms │ ├─┴─┴─┴─┼─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┼─┴─┴─┴─┼─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤ │ unix_ts_ms │ ver │ rand_a │ ├─┴─┼─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤ │var│ rand_b │ ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤ │ rand_b │ └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

0.3.4 - 2022-07-03

Added

  • cjs exports for browsers

0.3.3 - 2022-07-03

Fixed

  • type exports (#3)

0.3.2 - 2022-06-25

Changed

  • readme: link to the latest spec (draft-04)

0.3.1 - 2022-04-04

Changed

  • readme: update binary structure

0.3.0 - 2022-04-04

Changed

  • adhere to the latest version of the spec (draft-03)

0.2.3 - 2021-10-16

Changed

  • readme: link to the latest spec (draft-02)

0.2.2 - 2021-09-28

Fixed

  • ignore negative system clock adjustments

0.2.1 - 2021-09-27

Fixed

  • crypto object method binding

0.2.0 - 2021-09-27

Fixed

  • build: babel transforms for compatibility

0.1.4 - 2021-09-27

Fixed

  • readme: ci badge image

0.1.3 - 2021-09-27

Fixed

  • changelog: version comparison links

0.1.2 - 2021-09-27

Changed

  • meta: package keywords

0.1.1 - 2021-09-27

Fixed

  • readme: ci badge link

0.1.0 - 2021-09-27

Added

  • initial release