[![Build Status](](
[![Coverage Status](](

# 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:
The input string is also downcased before processing so the letter case doesn't matter.

## Installation

Add ShortUUID to your list of dependencies in `mix.exs`:

  def deps do
      {:shortuuid, "~> 2.0"}

## Examples

iex> "f98e80e7-9923-4173-8408-98f8254912ad" |> ShortUUID.encode
{:ok, "EwQd7sRtDbyyB6QRSWAtQn"}

iex> "f98e80e7-9923-4173-8408-98f8254912ad" |> ShortUUID.encode!

iex> "EwQd7sRtDbyyB6QRSWAtQn" |> ShortUUID.decode
{:ok, "f98e80e7-9923-4173-8408-98f8254912ad"}

iex> "EwQd7sRtDbyyB6QRSWAtQn" |> ShortUUID.decode!

## 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 [](