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

@point-of-sale/barcode-parser

v1.0.1

Published

[![npm](https://img.shields.io/npm/v/@point-of-sale/barcode-parser)](https://www.npmjs.com/@point-of-sale/barcode-parser) ![GitHub License](https://img.shields.io/github/license/NielsLeenheer/BarcodeParser)

Downloads

230

Readme

BarcodeParser

npm GitHub License

This library is part of @point-of-sale, a collection of libraries for interfacing browsers and Node with Point of Sale devices such as receipt printers, barcode scanners and customer facing displays.

What does this library do?

This library provides common barcode parsing functions used by the WebHIDBarcodeScanner, WebSerialBarcodeScanner, WebcamBarcodeScanner and KeyboardBarcodeScanner libraries.

How to use it?

This library is not intended to be used as a standalone direct dependancy. There is no guarantee for a stable API.

To use this library you first need to install it:

npm i @point-of-sale/barcode-parser

And import it:

import { Aim, GS1, Detector, Symbologies } from '@point-of-sale/barcode-parser';

AIM

Some barcode scanners give back an AIM Code Identifier which gives information about the barcode symbology and certain other options.

To parse the AIM Code Identifier call the Aim.decode() function. It requires two parameters: the 3 character AIM Code Indentifier, starting with a ], and the remaining value of the barcode.

let result = Aim.decode(']E0', '3046920029759');

The result will be an object with a key for the symbology:

{
    symbology: 'ean13'
}

Optionally there will be a key model for the QR code model and a key fnc1 that tells us if the FNC1 character is the first of second character of the encoded data.

GS1

Retail and warehouses often use barcodes that encode GS1 data. For example ITF-14, EAN and UPC barcodes encode the GS1 GTIN. Additionally a GS1 Digital Link QR Code, GS1 Datamatrix, GS1-128 or GS1 Databar can encode other GS1 elements.

To parse the GS1 data from a barcode you can call the GS1.decode() function. It only requires one parameter, an object with the following properties:

  • value The value of the barcode, for example: 3046920029759.
  • symbology The symbology of the barcode, for example: ean13.
  • fnc1 Optionally the value of the fnc1 property returned by the AIM.decode() function.

For example:

let result = GS1.decode({ 
    value:      '3046920029759',
    symbology:  'ean13'
});

Or:

let result = GS1.decode({ 
    value:      '010304692002975915251031',
    symbology:  'gs1-128',
    fnc1:       1
});

Or:

let result = GS1.decode({ 
    value:      'https://example.com/01/03046920029759?15=251031',
    symbology:  'qr-code'
});

The first one will result in an object with the GS1 GTIN as the only element:

{
    gtin: '03046920029759',
    elements: [
        { 
            ai: '01',
            label: 'GTIN',
            value: '03046920029759'
        }
    ]
}

The two below that will get an object with two elements:

{
    gtin: '03046920029759',
    elements: [
        { 
            ai: '01',
            label: 'GTIN',
            value: '03046920029759'
        }, { 
            ai: '15',
            label: 'BEST BEFORE or BEST BY',
            value: '251031'
        }
    ]
}

The object that is returned contains the following properties:

  • gtin Optionally, when the barcode contains a GTIN, the value of the GTIN.
  • elements An array for each element of the GS1 data. Each element is an object with an ai property for the application id, an label property containing a human readable description and value for the value of the element.

Detector

Guess the symbology based on the format of the barcode. Call the Detector.detect() function with the barcode data as a parameter.

let result = Detector.detect('3046920029759')

This results in an object with the following properties:

  • symbology The likely symbology for this barcode. It's a guess, but sometimes an educated guess.
  • guess Boolean that indicates if it is a completely guess, or if there if we're certain about our guess.

The example above will result this:

{
    symbology: 'ean13',
    guess: false
}

The barcode contains 13 digits, which makes it likely that it is a EAN-13 barcode. Additionally we've verified that the last digit is indeed the correct check digit, so we're pretty sure it is actually an EAN-13 barcode.

If the detector cannot make a determination what type of barcode it is, the function will return undefined.

Symbologies

Functions that help with specific symbologies. Right now there is only one function defined, for helping with UPC-E barcodes.

UPC-E

UPC-E barcodes are similar to UPC-A barcodes, but zero's in the barcode value are compressed, making the barcode physically smaller. Call the Symbologies.UPCE.expand() function to convert the compressed UPC-E barcode back to it's original value.

let result = Symbologies.UPCE.expand('02345673')

Will result in a string with the following value: 023456700003.


This library has been created by Niels Leenheer under the MIT license. Feel free to use it in your products. The development of this library is sponsored by Salonhub.