/
symbologies.js
32 lines (29 loc) Β· 938 Bytes
/
symbologies.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
/**
* Looks at the start of a barcode to identify
* the type of GS1 symbology is being read.
*
* @param {string} originalBarcode
* @return {obj} The symbology name and part of barcode that remains to be parsed.
*/
const findSymbology = (originalBarcode) => {
const symbologies = [
{ prefix: ']C1', name: 'GS1-128' },
{ prefix: ']e0', name: 'GS1 DataBar' },
{ prefix: ']e1', name: 'GS1 Composite' },
{ prefix: ']e2', name: 'GS1 Composite' },
{ prefix: ']d2', name: 'GS1 DataMatrix' },
{ prefix: ']Q3', name: 'GS1 QR Code' },
]
const symbologyUsed = symbologies.find(({ prefix }) => originalBarcode.startsWith(prefix))
if (symbologyUsed) {
return {
symbology: symbologyUsed.name,
remainingBarcode: originalBarcode.slice(symbologyUsed.prefix.length),
}
}
return {
symbology: 'unknown',
remainingBarcode: originalBarcode,
}
}
module.exports = exports = findSymbology