gtin v0.1.0 GTIN

This module provides a custom datatype for Global Trade Item Numbers. This includes the EAN, UPC, ISBN, ISSN standards.

Examples

iex> GTIN.new(4388810057657)
%GTIN{id: 438881005765, check_digit: 7}

iex> GTIN.new("4388810057657")
%GTIN{id: 438881005765, check_digit: 7}

iex> GTIN.new("978-3-7643-7755-7")
%GTIN{id: 978376437755, check_digit: 7}

Validations:

iex> ean = GTIN.new(4388810057657)
iex> GTIN.validate(ean)
true

iex> GTIN.validate("978-3-7643-7755-7")
true

iex> GTIN.validate("978-3-7643-7785-7") # Typo in ISBN
false

Summary

Functions

Creates a new GTIN struct from either:

  • an integer
  • a string which parses as an integer
  • a string containing dashes and numbers (as usual for ISBNs)

Validates a GTIN. Can take either a GTIN struct or any argument valid for new

Functions

new(gtin)

Creates a new GTIN struct from either:

  • an integer
  • a string which parses as an integer
  • a string containing dashes and numbers (as usual for ISBNs)
validate(gtin)

Validates a GTIN. Can take either a GTIN struct or any argument valid for new.