View Source UkraineTaxidEx.Commons (ukraine_tax_id v0.1.1)

Common functions for UkraineTaxidEx.

Summary

Types

A one digit of EDRPOU or ITIN it's non-negative integer from 0 to 9

List of digits of EDRPOU or ITIN

Functions

Gets the check digit (last digit) from a list of digits.

Converts a string or integer to a list of digits. Takes a value and optional length and clean parameters. When length is provided, pads the result with leading zeros. When clean is true, remove all non digit character from string. Returns list of digits as integers.

Return digits and check digit separatly in one tuple.

Wraps error in an :error tuple.

Normalizes the input value to a string of the specified length. Takes a value and required length parameter. Pads the result with leading zeros. Returns a string.

Wraps data in an :ok tuple.

Converts list of digits to a string.

Splits a list of digits into value digits and check digit.

Gets all digits except the check digit from a list of digits.

Types

digit()

@type digit() :: non_neg_integer() | nil

A one digit of EDRPOU or ITIN it's non-negative integer from 0 to 9

digits()

@type digits() :: [non_neg_integer()] | []

List of digits of EDRPOU or ITIN

Functions

check_digit(digits)

@spec check_digit(digits :: digits()) :: digit()

Gets the check digit (last digit) from a list of digits.

Examples

    iex> UkraineTaxidEx.Commons.check_digit([1, 2, 3, 4])
    4

digits(value, length \\ 0, clean? \\ false)

@spec digits(
  value :: String.t() | integer(),
  length :: non_neg_integer(),
  clean? :: boolean()
) ::
  digits()

Converts a string or integer to a list of digits. Takes a value and optional length and clean parameters. When length is provided, pads the result with leading zeros. When clean is true, remove all non digit character from string. Returns list of digits as integers.

Examples

    iex> UkraineTaxidEx.Commons.digits("123")
    [1, 2, 3]

    iex> UkraineTaxidEx.Commons.digits(123, 5)
    [0, 0, 1, 2, 3]

    iex> UkraineTaxidEx.Commons.digits("987", 5)
    [0, 0, 9, 8, 7]

digits_and_check_digit(digits)

@spec digits_and_check_digit(digits :: digits()) ::
  {value_digits :: digits(), check_digit :: digit()}

Return digits and check digit separatly in one tuple.

Examples

    iex> UkraineTaxidEx.Commons.digits_and_check_digit([1, 2, 3, 4])
    {[1, 2, 3, 4], 4}

error(error)

@spec error(error :: any()) :: {:error, any()}

Wraps error in an :error tuple.

Examples

    iex> UkraineTaxidEx.Commons.error("error")
    {:error, "error"}

normalize(value, length)

Normalizes the input value to a string of the specified length. Takes a value and required length parameter. Pads the result with leading zeros. Returns a string.

Examples

    iex> UkraineTaxidEx.Commons.normalize(123, 5)
    "00123"

    iex> UkraineTaxidEx.Commons.normalize("987", 5)
    "00987"

ok(data)

@spec ok(data :: any()) :: {:ok, any()}

Wraps data in an :ok tuple.

Examples

    iex> UkraineTaxidEx.Commons.ok("data")
    {:ok, "data"}

undigits(digits)

@spec undigits(digits :: digits()) :: String.t()

Converts list of digits to a string.

Examples

    iex> UkraineTaxidEx.Commons.undigits([1, 2, 3])
    "123"

value_and_check_digits(digits)

@spec value_and_check_digits(digits :: digits()) ::
  {value_digits :: digits(), check_digit :: digit()}

Splits a list of digits into value digits and check digit.

Examples

    iex> UkraineTaxidEx.Commons.value_and_check_digits([1, 2, 3, 4])
    {[1, 2, 3], 4}

value_digits(digits)

@spec value_digits(digits :: digits()) :: digits()

Gets all digits except the check digit from a list of digits.

Examples

    iex> UkraineTaxidEx.Commons.value_digits([1, 2, 3, 4])
    [1, 2, 3]