Home

Awesome

Universally Unique Lexicographically Sortable Identifier

A Clojure port of alizain/ulid

Clojars Project CircleCI

Background

A GUID/UUID can be suboptimal for many use-cases because:

A ULID however:

Usage

Generating a ULID String requires a ULID instance.


(require '[clj-ulid :as ulid])


; Generate ULID
(ulid/ulid)
; => "01bpf8bvjp4qas6vkg9maa13b5"

; Generate ULID from timestamp (useful for migrations)
(ulid/ulid 1501602817887)
; => "01bpf819tzbqdgxryyf664y7vs"

; Get embedded timestamp from ULID
(ulid/ulid->timestamp "01bpf819tzbqdgxryyf664y7vs")
; => 1501602817887

Specification

Below is the current specification of ULID as implemented in this repository.

Components

Timestamp

Entropy

Encoding

Crockford's Base32 is used as shown. This alphabet excludes the letters I, L, O, and U to avoid confusion and abuse.

0123456789ABCDEFGHJKMNPQRSTVWXYZ

String Representation

 01AN4Z07BY      79KA1307SR9X4MV3
|----------|    |----------------|
 Timestamp           Entropy
  10 chars           16 chars
   48bits             80bits
   base32             base32

Test

lein test

Prior Art