Git Product home page Git Product logo

gtin-validator's Introduction

Real GTIN Validator

Latest Stable Version Build Status Coverage Status

A GTIN is a string of digits that uniquely identifies a trade item (a product that is bought and sold). A GTIN is globally unique, meaning that no two products in the world share the same GTIN.

This library provides a straightforward way by which a number can be determined to be a valid GTIN or suspected of being invalid in some way.

Installation

via Composer

$ composer require real-digital/gtin-validator

via GitHub

$ git clone https://github.com/real-digital/gtin-validator.git

Usage

<?php

use Real\Validator\Gtin;

// create a valid GTIN
$value = '4006381333931';
$gtin = Gtin\Factory::create($value);


// handle errors
$value = 'any invalid value';
try {
    $gtin = Gtin\Factory::create($value);
} catch (Gtin\NonNormalizable $e) {
    // ...
}


// check whether GTIN is valid
$value = '4006381333931';
$isValid = Gtin\Factory::isValid($value);

GTIN interface overview

Each created GTIN implements a common interface. This is a complete list of its methods:

Method Type Functionality
checkDigit() integer Retrieve the rightmost digit called the "Check Digit"
indicator() integer Retrieve the "Indicator" component
key() string Retrieve GTIN value having a length corresponding to its variation
length() integer Retrieve length of the variation
origin() string Retrieve an origin value used for GTIN creation
padded() string Retrieve key padded to 14 digits
prefix() string Retrieve GS1 Prefix
variation() string Retrieve variation name

Testing

$ composer tests

License

Real GTIN Validator is licensed under The Apache License 2.0. Please see LICENSE for details.

Changelog

Please see CHANGELOG for more information.

gtin-validator's People

Contributors

aazon avatar odombrovskyi-dev avatar radarlog avatar synchro avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.