Description
ShortUUID is a simple Elixir library that allows you to create concise, unambiguous, URL-safe UUIDs.
Often, one needs to use non-sequential IDs in places where users will see them, but the IDs must be as concise and easy to use as possible. ShortUUID solves this problem by translating regular UUIDs to base57 using lowercase and uppercase letters and digits, and removing similar-looking characters such as l, 1, I, O and 0.
ShortUUID supports all most common UUID formats
ShortUUID alternatives and similar packages
Based on the "Utilities" category.
Alternatively, view ShortUUID alternatives based on common mentions on social networks and blogs.
-
erlware_commons
Erlware Commons is an Erlware project focused on all aspects of reusable Erlang components. -
retry
Simple Elixir macros for linear retry, exponential backoff and wait with composable delays -
async_with
The asynchronous version of Elixir's "with", resolving the dependency graph and executing the clauses in the most performant way possible! -
plasm
Ecto's composable query multitool (.count, .random, .earliest, .latest, .find, .at, .on, etc.) -
sips_downloader
Utility to download Elixir Sips screencast videos written in Elixir (subscription to Elixir Sips required) -
ar2ecto
Migrate your active record migrations to ecto compatible migrations -
dot-notes
Simple dot/bracket notation parsing/conversion for Maps/Lists -
exjprop
Elixir library for reading Java properties files from various sources. -
ExNric
Validation for National Registration Identity Card numbers (NRIC) -
ex_progress
A library for tracking progress across many tasks and sub-tasks -
fitex
FitEx is a Macro-Module which provides a bit of sugar for function definitions.
Learn Elixir in as little as 12 Weeks
Do you think we are missing an alternative of ShortUUID or a related project?
README
ShortUUID
ShortUUID is a simple Elixir library that generates concise, unambiguous, URL-safe UUIDs.
Often, one needs to use non-sequential IDs in places where users will see them, but the IDs must be as concise and easy to use as possible. ShortUUID solves this problem by translating regular UUIDs to base57 using lowercase and uppercase letters and digits, and removing similar-looking characters such as l, 1, I, O and 0.
Inspired by shortuuid.
Note: As long as the they use the same alphabet (23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz) different shortuuid implementations should be compatible, however there is no official standard afaik so I would strongly advise to do your own research and compatibility testing if you're doing any sort of interoperability between different libraries.
Unlike other shortuuid libraries this one does not generate UUIDs as this would break with the single task principle and also add potential unneeded dependencies. You can feed any valid UUID into ShortUUID.encode/1
. Some of the libraries you can use to generate UUIDs are
Elixir UUID, Erlang UUID and also Ecto as it can generate version 4 UUIDs.
ShortUUID supports the most common formats of UUIDs:
"2A162EE5-02F4-4701-9E87-72762CBCE5E2"
"2a162ee5-02f4-4701-9e87-72762cbce5e2"
"2a162ee502f447019e8772762cbce5e2"
"{2a162ee5-02f4-4701-9e87-72762cbce5e2}"
"{2a162ee502f447019e8772762cbce5e2}"
Installation
Add ShortUUID to your list of dependencies in mix.exs
:
def deps do
[
{:shortuuid, "~> 2.0"}
]
end
Examples
iex> "f98e80e7-9923-4173-8408-98f8254912ad" |> ShortUUID.encode
{:ok, "EwQd7sRtDbyyB6QRSWAtQn"}
iex> "f98e80e7-9923-4173-8408-98f8254912ad" |> ShortUUID.encode!
"EwQd7sRtDbyyB6QRSWAtQn"
iex> "EwQd7sRtDbyyB6QRSWAtQn" |> ShortUUID.decode
{:ok, "f98e80e7-9923-4173-8408-98f8254912ad"}
iex> "EwQd7sRtDbyyB6QRSWAtQn" |> ShortUUID.decode!
"f98e80e7-9923-4173-8408-98f8254912ad"
Using ShortUUID with Ecto
If you would like to use ShortUUID with Ecto schemas try Ecto.ShortUUID.
It provides a custom Ecto type which allows for ShortUUID primary and foreign keys while staying compatible with :binary_key
(EctoUUID
).
Documentation
Look up the full documentation at https://hexdocs.pm/shortuuid.