Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gtin

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gtin

GTIN (UPC, EAN, ITF, etc.) utilities.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12K
increased by7.11%
Maintainers
1
Weekly downloads
 
Created
Source

gtin

npm version javascript standard style travis build coveralls coverage david dependencies david dev dependencies

GTIN (UPC, EAN, ITF, etc.) utilities.

npm install gtin



gtin.validate(barcode)

Validates a GTIN (14, 13, 12, or 8-digit) barcode by check digit. Barcode must be a string.

To validate a UPC-E barcode, expand it first: validate(upce.expand('01278906'))

import {validate} from 'gtin'
validate('12341238')       // true
validate('1234123412344')  // true
validate('12341234123413') // true
validate('012000007897')   // true
validate('012000007896')   // false
validate('abc')            // Error thrown
validate(123)              // Error thrown
validate('123')            // Error thrown

gtin.minify(barcode)

Minifies GTIN to smallest possible representation, by stripping as many leading zeroes as possible. Does not compress to UPC-E.

import {minify} from 'gtin'
minify('00000012341238')  // '12341238'
minify('0000012341238')   // '12341238'
minify('01234123412344')  // '1234123412344
minify('001234123412344') // Error thrown
minify('abc')             // Error thrown
minify(123)               // Error thrown
minify('123')             // Error thrown

gtin.getFormat(barcode)

Gets the format of the given barcode. Does not validate checksum.

import {getFormat} from 'gtin'
getFormat('12341238')       // 'GTIN-8'
getFormat('123412341234')   // 'GTIN-12'
getFormat('1234123412344')  // 'GTIN-13'
getFormat('01234123412344') // 'GTIN-14'
getFormat('123412381')      // Error thrown
getFormat('abc')            // Error thrown
getFormat(123)              // Error thrown
getFormat('123')            // Error thrown

gtin.getRealFormat(barcode)

Gets the real format of the given barcode, by minifying it first.

import {getFormat} from 'gtin'
getFormat('1234123412344')  // 'GTIN-13'
getFormat('01234123412344') // 'GTIN-13'
getFormat('123412381')      // Error thrown
getFormat('abc')            // Error thrown
getFormat(123)              // Error thrown
getFormat('123')            // Error thrown

gtin.upce.compress(barcode)

Compress a UPC-A barcode to an 8-digit UPC-E barcode. Does not validate code by check digit. Barcode must be a string.

  • 12-digit UPC-A: Number system and check digits are taken into account.
  • 11-digit UPC-A: Number system 0 is assumed. Check digit is taken into account.
  • 10-digit UPC-A: Number system 0 is assumed. Check digit is generated.
import {upce} from 'gtin'
upce.compress('1200000789')   // '01278907'
upce.compress('12000007897')  // '01278907'
upce.compress('012000007897') // '01278907'
upce.compress('012000007896') // '01278906'
upce.compress('012345678905') // null
upce.compress(123)            // Error thrown
upce.compress('123')          // Error thrown
upce.compress('abc')          // Error thrown

gtin.upce.expand(barcode)

Expands a UPC-E barcode to a 12-digit UPC-A barcode. Does not validate code by check digit. Barcode must be a string.

  • 8-digit UPC-E: Number system and check digits are taken into account.
  • 7-digit UPC-E: Number system 0 is assumed. Check digit is taken into account.
  • 6-digit UPC-E: Number system 0 is assumed. Check digit is generated.
import {upce} from 'gtin'
upce.expand('127890')    // '012000007897'
upce.expand('1278907')   // '012000007897'
upce.expand('01278907')  // '012000007897'
upce.expand('01278906')  // '012000007896'
upce.expand('123412341') // Error thrown
upce.expand(123)         // Error thrown
upce.expand('123')       // Error thrown
upce.expand('abc')       // Error thrown

Keywords

FAQs

Package last updated on 12 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc