ExGtin (ExGtin v1.0.1) View Source

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

Link to this section Summary

Functions

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

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

Find the GS1 prefix country for a GTIN number

Check for 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

Link to this section Functions

Link to this function

generate(number)

View Source (since 0.4.0)

Specs

generate(String.t() | [number()]) :: number() | {atom(), String.t()}

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

Returns code with check digit

Examples

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

iex> ExGtin.generate("62921")
{:error, "Invalid GTIN Code Length"}
Link to this function

generate!(number)

View Source (since 1.0.0)

Specs

generate!(String.t() | [number()]) :: number() | {atom(), String.t()}

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

Throws Argument Exception if there was an error

Examples

iex> ExGtin.generate!("629104150021")
"6291041500213"

iex> ExGtin.generate("62921")
{:error, "Invalid GTIN Code Length"}
Link to this function

gs1_prefix_country(number)

View Source (since 0.1.0)

Specs

gs1_prefix_country(String.t() | [number()]) :: {atom(), String.t()}

Find the GS1 prefix country for a GTIN number

Returns {atom, String.t()}

Examples

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

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

iex> ExGtin.gs1_prefix_country("9541041500214")
{:error, "No GS1 prefix found"}
Link to this function

validate(number)

View Source (since 0.4.0)

Specs

validate(String.t() | [number()]) :: {atom(), String.t()}

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

Returns {:ok, "GTIN-#"} or {:error}

Examples

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

iex> ExGtin.validate("6291041500214")
{:error, "Invalid Code"}
Link to this function

validate!(number)

View Source (since 1.0.0)

Specs

validate!(String.t() | [number()]) :: {atom(), String.t()}

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

Throws ArgumentError if an error occurs

Examples

iex> ExGtin.validate!("6291041500213")
"GTIN-13"