Liking cljdoc? Tell your friends :D

identika.uuid7

UUID v7 generation, parsing, and validation.

Implements RFC 9562 UUID v7 (time-ordered):

  • 36-char hex-hyphenated string (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
  • 48 bits of big-endian Unix timestamp in milliseconds (bytes 0-5)
  • 12 bits of randomness (rand_a, bytes 6-7) with version 7 (0111) in byte 6
  • 62 bits of randomness (rand_b, bytes 8-15) with variant 10 in byte 8
  • Lexicographically sortable by creation time
  • Pure Clojure, zero dependencies beyond java.security.SecureRandom
UUID v7 generation, parsing, and validation.

Implements RFC 9562 UUID v7 (time-ordered):
- 36-char hex-hyphenated string (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
- 48 bits of big-endian Unix timestamp in milliseconds (bytes 0-5)
- 12 bits of randomness (rand_a, bytes 6-7) with version 7 (0111) in byte 6
- 62 bits of randomness (rand_b, bytes 8-15) with variant 10 in byte 8
- Lexicographically sortable by creation time
- Pure Clojure, zero dependencies beyond java.security.SecureRandom
raw docstring

decodeclj

(decode s)

Decode a UUID v7 string into a 16-byte byte array. Returns nil if s is not a valid UUID v7.

(decode "019ebd32-2280-7168-b09b-2240203908ea") ;; => #object["[B" 0x...]

Decode a UUID v7 string into a 16-byte byte array.
Returns nil if s is not a valid UUID v7.

  (decode "019ebd32-2280-7168-b09b-2240203908ea")
  ;; => #object["[B" 0x...]
sourceraw docstring

encodeclj

(encode byte-arr)

Encode a 16-byte byte array into a UUID v7 string. Throws IllegalArgumentException when the array is not exactly 16 bytes.

(encode (byte-array 16 (range 16))) ;; => "00010203-0405-0607-0809-0a0b0c0d0e0f"

Encode a 16-byte byte array into a UUID v7 string.
Throws IllegalArgumentException when the array is not exactly 16 bytes.

  (encode (byte-array 16 (range 16)))
  ;; => "00010203-0405-0607-0809-0a0b0c0d0e0f"
sourceraw docstring

genclj

(gen)
(gen millis)

Generate a new UUID v7 string.

With no arguments, stamps the current system time. Pass an explicit millisecond Unix epoch to generate a UUID for a known instant.

Returns a 36-character hex-hyphenated RFC 9562 UUID string.

(gen) ;; => "019ebd32-2666-7168-b09b-2240203908ea"

(gen 1781290640000) ;; => "019ebd32-2280-7168-b09b-2240203908ea"

Generate a new UUID v7 string.

With no arguments, stamps the current system time. Pass an explicit
millisecond Unix epoch to generate a UUID for a known instant.

Returns a 36-character hex-hyphenated RFC 9562 UUID string.

  (gen)
  ;; => "019ebd32-2666-7168-b09b-2240203908ea"

  (gen 1781290640000)
  ;; => "019ebd32-2280-7168-b09b-2240203908ea"
sourceraw docstring

monotonicclj

(monotonic generator-atom)

Generate monotonically increasing UUID v7s using an explicit state atom.

Usage: (def gen (atom nil)) (identika.uuid7/monotonic gen)

The atom holds the last generated UUID v7 string. When several calls land in the same millisecond the random payload (rand_a ‖ rand_b) is incremented instead of re-rolled, mirroring the random bit-increment counter method in RFC 9562 §6.2.1. If that payload is exhausted the timestamp advances by one millisecond. When the wall clock moves backwards, generation continues from the last timestamp so the sequence never regresses.

Each call resets generator-atom to the value it returns.

Generate monotonically increasing UUID v7s using an explicit state atom.

Usage:
  (def gen (atom nil))
  (identika.uuid7/monotonic gen)

The atom holds the last generated UUID v7 string. When several calls land in
the same millisecond the random payload (rand_a ‖ rand_b) is incremented
instead of re-rolled, mirroring the random bit-increment counter method in
RFC 9562 §6.2.1. If that payload is exhausted the timestamp advances by one
millisecond. When the wall clock moves backwards, generation continues from
the last timestamp so the sequence never regresses.

Each call resets `generator-atom` to the value it returns.
sourceraw docstring

timestampclj

(timestamp s)

Extract the millisecond Unix timestamp embedded in a UUID v7 string.

Returns nil when s is not a valid UUID v7.

(timestamp "019ebd32-2280-7168-b09b-2240203908ea") ;; => 1781290640000

Extract the millisecond Unix timestamp embedded in a UUID v7 string.

Returns nil when `s` is not a valid UUID v7.

  (timestamp "019ebd32-2280-7168-b09b-2240203908ea")
  ;; => 1781290640000
sourceraw docstring

valid?clj

(valid? s)

Return true if s is a valid UUID v7 string (36-char hex-hyphenated, version 7, variant 10xx).

(valid? "019ebd32-2280-7168-b09b-2240203908ea") ;; => true

(valid? "550e8400-e29b-41d4-a716-446655440000") ;; => false

Return true if s is a valid UUID v7 string (36-char hex-hyphenated,
version 7, variant 10xx).

  (valid? "019ebd32-2280-7168-b09b-2240203908ea")
  ;; => true

  (valid? "550e8400-e29b-41d4-a716-446655440000")
  ;; => false
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close