-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (29 loc) · 1.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const barcodeInput = document.getElementById('barcode');
document.getElementById('parseBarcodeParserButton').onclick = () => {
// sample code showing how to parse a GS1 barcode using the BarcodeParser library
const data = barcodeInput.value;
const outputElem = document.getElementById('barcodeParserOutput');
try {
const answer = parseBarcode(data);
let hri = '';
for (let item of answer.parsedCodeItems) {
hri += `${item.ai} (${item.dataTitle}): ${item.data}`;
hri += '\n';
}
outputElem.innerText = hri;
} catch (e) {
outputElem.innerText = `ERR Parsing failed with error: ${e}`;
}
};
document.getElementById('parseDLTButton').onclick = () => {
// sample code showing how to parse a GS1 barcode using the GS1 Digital Link Toolkit library
const data = barcodeInput.value;
const outputElem = document.getElementById('dltOutput');
try {
const dlt = new GS1DigitalLinkToolkit();
const answer = dlt.extractFromGS1elementStrings(data);
outputElem.innerText = JSON.stringify(answer);
} catch (e) {
outputElem.innerText = `ERR Parsing failed with error: ${e}`;
}
};