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.
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.
If there are no errors, the interpretScan()
function returns an object as follows
AIbrackets
: The equivalent GS1 element string in human-readable AI syntaxAIfnc1
: 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 Identifierlabel
: what that AI is used forvalue
: the value
The order for the ol
list matches that found in a GS1 Digital Link URI
- primary identifier
- any applicable qualifiers
- any data attributes
- 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.
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.
You might want to head over to the scanner demo.
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.