Skip to content

A library for generating 22-byte-length, Base62-encoded v4 UUIDs

License

Notifications You must be signed in to change notification settings

aboard-io/base62_uuid

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Base62UUID Coverage Status

A library for generating 22-byte-length, Base62-encoded v4 UUIDs.

UUIDs are great for use as primary keys in relational databases, but they don't look great in URLs. This library makes it easy to generate, encode, and decode Base62 v4 UUIDs that have a guaranteed length of 22 bytes. That way, rather than URLs that look like:

https://example.com/widgets/7af42354-0835-475f-adb5-15fc893526e1

You can have a shorter and friendlier looking URL like:

https://example.com/widgets/3k0dNymf72EzlHEkZLwjhZ

Installation

If available in Hex, the package can be installed as:

  1. Add base62_uuid to your list of dependencies in mix.exs:

    def deps do
      [{:base62_uuid, "~> 2.0.0"}]
    end
  2. Ensure base62_uuid is started before your application:

    def application do
      [applications: [:base62_uuid]]
    end

Usage

Generate a Base62-encoded UUID

iex> Base62UUID.generate()
"5rljkyCY7vXDv2bPAnCQdL"

Encode a UUID to Base62

iex> Base62UUID.encode("7af42354-0835-475f-adb5-15fc893526e1")
{:ok, "3k0dNymf72EzlHEkZLwjhZ"}

Decode a Base62-encoded UUID

iex> Base62UUID.decode("3k0dNymf72EzlHEkZLwjhZ")
{:ok, "7af42354-0835-475f-adb5-15fc893526e1"}

About

A library for generating 22-byte-length, Base62-encoded v4 UUIDs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir 95.5%
  • HCL 4.5%