ShortUUID is a module for encoding and decoding UUIDs using a base57 alphabet.
Functions
encode/1- Encodes a UUID into a shorter string using base57 alphabetencode!/1- Same as encode/1 but raises an error on failuredecode/1- Decodes a shortened string back into a UUIDdecode!/1- Same as decode/1 but raises an error on failure
Example
iex> ShortUUID.encode("550e8400-e29b-41d4-a716-446655440000")
{:ok, "H9cNmGXLEc8NWcZzSThA9S"}
iex> ShortUUID.decode("H9cNmGXLEc8NWcZzSThA9S")
{:ok, "550e8400-e29b-41d4-a716-446655440000"}For custom alphabets and more options, see ShortUUID.Builder.
To implement your own compatible ShortUUID module, use ShortUUID.Behaviour.
Summary
Functions
Decodes a 22-character short ID back into a lowercase, hyphenated UUID string.
Decodes a short ID like decode/1, but returns the UUID directly and raises
an ArgumentError on invalid input.
Encodes a UUID string into a 22-character short ID.
Encodes a UUID string like encode/1, but returns the short ID directly and
raises an ArgumentError on invalid input.
Functions
Decodes a 22-character short ID back into a lowercase, hyphenated UUID string.
Short IDs are case-sensitive and must use exactly this module's alphabet
(57 characters: "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"). Returns {:ok, uuid} or {:error, "Invalid input"}.
Decodes a short ID like decode/1, but returns the UUID directly and raises
an ArgumentError on invalid input.
Encodes a UUID string into a 22-character short ID.
Accepts UUIDs with or without hyphens, in curly braces or with a urn:uuid:
prefix, in any letter case. The alphabet has 57 characters: "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".
Returns {:ok, short_id} or {:error, "Invalid UUID"}.
Encodes a UUID string like encode/1, but returns the short ID directly and
raises an ArgumentError on invalid input.