This is an Elm port of the Hashids library by Ivan Akimov. This is not a cryptographic hashing algorithm. Hashids is typically used to encode numbers to a format suitable for appearance in places like urls.
See the official Hashids home page: http://hashids.org
Hashids is a small open-source library that generates short, unique, non-sequential ids from numbers. It converts numbers like 347 into strings like @yr8@, or a list of numbers like [27, 986] into @3kTMd@. You can also decode those ids back. This is useful in bundling several parameters into one or simply using them as short UIDs.
Create a context object using the given salt, a minimum hash length, and a custom alphabet. If you only need to supply the salt, or the first two arguments, use 'hashidsSimple' or 'hashidsMinimum' instead.
Changing the alphabet is useful if you want to make your hashes unique, i.e., create hashes different from those generated by other applications relying on the same algorithm.
Create a context object using the default alphabet and the provided salt, without any minimum required length.
Create a context object using the default alphabet and the provided salt. The generated hashes will have a minimum length as specified by the second argument.
Encode a hexadecimal number.
Example use:
encodeHex context "ff83"Decode a hash generated with 'encodeHex'.
Example use:
decodeHex context "yzgwD"Encode a single number.
Example use:
hash =
let
context = hashidsSimple "this is my salt"
in
encode context 5 -- == "rD"Encode a list of numbers.
Example use:
hash =
let
context = hashidsSimple "this is my salt"
in
encodeList context [2, 3, 5, 7, 11] -- == "EOurh6cbTD"Decode a hash.
Example use:
hash =
let
context = hashidsSimple "this is my salt"
in
decode context "rD" -- == [5]Encode a number using the provided salt.
This convenience function creates a context with the default alphabet. If the same context is used repeatedly, use 'encode' with one of the constructors instead.
Encode a list of numbers using the provided salt.
This function wrapper creates a context with the default alphabet. If the same context is used repeatedly, use 'encodeList' with one of the constructors instead.
Decode a hash using the provided salt.
This convenience function creates a context with the default alphabet. If the same context is used repeatedly, use 'decode' with one of the constructors instead.
Shortcut for 'encodeHex'.
Shortcut for 'decodeHex'.
Opaque type with various internals required for encoding and decoding.