Hashids (hashids v2.0.5) View Source
Hashids lets you obfuscate numerical identifiers via reversible mapping.
Example
h = Hashids.new(salt: "my salt")
encoded = Hashids.encode(h, [1,2,3])
{:ok, [1,2,3]} = Hashids.decode(h, encoded)
Link to this section Summary
Functions
Decode the given iodata back into a list of numbers.
Decode the given iodata back into a list of numbers.
Encode the given number or a list of numbers.
Link to this section Functions
Specs
decode(t(), iodata()) :: {:ok, [non_neg_integer()]} | {:error, :invalid_input_data}
Decode the given iodata back into a list of numbers.
Specs
decode!(t(), iodata()) :: [non_neg_integer()] | no_return()
Decode the given iodata back into a list of numbers.
Will raise a Hashids.DecodingError
if the provided data is not a valid hash value or a
Hashids struct with incompatible alphabet.
Specs
encode(t(), non_neg_integer()) :: iodata()
encode(t(), [non_neg_integer()]) :: iodata()
Encode the given number or a list of numbers.
Only non-negative integers are supported.
Specs
new(alphabet: binary(), salt: binary(), min_len: non_neg_integer()) :: t()
Create a struct containing the configuration options for Hashids. It should be passed to
encode/2
and decode/2
.
Raises Hashids.Error
if it encounters an invalid option.
Options
:alphabet
– a string of characters to be used in the resulting hash value. By default, characters from the Latin alphabet and digits are used.:salt
– a string that will be used to permute the hash value and make it decodable only by using the same salt that was provided during encoding. Default: empty string.:min_len
– the minimum length of the resulting hash. Default: 0.