Home

Awesome

ExGtin

CI Status contributions welcome Hex.pm Packagist

A GTIN (Global Trade Item Number) & UPC (Universal Price Code) Generation and Validation Library in Elixir under the GS1 specification.

Features

Features to Come:

Installation

WARNING 1.0.1 contains breaking changes from 1.0.0 (I know this is a patch release but the breaking changes related to the deprecation of check_gtin and generate_gtin were noted in the changelog and docs over a year ago) WARNING 1.0.0 contains breaking changes from 0.4.0

Add :ex_gtin as a dependency to your project's mix.exs:

def deps do
  [{:ex_gtin, "~> 1.1.0"}]
end

and run mix deps.get to install the :ex_gtin dependency

mix deps.get

Usage

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

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

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

Pass GTIN numbers in as a String, Number or an Array

iex> number = [6, 2, 9, 1, 0, 4, 1, 5, 0, 0, 2, 1,3]
iex> ExGtin.validate(number)
{:ok, "GTIN-13"}

iex> number = 6_291_041_500_213
iex> ExGtin.validate(number)
{:ok, "GTIN-13"}
iex> ExGtin.generate("629104150021")
{:ok, "6291041500213"}

iex> ExGtin.generate!("629104150021")
"6291041500213"
iex> ExGtin.Validation.find_gs1_prefix_country("53523235")
{:ok, "GS1 Malta"}
iex> ExGtin.normalize("6291041500213")
{:ok, "06291041500213"}

Using Strings, Arrays or Numbers

iex> ExGtin.validate("6291041500213")
{:ok, "GTIN-13"}
iex> ExGtin.validate([6, 2, 9, 1, 0, 4, 1, 5, 0, 0, 2, 1, 3])
{:ok, "GTIN-13"}
iex> ExGtin.validate(6291041500213)
{:ok, "GTIN-13"}

Integers with leading zeros may not process properly

Reference

Documentation can be found at https://hexdocs.pm/ex_gtin on HexDocs.

Tests

Run tests with

mix test

Run test coverage

MIX_ENV=test mix coveralls

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

When making pull requests, please be sure to update the CHANGELOG.md with the corresponding changes. Please make sure that all tests pass, add tests for new functionality and that the static analysis checker credo is run. Use mix pull_request_checkout.task to ensure that everything checks out.

Run static code analysis

mix credo

Generate Documentation

mix docs

Run the gambit of tests, static analysis and coverage

mix pull_request_checkout.task

Sponsors

This project is sponsored by KickinEspresso

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Code of Conduct

Please refer to the Code of Conduct for details

Security

Please refer to the Security for details

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Publish & Releasing

mix hex.publish