Elixir GTIN & UPC Generation and Validation Library
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
lib
test
.editorconfig
.gitignore
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README.md
mix.exs
mix.lock

README.md

ExGtin

Build 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

  • Supports GTIN-8, GTIN-12 (UPC-12), GTIN-13 (GLN), GTIN-14, GSIN, SSCC codes
  • Generate GTIN
  • Check GTIN validity
  • Lookup GS1 country prefix

Installation

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

Usage

  • Check GTIN codes

    iex> ExGtin.check_gtin("6291041500213")
    {:ok, "GTIN-13"}
    
    iex> ExGtin.check_gtin("6291041500214")
    {:error, "Invalid Code"}
    
  • Generate GTIN codes

    iex> ExGtin.generate_gtin("629104150021")
    "6291041500213"
    
  • Lookup GS1 Prefix

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

Using Strings, Arrays or Numbers

  • String

    iex> ExGtin.check_gtin("6291041500213")
    {:ok, "GTIN-13"}
    
  • Array of Integers

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

    iex> ExGtin.check_gtin(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

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.

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

License

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

Publish

mix hex.publish