Skip to content

A JavaScript library the interprets a string typically from a barcode scan

License

Notifications You must be signed in to change notification settings

gs1/interpretGS1scan

Repository files navigation

Interpret GS1 scan

Interpret GS1 scan is a JavaScript library that interprets a given string of data as its constituent GS1 application identifiers and their values. It accepts AI syntax, both human readable and using FNC1, as well as GS1 Digital Link URIs. The primary use case is the interpretation of a string captured by scanning a barcode.

Dependency

Interpret GS1 scan depends on the GS1 Digital Link toolkit and the plausibleGS1DL.js function. The latter includes ample documentation within the code itself and exists to provide a simple way to determine whether a given string plausibly is, or definitely is not, a GS1 Digital Link URI.

The Interpret Scan function

If there are no errors, the interpretScan() function returns an object as follows

  • AIbrackets: The equivalent GS1 element string in human-readable AI syntax
  • AIfnc1: The equivalent GS1 element string in AI syntax with FNC1 (as used in barcodes)
  • dl: The equivalent GS1 Digital Link URL (on id.gs1.org)
  • ol: An ordered array of objects parsed/interpreted from the input string:
    • ai: the GS1 Application Identifier
    • label: what that AI is used for
    • value: the value

The order for the ol list matches that found in a GS1 Digital Link URI

  1. primary identifier
  2. any applicable qualifiers
  3. any data attributes
  4. any non-GS1 AIs and their values

Simply pass the string to be interpreted to the `interpretScan()` function.

It can handle any of the 3 formats as input:

  • Human readable AI syntax (i.e. with brackets)
  • Pure AI syntax (i.e. with the FNC1 character)
  • GS1 Digital Link URI

If the input string cannot be interpreted, i.e. it's not a valid GS1 string, then the returned object has a value for errmsg which is the system error message.

Display interpretation

A second function, displayInterpretation() takes two parameters: the string (which it passes to interpretScan()) and the element in an HTML page to which it can write its interpretation (as a number of DOM elements).

A basic demo is available.

Scanner demo

You might want to head over to the scanner demo.

QR code for https://gs1.github.io/interpretGS1scan/camera.html

Sadly, this demo does not work in all browsers. It seems to work well with:

  • Samsung Internet on Android
  • Chrome on Android

It is usable but without the beep or choice of camera when used with Safari on iOS

It does not work with Chrome on iOS

It does not work with Firefox on Windows

We'll do what we can to improve this but a lot of it is down to the underlying libraries and the variance in implementation of the camera API across browsers and platforms.

About

A JavaScript library the interprets a string typically from a barcode scan

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published