Skip to content

Commit 56c38fb

Browse files
committed
Update examples in the Readme
1 parent 1956f2e commit 56c38fb

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ end
2424

2525
## Usage
2626

27-
Hashids encodes a list of integers into a char list. Some of the encoding
27+
Hashids encodes a list of integers into a string (technically, iodata). Some of the encoding
2828
parameters can be customized.
2929

3030
```elixir
@@ -49,15 +49,26 @@ Hashids.decode!(s, cipher2)
4949
```
5050

5151
It is also possible to customize the character set used for the cipher text by
52-
providing an alphabet as a char list. It has to be at least 16 characters long.
52+
providing a custom alphabet. It has to be at least 16 characters long.
5353

5454
```elixir
55-
s = Hashids.new(alphabet: "1234567890абвгдежизклмн")
55+
defmodule MyAccessToken do
56+
@cyrillic_alphabet "123456789абвгґдеєжзиіїйклмнопрстуфцчшщьюяАБВГҐДЕЄЖЗИІЇЙКЛМНОПРСТУФЦЧШЩЬЮЯ"
57+
@coder Hashids.new(alphabet: @cyrillic_alphabet)
5658

57-
cipher = Hashids.encode(s, [1234, 786, 21, 0])
58-
#=> "имнк40же3ги1з"
59+
def encode(token_ids) do
60+
Hashids.encode(@coder, token_ids)
61+
end
5962

60-
Hashids.decode(s, cipher)
63+
def decode(data) do
64+
Hashids.decode(@coder, data)
65+
end
66+
end
67+
68+
data = MyAccessToken.encode([1234, 786, 21, 0])
69+
#=> "ЦфюєИНаЛ1И"
70+
71+
MyAccessToken.decode(data)
6172
#=> {:ok, [1234, 786, 21, 0]}
6273
```
6374

0 commit comments

Comments
 (0)