You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+92-12Lines changed: 92 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,22 +10,39 @@
10
10
11
11
<!-- MDOC !-->
12
12
13
-
ShortUUID is a lightweight Elixir library that generates short and unique IDs for use in URLs. It provides a solution when you need IDs that are easy to use and understand for users.
13
+
ShortUUID is a lightweight Elixir library for generating short, unique IDs in URLs. It turns standard UUIDs into smaller strings ideal for use in URLs.
14
+
You can choose from a set of predefined alphabets or define your own.
15
+
The default alphabet includes lowercase letters, uppercase letters, and digits, omitting characters like 'l', '1', 'I', 'O', and '0' to keep them readable.
14
16
15
-
Instead of using long and complex UUIDs, ShortUUID converts them into shorter strings using a combination of lowercase and uppercase letters, as well as digits. It avoids using similar-looking characters such as 'l', '1', 'I', 'O', and '0'.
17
+
**Note:** Different ShortUUID implementations be compatible as long as they use the same alphabet. However, there is no official standard, so if you plan to use ShortUUID with other libraries, it's a good idea to research and test for compatibility.
16
18
17
-
**Note:** It's worth noting that different ShortUUID implementations should work together if they use the same set of characters. However, there is no official standard, so if you plan to use ShortUUID with other libraries, it's a good idea to research and test for compatibility.
18
-
19
-
Unlike some other libraries, ShortUUID doesn't generate UUIDs itself. Instead, you can input any valid UUID into the `ShortUUID.encode/1`. To generate UUIDs, you can use libraries like
19
+
Unlike some other solutions, ShortUUID does not produce UUIDs on its own as there are already plenty of libraries to do so. To generate UUIDs, use libraries such as
20
20
[Elixir UUID](https://github.com/zyro/elixir-uuid), [Erlang UUID](https://github.com/okeuday/uuid) and also [Ecto](https://hexdocs.pm/ecto/Ecto.UUID.html) as it can generate version 4 UUIDs.
21
21
22
-
ShortUUID supports common UUID formats and is case-insensitive. It also supports binary UUIDs returned from DBs like PostgreSQL when the uuid type is used to store the UUID.
22
+
ShortUUID supports common UUID formats and is case-insensitive.
23
23
24
24
## Compatibility
25
25
26
-
Starting with version `v3.0.0`, this library will follow suit with changes in other language implementations and move the most significant bit of the encoded value to the start. This also means that padding will be applied to the end of the string, not the start
27
-
This change will restore compatibility with other libraries like [shortuuid](https://github.com/skorokithakis/shortuuid) from v1.0.0 onwards and [short-uuid
28
-
](https://github.com/oculus42/short-uuid).
26
+
### v4.0.0 breaking changes
27
+
28
+
Raw binary UUID input (as `<<...>>`) is no longer supported. UUIDs must be provided as strings in standard UUID format (`"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"`) or as 32-character hex strings without hyphens.
29
+
30
+
Examples of supported formats:
31
+
```elixir
32
+
# Supported
33
+
"550e8400-e29b-41d4-a716-446655440000"# With hyphens
34
+
"550e8400e29b41d4a716446655440000"# Without hyphens
Changed bit order and padding behavior to align with other language implementations:
43
+
- Most significant bits are now encoded first
44
+
- Padding characters appear at the end of the string
45
+
- Compatible with Python's [shortuuid](https://github.com/skorokithakis/shortuuid) v1.0.0+ and Node.js [short-uuid](https://github.com/oculus42/short-uuid)
29
46
30
47
Before `v3.0.0`
31
48
```elixir
@@ -68,7 +85,7 @@ Add `:shortuuid` to your list of dependencies in `mix.exs`:
68
85
```elixir
69
86
defdepsdo
70
87
[
71
-
{:shortuuid, "~> 3.0"}
88
+
{:shortuuid, "~> 4.0"}
72
89
]
73
90
end
74
91
```
@@ -95,6 +112,69 @@ If you would like to use ShortUUID with Ecto schemas try [Ecto.ShortUUID](https:
95
112
96
113
It provides a custom Ecto type which allows for ShortUUID primary and foreign keys while staying compatible with `:binary_key` (`EctoUUID`).
97
114
115
+
## Custom Alphabets
116
+
117
+
Starting with version `v4.0.0`, ShortUUID allows you to define custom alphabets for encoding and decoding UUIDs. You can use predefined alphabets or define your own.
118
+
119
+
### Restrictions
120
+
121
+
- The alphabet must contain at least 16 unique characters.
122
+
- The alphabet must not contain duplicate characters.
123
+
124
+
### Predefined Alphabets
125
+
126
+
Starting with version `v4.0.0`, the following predefined alphabets are available:
0 commit comments