View Source Ulidex (ulidex v0.2.0)
This is an implementation of the ULID (Universally Unique Lexicographically Sortable Identifier) spec.
Link to this section Summary
Functions
Takes a Crockford 32 encoded ULID and returns a a 128 bit binary ULID.
Takes a 128 bit binary ULID and returns a Crockford 32 encoded ULID.
Generates a Crockford 32 encoded ULID for the given timestamp which must be in milliseconds.
Link to this section Types
@type t() :: String.t()
A Crockford 32 encoded ULID.
Link to this section Functions
@spec decode(t()) :: Ulidex.Binary.t()
Takes a Crockford 32 encoded ULID and returns a a 128 bit binary ULID.
Raises Ulidex.Error.InvalidUlidString
when the input is malformed.
examples
Examples
iex> ulid = "01G3C1TW8AKE19BYDDR6996C1D"
iex> Ulidex.decode(ulid)
<<1, 128, 216, 29, 113, 10, 155, 130, 149, 249, 173, 193, 146, 147, 48, 45>>
@spec encode(Ulidex.Binary.t()) :: t()
Takes a 128 bit binary ULID and returns a Crockford 32 encoded ULID.
Raises Ulidex.Error.InvalidBinary
when the input is malformed.
examples
Examples
iex> ulid = <<1, 128, 211, 67, 45, 254, 115, 142, 105, 252, 121, 217, 228, 222, 219, 155>>
iex> Ulidex.encode(ulid)
"01G39M6BFYEE76KZ3SV7JDXPWV"
Generates a Crockford 32 encoded ULID for the given timestamp which must be in milliseconds.
If no timestamp is given it uses the current system time.
examples
Examples
iex> ulid = Ulidex.generate()
iex> <<_::size(208)>> = ulid