View Source ShortUUID.Builder (ShortUUID v4.1.0)
ShortUUID.Builder is a module for encoding and decoding UUIDs (Universally Unique Identifiers) using various predefined or custom alphabets.
Usage
To create your module, simply use
it and optionally provide an alphabet option:
defmodule MyModule do
use ShortUUID.Builder, alphabet: :base58
end
The alphabet
option must be one of the predefined alphabets or a custom string (16+ unique characters).
Predefined Alphabets
The following predefined alphabets are available:
:base57_shortuuid
- "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz":base32
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567":base32_crockford
- "0123456789ABCDEFGHJKMNPQRSTVWXYZ":base32_hex
- "0123456789ABCDEFGHIJKLMNOPQRSTUV":base32_z
- "ybndrfg8ejkmcpqxot1uwisza345h769":base58
- "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz":base62
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz":base64
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/":base64_url
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
Functions
The following functions are available for encoding and decoding UUIDs:
encode/1
- Encodes a UUID using the specified or default alphabet.encode!/1
- Encodes a UUID using the specified or default alphabet, raising an error on failure.decode/1
- Decodes a string into a UUID using the specified or default alphabet.decode!/1
- Decodes a string into a UUID using the specified or default alphabet, raising 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"}