UNPKG

javascript-barcode-reader

Version:

Simple & Fast Barcode decoder for Browser and Node.js

38 lines 952 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decoder = void 0; const CHAR_SET = { nnnnnww: '0', nnnnwwn: '1', nnnwnnw: '2', wwnnnnn: '3', nnwnnwn: '4', wnnnnwn: '5', nwnnnnw: '6', nwnnwnn: '7', nwwnnnn: '8', wnnwnnn: '9', nnnwwnn: '-', nnwwnnn: '$', wnnnwnw: ':', wnwnnnw: '/', wnwnwnn: '.', nnwwwww: '+', nnwwnwn: 'A', nnnwnww: 'B', nwnwnnw: 'C', nnnwwwn: 'D', }; function decoder(lines) { const code = []; const barThreshold = Math.ceil(lines.reduce((pre, item) => (pre + item) / 2, 0)); // Read one encoded character at a time. while (lines.length > 0) { const seg = lines.splice(0, 8).splice(0, 7); const a = seg.map(line => (line < barThreshold ? 'n' : 'w')).join(''); code.push(CHAR_SET[a]); } return code.join(''); } exports.decoder = decoder; //# sourceMappingURL=index.js.map