Recordlocator (recordlocator v1.0.0)
Recordlocator
is a module for generating Recordlocators from integer values and decoding Recordlocators back to the integer value.
A Recordlocator is an alphanumeric representation for an integer value. It uses a 32 character alphabet to encode the integer values. A RecordLocator is shorter than the corresponding integer and easier to read and memorize. You can use it to encode autoincrement primary keys from an database into an human-readable representation for your users.
Summary
Functions
Decodes Recordlocator string back into an integer. Returns {:ok, integer} for valid Recordlocators and {:error, reason} for invalid characters.
Decodes Recordlocator string back into an integer. Throws an ArgumentError if the input string contains invalid characters.
Encodes an integer into a Recordlocator.
Encodes an integer into a Recordlocator. Throws an ArgumentError for errors.
Functions
decode(string)
@spec decode(String.t()) :: {:ok, non_neg_integer()} | {:error, String.t()}
Decodes Recordlocator string back into an integer. Returns {:ok, integer} for valid Recordlocators and {:error, reason} for invalid characters.
Examples
iex> Recordlocator.decode("78G")
iex> Recordlocator.decode("5E82T")
iex> Recordlocator.decode("2")
iex> Recordlocator.decode("ABC")
decode!(string)
@spec decode!(String.t()) :: non_neg_integer()
Decodes Recordlocator string back into an integer. Throws an ArgumentError if the input string contains invalid characters.
Examples
iex> Recordlocator.decode!("78G") 5325
iex> Recordlocator.decode!("5E82T") 3512345
iex> Recordlocator.decode!("2") 0
iex> Recordlocator.decode!("ABC") ** (ArgumentError) Invalid character in input string: B
encode(integer)
Encodes an integer into a Recordlocator.
Examples
iex> Recordlocator.encode(5325)
iex> Recordlocator.encode(3512345)
iex> Recordlocator.encode(-1)
encode!(integer)
Encodes an integer into a Recordlocator. Throws an ArgumentError for errors.
Examples
iex> Recordlocator.encode!(5325) "78G"
iex> Recordlocator.encode!(3512345) "5E82T"
iex> Recordlocator.encode!(-1) ** (ArgumentError) Input must be a non-negative integer