View Source Hashids (hashids v2.1.0)
Hashids lets you obfuscate numerical identifiers via reversible mapping.
example
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
@spec decode(t(), iodata()) :: {:ok, [non_neg_integer()]} | {:error, :invalid_input_data}
Decode the given iodata back into a list of numbers.
@spec 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.
@spec encode(t(), non_neg_integer()) :: iodata()
@spec encode(t(), [non_neg_integer()]) :: iodata()
Encode the given number or a list of numbers.
Only non-negative integers are supported.
@spec 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
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.