npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bark-js

v1.2.1

Published

Parse barcode inputs into a unified GS1-128 like format

Downloads

2,037

Readme

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!