Documentation for JavaScript

Usage Sample

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.HIBC, ScanditParser.GS1AI or ScanditParser.DLID, 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:{…}}