DarkMatter.ShortIds (DarkMatter v1.1.4) View Source
Generates a unique short_id
for use in abreviated non-uuid id aliases.
The alphabet is truncated based on the reasoning found here: https://fiznool.com/blog/2014/11/16/short-id-generation-in-javascript/
Link to this section Summary
Functions
Decodes a given key
from a unique short-id
Handles parsing the response
Handles parsing the response and raising an error in the event of failure
Encodes a given cipher
to a unique short-id
Link to this section Types
Specs
cipher() :: String.t()
Specs
key() :: pos_integer()
Specs
keys() :: [pos_integer()]
Specs
options() :: [alphabet: binary(), salt: binary(), min_len: pos_integer()]
Link to this section Functions
Link to this function
decode(cipher, opts \\ [alphabet: "ABDEGJKMNPQRVWXYZ23456789", min_len: 3])
View SourceSpecs
Decodes a given key
from a unique short-id
## Examples
iex> decode("NY6")
{:ok, [5]}
Link to this function
decode_singular_cipher(cipher, opts \\ [alphabet: "ABDEGJKMNPQRVWXYZ23456789", min_len: 3])
View SourceSpecs
Handles parsing the response
## Examples
iex> decode_singular_cipher("NY6")
{:ok, 5}
iex> decode_singular_cipher("")
:error
iex> decode_singular_cipher("RZJRXKW936")
:error
Specs
Handles parsing the response and raising an error in the event of failure
## Examples
iex> decode_singular_cipher!("NY6")
5
iex> decode_singular_cipher!("")
** (ArgumentError) ShortIds: invalid cipher: ""
Link to this function
encode(key, opts \\ [alphabet: "ABDEGJKMNPQRVWXYZ23456789", min_len: 3])
View SourceSpecs
Encodes a given cipher
to a unique short-id
## Examples
iex> encode(5)
"NY6"
iex> encode([5, 38, 12345])
"RZJRXKW936"