View Source Ulid (ulidex v0.1.0)

This is an implementation of the ULID (Universally Unique Lexicographically Sortable Identifier) spec.

Link to this section Summary

Types

t()

A Crockford 32 encoded ULID.

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()) :: Ulid.Binary.t()

Takes a Crockford 32 encoded ULID and returns a a 128 bit binary ULID.

Raises Ulid.Error.InvalidUlidString when the input is malformed.

examples

Examples

iex> ulid = "01G3C1TW8AKE19BYDDR6996C1D"
iex> Ulid.decode(ulid)
<<1, 128, 216, 29, 113, 10, 155, 130, 149, 249, 173, 193, 146, 147, 48, 45>>
@spec encode(Ulid.Binary.t()) :: t()

Takes a 128 bit binary ULID and returns a Crockford 32 encoded ULID.

Raises Ulid.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> Ulid.encode(ulid)
"01G39M6BFYEE76KZ3SV7JDXPWV"
Link to this function

generate(timestamp \\ System.system_time(:millisecond))

View Source
@spec generate(integer()) :: binary()

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 = Ulid.generate()
iex> <<_::size(208)>> = ulid