Giter VIP home page Giter VIP logo

bark-js's Introduction

Bark JS

npm version Travis Issues

Bark parses GS1-128 barcodes and extracts the catalogued data according to the GS1 General Specifications (PDF). It can also parse other SKU-related formats to convert into GTINs in GS1, such as EAN-13, ITF-14 and UPC-A.

How to use it

npm install bark-js

Examples

Let's pretend we scan the box in this photo.

const bark = require('bark-js')

bark( '015730033004265615171019' )
// returns:
{
  symbology: 'unknown',
  elements: [
    {
      ai: '01',
      title: 'GTIN',
      value: '57300330042656',
      raw: '57300330042656'
    },
    {
      ai: '15',
      title: 'BEST BEFORE or BEST BY',
      value: '2017-10-19',
      raw: '171019'
    }
  ],
  originalBarcode: '015730033004265615171019'
}

If you are going to scan simple barcodes (e.g. UPC-A, EAN-13, ITF-14, etc.) you can set the assumeGtin option to treat shorter barcodes (11-14 digits) as GS1-128 with a GTIN AI:

const bark = require('bark-js')

bark( '09002490100094', { assumeGtin: true } )
// returns:
{
  symbology: 'unknown',
  elements: [
    {
      ai: '01',
      title: 'GTIN',
      value: '09002490100094',
      raw: '09002490100094'
    }
  ],
  originalBarcode: '0109002490100094'
}

Depending on your barcode reader, you may receive FNC characters that arent the <GS> (ASCII 29) character. To set the group separator yourself, pass the fnc option:

const bark = require('bark-js')

bark( '10FRIDGEX0109002490100094', { fnc: 'X' } )
// returns:
{
  symbology: 'unknown',
  elements: [
    {
      ai: '10',
      title: 'BATCH/LOT',
      value: 'FRIDGE',
      raw: 'FRIDGEX'
    },
    {
      ai: '01',
      title: 'GTIN',
      value: '09002490100094',
      raw: '09002490100094'
    }
  ],
  originalBarcode: '10FRIDGEX0109002490100094'
}

Depending on the type of elements in your code, the parsers may append additional fields to such as isoCurrencyCode and amount for your convenience:

const bark = require('bark-js')

bark( '393297817999' )
// returns:
{
  symbology: 'unknown',
  elements: [
    {
      ai: '3932',
      title: 'PRICE',
      value: '978179.99',
      isoCurrencyCode: '978',
      amount: '179.99',
      raw: '97817999'
    }
  ],
  originalBarcode: '393297817999'
}

Contributing

Pull requests to Sleavely/Bark-JS are encouraged and appreciated!

bark-js's People

Contributors

sleavely avatar dependabot[bot] avatar uzef1997 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.