Current section

11 Versions

Jump to

Compare versions

4 files changed
+14 additions
-4 deletions
  @@ -1,5 +1,6 @@
1 1 [![Build Status](https://travis-ci.com/gpedic/ex_shortuuid.svg?branch=master)](https://travis-ci.com/gpedic/ex_shortuuid)
2 2 [![Coverage Status](https://coveralls.io/repos/github/gpedic/ex_shortuuid/badge.svg)](https://coveralls.io/github/gpedic/ex_shortuuid)
3 + [![Hex.pm](https://img.shields.io/hexpm/v/shortuuid.svg)](https://hex.pm/packages/shortuuid)
3 4
4 5 # ShortUUID
  @@ -10,4 +10,4 @@
10 10 {<<"links">>,[{<<"GitHub">>,<<"https://github.com/gpedic/ex_shortuuid">>}]}.
11 11 {<<"name">>,<<"shortuuid">>}.
12 12 {<<"requirements">>,[]}.
13 - {<<"version">>,<<"2.0.1">>}.
13 + {<<"version">>,<<"2.1.0">>}.
  @@ -48,6 +48,11 @@ defmodule ShortUUID do
48 48
49 49 Letter case is not relevant.
50 50
51 + Also supported since `v2.1.0` is the encoding of binary UUIDs
52 +
53 + iex> ShortUUID.encode!(<<0xFA, 0x62, 0xAF, 0x80, 0xA8, 0x61, 0x45, 0x6C, 0xAB, 0x77, 0xD5, 0x67, 0x7E, 0x2E, 0x8B, 0xA8>>)
54 + "PuQURs6h2XSBBVNgqSHJZn"
55 +
51 56 ## Using ShortUUID with Ecto
52 57
53 58 If you would like to use ShortUUIDs with Ecto check out [ecto_shortuuid](https://github.com/gpedic/ecto_shortuuid).
  @@ -79,7 +84,11 @@ defmodule ShortUUID do
79 84 {:ok, "keATfB8JP2ggT7U9JZrpV9"}
80 85
81 86 """
82 - @spec encode(String.t()) :: {:ok, String.t()} | {:error, String.t()}
87 + @spec encode(binary) :: {:ok, String.t()} | {:error, String.t()}
88 + def encode(<<uuid::128>>) do
89 + {:ok, uuid |> int_to_string |> pad_shortuuid}
90 + end
91 +
83 92 def encode(uuid) when is_binary(uuid) do
84 93 stripped_uuid = strip_uuid(uuid)
85 94
  @@ -111,7 +120,7 @@ defmodule ShortUUID do
111 120 "keATfB8JP2ggT7U9JZrpV9"
112 121
113 122 """
114 - @spec encode!(String.t()) :: String.t()
123 + @spec encode!(binary) :: String.t()
115 124 def encode!(uuid) do
116 125 case encode(uuid) do
117 126 {:ok, encoded_uuid} ->
  @@ -2,7 +2,7 @@ defmodule ShortUUID.Mixfile do
2 2 use Mix.Project
3 3
4 4 @name "ShortUUID"
5 - @version "2.0.1"
5 + @version "2.1.0"
6 6 @url "https://github.com/gpedic/ex_shortuuid"
7 7
8 8 def project do