Documentation for JavaScript

Usage Sample

Load the parser library with a script tag in the HTML file in which you want to use it:

<script src="path-to-folder-containing-parser-library/scandit-parser.js"></script>

Once this is done, you can use the parser library by calling ScanditParser.

The following code shows typical usage of the parser library.

var string = '+A123BJC5D6E71G';
var options = null;
try {
    var result = ScanditParser.parseString(
        ScanditParser.Type.HIBC,
        string,
        options
        );
} catch (e) {
    // Something went wrong
}

// We can directly access the json object ...
console.log(result.json);
// .. or we can acces individual fields by name
var field = result.getFieldByName("metadata");
console.log(field.parsed);
console.log(field.rawString);

Some data formats allow for special parsing options which modify the behaviour of the parser. These can be set by specifying them in the options object, e.g.:

options = {'outputHumanReadableString' : true};

Methods

class ScanditParser
parseString(dataFormat, string, options)

string is the string to be parsed, dataFormat may be ScanditParser.Type.HIBC, ScanditParser.Type.GS1AI, ScanditParser.Type.DLID, or ScanditParser.Type.MRTD, options is a JavaScript Object containing the parser options where the keys specify the respective option name.

Returns

An object result, which contains the properties result.json (raw json output of the parser library) and the method result.getFieldByName(name) which returns a field object {name:’…’, rawString:’…’, parsed:{…}}