ExGtin.Validation (ExGtin v1.2.0)

View Source

Documentation for ExGtin. This library provides functionality for validating GTIN compliant codes.

Summary

Functions

Checks the code for the proper length as specified by the GTIN-8,12,13,14 specification

Find the GS1 prefix country for a GTIN number

When generating the code, checks the code for the proper length as specified by the GTIN-8,12,13,14 specification. The code should be -1 the length of the GTIN code as the check digit will be added later

Generate check digit GTIN-8, GTIN-12, GTIN-13, GTIN-14, GSIN, SSCC codes

Generate valid GTIN-8, GTIN-12, GTIN-13, GTIN-14, GSIN, SSCC codes

Check for valid GTIN-8, GTIN-12, GTIN-13, GTIN-14, GSIN, SSCC codes

Looks up the GS1 prefix in a table GS1 Reference https://www.gs1.org/company-prefix

By index, returns the corresponding value to multiply the digit by

Calculates the sum of the digits in a string and multiplied value based on index order

Calculates the difference of the highest rounded multiple of 10

Functions

check_code_length(number)

(since 1.0.0)
@spec check_code_length([number()]) :: {atom(), String.t()}

Checks the code for the proper length as specified by the GTIN-8,12,13,14 specification

Returns {atom, String.t()}

Examples

iex> ExGtin.Validation.check_code_length([1,2,3,4,5,6,7,8])
{:ok, "GTIN-8"}

iex> ExGtin.Validation.check_code_length([1,2,3,4,5,6,7])
{:error, "Invalid GTIN Code Length"}

find_gs1_prefix_country(number)

(since 1.0.0)
@spec find_gs1_prefix_country(String.t()) :: {atom(), String.t()}
@spec find_gs1_prefix_country(number()) :: {atom(), String.t()}
@spec find_gs1_prefix_country([number()]) :: {atom(), String.t()}

Find the GS1 prefix country for a GTIN number

Returns {atom, String.t()}

Examples

iex> ExGtin.Validation.find_gs1_prefix_country("53523235")
{:ok, "GS1 Malta"}

iex> ExGtin.Validation.find_gs1_prefix_country("6291041500214")
{:ok, "GS1 Emirates"}

iex> ExGtin.Validation.find_gs1_prefix_country("9541041500214")
{:error, "No GS1 prefix found"}

generate_check_code_length(number)

(since 1.0.0)
@spec generate_check_code_length([number()]) :: {atom(), String.t()}

When generating the code, checks the code for the proper length as specified by the GTIN-8,12,13,14 specification. The code should be -1 the length of the GTIN code as the check digit will be added later

Returns {atom, String.t()}

Examples

iex> ExGtin.Validation.generate_check_code_length([1,2,3,4,5,6,7])
{:ok, "GTIN-8"}

iex> ExGtin.Validation.generate_check_code_length([1,2,3,4,5,6])
{:error, "Invalid GTIN Code Length"}

generate_check_digit(number)

(since 1.0.0)
@spec generate_check_digit([number()]) :: number()

Generate check digit GTIN-8, GTIN-12, GTIN-13, GTIN-14, GSIN, SSCC codes

Returns number

Examples

iex> ExGtin.Validation.generate_check_digit([6,2,9,1,0,4,1,5,0,0,2,1])
3

generate_gtin_code(number)

(since 1.0.0)
@spec generate_gtin_code(String.t()) :: String.t() | {atom(), String.t()}
@spec generate_gtin_code(number()) :: String.t() | {atom(), String.t()}
@spec generate_gtin_code([number()]) :: String.t() | {atom(), String.t()}

Generate valid GTIN-8, GTIN-12, GTIN-13, GTIN-14, GSIN, SSCC codes

Returns {atom, String.t()}

Examples

iex> ExGtin.Validation.generate_gtin_code("629104150021")
{:ok, "6291041500213"}

iex> ExGtin.Validation.generate_gtin_code("62921")
{:error, "Invalid GTIN Code Length"}

gtin_check_digit(number)

(since 1.0.0)
@spec gtin_check_digit(String.t()) :: {atom(), String.t()}
@spec gtin_check_digit(number()) :: {atom(), String.t()}
@spec gtin_check_digit([number()]) :: {atom(), String.t()}

Check for valid GTIN-8, GTIN-12, GTIN-13, GTIN-14, GSIN, SSCC codes

Returns {atom, String.t()}

Examples

iex> ExGtin.Validation.gtin_check_digit("6291041500213")
{:ok, "GTIN-13"}

iex> ExGtin.Validation.gtin_check_digit("6291041500214")
{:error, "Invalid Code"}

lookup_gs1_prefix(number)

(since 1.0.0)
@spec lookup_gs1_prefix(integer()) :: {atom(), String.t()}

Looks up the GS1 prefix in a table GS1 Reference https://www.gs1.org/company-prefix

Returns {atom, String.t()}

mult_by_index_code(index)

(since 1.0.0)
@spec mult_by_index_code(number()) :: number()

By index, returns the corresponding value to multiply the digit by

Returns number

Examples

iex> ExGtin.Validation.mult_by_index_code(1)
1

iex> ExGtin.Validation.mult_by_index_code(2)
3

multiply_and_sum_array(numbers)

(since 1.0.0)
@spec multiply_and_sum_array([number()]) :: number()

Calculates the sum of the digits in a string and multiplied value based on index order

Returns number

Examples

iex> ExGtin.Validation.multiply_and_sum_array([6,2,9,1,0,4,1,5,0,0,2,1])
57

subtract_from_nearest_multiple_of_ten(number)

(since 1.0.0)
@spec subtract_from_nearest_multiple_of_ten(number()) :: number()

Calculates the difference of the highest rounded multiple of 10

Returns number

Examples

iex> ExGtin.Validation.subtract_from_nearest_multiple_of_ten(57)
3