Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jclem/base62_uuid
A library for generating 22-byte-length, Base62-encoded v4 UUIDs
https://github.com/jclem/base62_uuid
Last synced: about 1 month ago
JSON representation
A library for generating 22-byte-length, Base62-encoded v4 UUIDs
- Host: GitHub
- URL: https://github.com/jclem/base62_uuid
- Owner: jclem
- License: mit
- Created: 2016-09-20T16:38:01.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-02-16T16:57:41.000Z (over 2 years ago)
- Last Synced: 2024-04-24T00:40:02.950Z (7 months ago)
- Language: Elixir
- Homepage: https://hex.pm/packages/base62_uuid
- Size: 44.9 KB
- Stars: 10
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Base62UUID [![Coverage Status](https://coveralls.io/repos/github/jclem/base62_uuid/badge.svg?branch=master)](https://coveralls.io/github/jclem/base62_uuid?branch=master)
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](https://hex.pm/docs/publish), the package can be installed
as:1. Add `base62_uuid` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:base62_uuid, "~> 2.0.0"}]
end
```2. Ensure `base62_uuid` is started before your application:
```elixir
def application do
[applications: [:base62_uuid]]
end
```## Usage
### Generate a Base62-encoded UUID
```elixir
iex> Base62UUID.generate()
"5rljkyCY7vXDv2bPAnCQdL"
```### Encode a UUID to Base62
```elixir
iex> Base62UUID.encode("7af42354-0835-475f-adb5-15fc893526e1")
{:ok, "3k0dNymf72EzlHEkZLwjhZ"}
```### Decode a Base62-encoded UUID
```elixir
iex> Base62UUID.decode("3k0dNymf72EzlHEkZLwjhZ")
{:ok, "7af42354-0835-475f-adb5-15fc893526e1"}
```