Socket
Socket
Sign inDemoInstall

javascript-barcode-reader

Package Overview
Dependencies
90
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.6.6 to 0.6.7

235

dist/javascript-barcode-reader.es5.js
import { read } from 'jimp';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
const CHAR_SET = {

@@ -918,49 +942,51 @@ nnnnnww: '0',

const isNode = typeof process === 'object' && process.release && process.release.name === 'node';
async function getImageDataFromSource(source) {
return new Promise((resolve, reject) => {
if (typeof source === 'string') {
if (source.startsWith('#')) {
const imageElement = document.getElementById(source.substr(1));
if (imageElement instanceof HTMLImageElement) {
resolve(createImageData(imageElement));
function getImageDataFromSource(source) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
if (typeof source === 'string') {
if (source.startsWith('#')) {
const imageElement = document.getElementById(source.substr(1));
if (imageElement instanceof HTMLImageElement) {
resolve(createImageData(imageElement));
}
if (imageElement instanceof HTMLCanvasElement) {
const ctx = imageElement.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
resolve(ctx.getImageData(0, 0, imageElement.width, imageElement.height));
}
reject(new Error('Invalid image source specified!'));
}
if (imageElement instanceof HTMLCanvasElement) {
const ctx = imageElement.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
resolve(ctx.getImageData(0, 0, imageElement.width, imageElement.height));
else if (isUrl(source)) {
const img = new Image();
img.onerror = reject;
img.onload = () => resolve(createImageData(img));
img.src = source;
}
reject(new Error('Invalid image source specified!'));
else if (isNode) {
read(source, (err, image) => {
if (err) {
reject(err);
}
else {
const { data, width, height } = image.bitmap;
resolve({
data: Uint8ClampedArray.from(data),
width,
height,
});
}
});
}
}
else if (isUrl(source)) {
const img = new Image();
img.onerror = reject;
img.onload = () => resolve(createImageData(img));
img.src = source;
else if (source instanceof HTMLImageElement) {
resolve(createImageData(source));
}
else if (isNode) {
read(source, (err, image) => {
if (err) {
reject(err);
}
else {
const { data, width, height } = image.bitmap;
resolve({
data: Uint8ClampedArray.from(data),
width,
height,
});
}
});
else if (source instanceof HTMLCanvasElement) {
const ctx = source.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
resolve(ctx.getImageData(0, 0, source.width, source.height));
}
}
else if (source instanceof HTMLImageElement) {
resolve(createImageData(source));
}
else if (source instanceof HTMLCanvasElement) {
const ctx = source.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
resolve(ctx.getImageData(0, 0, source.width, source.height));
}
});
});

@@ -979,3 +1005,3 @@ }

const index = (row * width + column) * channels;
columnSum += Math.sqrt((data[index] ** 2 + data[index + 1] ** 2 + data[index + 2] ** 2) / 3);
columnSum += Math.sqrt((Math.pow(data[index], 2) + Math.pow(data[index + 1], 2) + Math.pow(data[index + 2], 2)) / 3);
}

@@ -1004,3 +1030,2 @@ // pixels are same in column

// available decoders
const isTestEnv = process && process.env.NODE_ENV === 'test';

@@ -1020,64 +1045,66 @@ var BARCODE_DECODERS;

}
async function javascriptBarcodeReader({ image, barcode, barcodeType, options, }) {
let decoder$6;
switch (barcode) {
case BARCODE_DECODERS.codabar:
decoder$6 = decoder;
break;
case BARCODE_DECODERS['code-128']:
decoder$6 = decoder$1;
break;
case BARCODE_DECODERS['code-39']:
decoder$6 = decoder$2;
break;
case BARCODE_DECODERS['code-93']:
decoder$6 = decoder$3;
break;
case BARCODE_DECODERS['code-2of5']:
decoder$6 = decoder$4;
break;
case BARCODE_DECODERS['ean-13']:
decoder$6 = decoder$5;
barcodeType = '13';
break;
case BARCODE_DECODERS['ean-8']:
decoder$6 = decoder$5;
barcodeType = '8';
break;
default:
throw new Error(`Invalid barcode specified. Available decoders: ${BARCODE_DECODERS}.`);
}
const useSinglePass = isTestEnv || (options && options.singlePass) || false;
const { data, width, height } = isImageLike(image) ? image : await getImageDataFromSource(image);
const channels = data.length / (width * height);
let finalResult = '';
// apply adaptive threshold
if (options && options.useAdaptiveThreshold) {
applyAdaptiveThreshold(data, width, height);
}
// check points for barcode location
const searchPoints = [5, 6, 4, 7, 3, 8, 2, 9, 1];
const searchLineStep = Math.round(height / searchPoints.length);
const rowsToScan = Math.min(2, height);
for (let i = 0; i < searchPoints.length; i += 1) {
const start = channels * width * Math.floor(searchLineStep * searchPoints[i]);
const end = start + rowsToScan * channels * width;
const lines = getLines(data.slice(start, end), width, rowsToScan);
if (lines.length === 0) {
if (useSinglePass || i === searchPoints.length - 1) {
throw new Error('Failed to detect lines in the image!');
function javascriptBarcodeReader({ image, barcode, barcodeType, options, }) {
return __awaiter(this, void 0, void 0, function* () {
let decoder$6;
switch (barcode) {
case BARCODE_DECODERS.codabar:
decoder$6 = decoder;
break;
case BARCODE_DECODERS['code-128']:
decoder$6 = decoder$1;
break;
case BARCODE_DECODERS['code-39']:
decoder$6 = decoder$2;
break;
case BARCODE_DECODERS['code-93']:
decoder$6 = decoder$3;
break;
case BARCODE_DECODERS['code-2of5']:
decoder$6 = decoder$4;
break;
case BARCODE_DECODERS['ean-13']:
decoder$6 = decoder$5;
barcodeType = '13';
break;
case BARCODE_DECODERS['ean-8']:
decoder$6 = decoder$5;
barcodeType = '8';
break;
default:
throw new Error(`Invalid barcode specified. Available decoders: ${BARCODE_DECODERS}.`);
}
const useSinglePass = isTestEnv || (options && options.singlePass) || false;
const { data, width, height } = isImageLike(image) ? image : yield getImageDataFromSource(image);
const channels = data.length / (width * height);
let finalResult = '';
// apply adaptive threshold
if (options && options.useAdaptiveThreshold) {
applyAdaptiveThreshold(data, width, height);
}
// check points for barcode location
const searchPoints = [5, 6, 4, 7, 3, 8, 2, 9, 1];
const searchLineStep = Math.round(height / searchPoints.length);
const rowsToScan = Math.min(2, height);
for (let i = 0; i < searchPoints.length; i += 1) {
const start = channels * width * Math.floor(searchLineStep * searchPoints[i]);
const end = start + rowsToScan * channels * width;
const lines = getLines(data.slice(start, end), width, rowsToScan);
if (lines.length === 0) {
if (useSinglePass || i === searchPoints.length - 1) {
throw new Error('Failed to detect lines in the image!');
}
continue;
}
continue;
// Run the decoder
const result = decoder$6(lines, barcodeType);
if (!result)
continue;
else if (useSinglePass || !result.includes('?'))
return result;
finalResult = combineAllPossible(finalResult, result);
if (!finalResult.includes('?'))
return finalResult;
}
// Run the decoder
const result = decoder$6(lines, barcodeType);
if (!result)
continue;
else if (useSinglePass || !result.includes('?'))
return result;
finalResult = combineAllPossible(finalResult, result);
if (!finalResult.includes('?'))
return finalResult;
}
return finalResult;
return finalResult;
});
}

@@ -1084,0 +1111,0 @@

@@ -1,2 +0,16 @@

import{read as n}from"jimp";const e={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 t(n){const t=[],w=Math.ceil(n.reduce((n,e)=>(n+e)/2,0));for(;n.length>0;){const o=n.splice(0,8).splice(0,7).map(n=>n<w?"n":"w").join("");t.push(e[o])}return t.join("")}const w=["212222","222122","222221","121223","121322","131222","122213","122312","132212","221213","221312","231212","112232","122132","122231","113222","123122","123221","223211","221132","221231","213212","223112","312131","311222","321122","321221","312212","322112","322211","212123","212321","232121","111323","131123","131321","112313","132113","132311","211313","231113","231311","112133","112331","132131","113123","113321","133121","313121","211331","231131","213113","213311","213131","311123","311321","331121","312113","312311","332111","314111","221411","431111","111224","111422","121124","121421","141122","141221","112214","112412","122114","122411","142112","142211","241211","221114","413111","241112","134111","111242","121142","121241","114212","124112","124211","411212","421112","421211","212141","214121","412121","111143","111341","131141","114113","114311","411113","411311","113141","114131","311141","411131","211412","211214","211232","233111","211133","2331112"],o=[" ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL","BS","HT","LF","VT","FF","CR","SO","SI","DLE","DC1","DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM","SUB","ESC","FS","GS","RS","US","FNC 3","FNC 2","Shift B","Code C","Code B","FNC 4","FNC 1","Code A","Code B","Code C","Stop","Reverse Stop"],r=[" ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","{","|","}","~","DEL","FNC 3","FNC 2","Shift A","Code C","FNC 4","Code A","FNC 1","Code A","Code B","Code C","Stop","Reverse Stop"],s=["00","01","02","03","04","05","06","07","08","09","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","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","Code B","Code A","FNC 1","Code A","Code B","Code C","Stop","Reverse Stop"];function c(n){const e=[];let t,c,i=r;const a=(n=>{const e=n.length-13,t=n.reduce((n,t,w)=>w>=e?n:n+t,0)/(11*Math.ceil(e/6));return n.map(n=>Math.round(n/t)||1)})(n);if(!a)return"";a.pop();for(let n=0;6*n<a.length-13;n+=1){t=a.slice(6*n,6*(n+1)).join("");const l=i[w.indexOf(t)];switch(l){case"Code A":i=o;break;case"Code B":i=r;break;case"Code C":i=s;break;case"FNC 4":break;default:l?("FNC 4"===c?e.push(l.charCodeAt(0)+128):e.push(l),c=l):e.push("?")}}return e.join("")}const i={nnnwwnwnn:"0",wnnwnnnnw:"1",nnwwnnnnw:"2",wnwwnnnnn:"3",nnnwwnnnw:"4",wnnwwnnnn:"5",nnwwwnnnn:"6",nnnwnnwnw:"7",wnnwnnwnn:"8",nnwwnnwnn:"9",wnnnnwnnw:"A",nnwnnwnnw:"B",wnwnnwnnn:"C",nnnnwwnnw:"D",wnnnwwnnn:"E",nnwnwwnnn:"F",nnnnnwwnw:"G",wnnnnwwnn:"H",nnwnnwwnn:"I",nnnnwwwnn:"J",wnnnnnnww:"K",nnwnnnnww:"L",wnwnnnnwn:"M",nnnnwnnww:"N",wnnnwnnwn:"O",nnwnwnnwn:"P",nnnnnnwww:"Q",wnnnnnwwn:"R",nnwnnnwwn:"S",nnnnwnwwn:"T",wwnnnnnnw:"U",nwwnnnnnw:"V",wwwnnnnnn:"W",nwnnwnnnw:"X",wwnnwnnnn:"Y",nwwnwnnnn:"Z",nwnnnnwnw:"-",wwnnnnwnn:".",nwwnnnwnn:" ",nwnwnwnnn:"$",nwnwnnnwn:"/",nwnnnwnwn:"+",nnnwnwnwn:"%",nwnnwnwnn:"*"};function a(n){const e=[],t=Math.ceil(n.reduce((n,e)=>n+e,0)/n.length);for(;n.length>0;){const w=n.splice(0,10).map(n=>n>t?"w":"n").slice(0,9).join("");e.push(i[w])}return"*"!==e.pop()||"*"!==e.shift()?"":e.join("")}const l=[{100010100:"0"},{101001e3:"1"},{101000100:"2"},{101000010:"3"},{100101e3:"4"},{100100100:"5"},{100100010:"6"},{10101e4:"7"},{100010010:"8"},{100001010:"9"},{110101e3:"A"},{110100100:"B"},{110100010:"C"},{110010100:"D"},{110010010:"E"},{110001010:"F"},{101101e3:"G"},{101100100:"H"},{101100010:"I"},{100110100:"J"},{100011010:"K"},{101011e3:"L"},{101001100:"M"},{101000110:"N"},{100101100:"O"},{100010110:"P"},{110110100:"Q"},{110110010:"R"},{110101100:"S"},{110100110:"T"},{110010110:"U"},{110011010:"V"},{101101100:"W"},{101100110:"X"},{100110110:"Y"},{100111010:"Z"},{100101110:"-"},{111010100:"."},{111010010:" "},{111001010:"$"},{101101110:"/"},{101110110:"+"},{110101110:"%"},{100100110:"($)"},{111011010:"(%)"},{111010110:"(/)"},{100110010:"(+)"},{101011110:"*"}];function h(n){const e=[],t=[];n.pop();const w=Math.ceil(n.reduce((n,e)=>n+e,0)/n.length),o=Math.ceil(n.reduce((n,e)=>e<w?(n+e)/2:n,0));for(let e=0;e<n.length;e+=1){let w=n[e];for(;w>0;)e%2==0?t.push(1):t.push(0),w-=o}for(let n=0;n<t.length;n+=9){const w=t.slice(n,n+9).join(""),o=l.filter(n=>Object.keys(n)[0]===w);e.push(o[0][w])}if("*"!==e.shift()||"*"!==e.pop())return"";const r=e.pop();let s,c,i=0;const a=n=>Object.values(n)[0]===s;for(let n=e.length-1;n>=0;n-=1)s=e[n],c=l.indexOf(l.filter(a)[0]),i+=c*(1+(e.length-(n+1))%20);if(Object.values(l[i%47])[0]!==r)return"";const h=e.pop();i=0;for(let n=e.length-1;n>=0;n-=1)s=e[n],c=l.indexOf(l.filter(a)[0]),i+=c*(1+(e.length-(n+1))%20);return Object.values(l[i%47])[0]!==h?"":e.join("")}const f=["nnwwn","wnnnw","nwnnw","wwnnn","nnwnw","wnwnn","nwwnn","nnnww","wnnwn","nwnwn"];function d(n,e){const t=[],w=Math.ceil(n.reduce((n,e)=>(n+e)/2,0));if("interleaved"===e){const e=n.splice(0,4).map(n=>n>w?"w":"n").join(""),o=n.splice(n.length-3,3).map(n=>n>w?"w":"n").join("");if("nnnn"!==e||"wnn"!==o)return"";for(;n.length>0;){const e=n.splice(0,10),o=e.filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join("");t.push(f.indexOf(o));const r=e.filter((n,e)=>e%2!=0).map(n=>n>w?"w":"n").join("");t.push(f.indexOf(r))}}else{const e=n.splice(0,6).filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join(""),o=n.splice(n.length-5,5).filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join("");if("wwn"!==e||"wnw"!==o)return"";for(;n.length>0;){const e=n.splice(0,10).filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join("");t.push(f.indexOf(e))}}return t.join("")}const p={3211:"0",2221:"1",2122:"2",1411:"3",1132:"4",1231:"5",1114:"6",1312:"7",1213:"8",3112:"9"};function u(n,e="13"){let t="";const w=(n[0]+n[1]+n[2])/3;n.shift(),n.shift(),n.shift(),n.pop(),n.pop(),n.pop(),"13"===e?n.splice(24,5):n.splice(16,5);for(let e=0;e<n.length;e+=4){const o=n.slice(e,e+4),r=[o[0]/w,o[1]/w,o[2]/w,o[3]/w].map(n=>1.5===n?1:Math.round(n)),s=p[r.join("")]||p[r.reverse().join("")];t+=s||"?"}return t}function C(n,e){if(""===n||""===e)return e;const t=n.split("");return e.split("").forEach((n,e)=>{t[e]&&"?"!==t[e]||n&&"?"!==n&&(t[e]=n)}),t.join("")}function g(n){const e=document.createElement("canvas"),t=e.getContext("2d");if(!t)throw new Error("Cannot create canvas 2d context");const w=n.naturalWidth,o=n.naturalHeight;return e.width=w,e.height=o,t.drawImage(n,0,0),t.getImageData(0,0,w,o)}const m="object"==typeof process&&process.release&&"node"===process.release.name;function E(n,e,t){const w=[],o=n.length/(e*t);let r=0,s=0;for(let c=0;c<e;c+=1){let i=0,a=0;for(let w=0;w<t;w+=1){const t=(w*e+c)*o;i+=Math.sqrt((n[t]**2+n[t+1]**2+n[t+2]**2)/3)}a=i/t>=127?255:0,255===a&&0===r||(a===s?r+=1:(w.push(r),s=a,r=1),c===e-1&&0===a&&w.push(r))}return w}const b=process&&"test"===process.env.NODE_ENV;var j;async function S({image:e,barcode:w,barcodeType:o,options:r}){let s;switch(w){case j.codabar:s=t;break;case j["code-128"]:s=c;break;case j["code-39"]:s=a;break;case j["code-93"]:s=h;break;case j["code-2of5"]:s=d;break;case j["ean-13"]:s=u,o="13";break;case j["ean-8"]:s=u,o="8";break;default:throw new Error(`Invalid barcode specified. Available decoders: ${j}.`)}const i=b||r&&r.singlePass||!1,{data:l,width:f,height:p}=(S=e).data&&S.width&&S.height?e:await async function(e){return new Promise((t,w)=>{if("string"==typeof e)if(e.startsWith("#")){const n=document.getElementById(e.substr(1));if(n instanceof HTMLImageElement&&t(g(n)),n instanceof HTMLCanvasElement){const e=n.getContext("2d");if(!e)throw new Error("Cannot create canvas 2d context");t(e.getImageData(0,0,n.width,n.height))}w(new Error("Invalid image source specified!"))}else if(!(o=e).startsWith("#")&&/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(o)){const n=new Image;n.onerror=w,n.onload=()=>t(g(n)),n.src=e}else m&&n(e,(n,e)=>{if(n)w(n);else{const{data:n,width:w,height:o}=e.bitmap;t({data:Uint8ClampedArray.from(n),width:w,height:o})}});else if(e instanceof HTMLImageElement)t(g(e));else if(e instanceof HTMLCanvasElement){const n=e.getContext("2d");if(!n)throw new Error("Cannot create canvas 2d context");t(n.getImageData(0,0,e.width,e.height))}var o})}(e);var S;const v=l.length/(f*p);let M="";r&&r.useAdaptiveThreshold&&function(n,e,t){const w=new Array(e*t).fill(0),o=n.length/(e*t),r=Math.floor(t),s=Math.floor(r/2);for(let r=0;r<e;r+=1){let s=0;for(let c=0;c<t;c+=1){const t=c*e+r,i=t*o,a=(n[i]+n[i+1]+n[i+2])/3;n[i]=a,n[i+1]=a,n[i+2]=a,s+=a,w[t]=0===r?s:w[t-1]+s}}for(let r=0;r<e;r+=1)for(let c=0;c<t;c+=1){const i=(c*e+r)*o;let a=r-s,l=r+s,h=c-s,f=c+s;a<0&&(a=0),l>=e&&(l=e-1),h<0&&(h=0),f>=t&&(f=t-1);const d=(l-a)*(f-h),p=w[f*e+l]-w[h*e+l]-w[f*e+a]+w[h*e+a];let u=255;n[i]*d<.85*p&&(u=0),n[i]=u,n[i+1]=u,n[i+2]=u}}(l,f,p);const N=[5,6,4,7,3,8,2,9,1],A=Math.round(p/N.length),F=Math.min(2,p);for(let n=0;n<N.length;n+=1){const e=v*f*Math.floor(A*N[n]),t=e+F*v*f,w=E(l.slice(e,t),f,F);if(0===w.length){if(i||n===N.length-1)throw new Error("Failed to detect lines in the image!");continue}const r=s(w,o);if(r){if(i||!r.includes("?"))return r;if(M=C(M,r),!M.includes("?"))return M}}return M}!function(n){n["code-128"]="code-128",n["code-2of5"]="code-2of5",n["code-39"]="code-39",n["code-93"]="code-93",n["ean-13"]="ean-13",n["ean-8"]="ean-8",n.codabar="codabar"}(j||(j={}));export{j as BARCODE_DECODERS,S as javascriptBarcodeReader};
import{read as n}from"jimp";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function e(n,e,t,w){return new(t||(t=Promise))((function(o,r){function c(n){try{s(w.next(n))}catch(n){r(n)}}function i(n){try{s(w.throw(n))}catch(n){r(n)}}function s(n){n.done?o(n.value):new t((function(e){e(n.value)})).then(c,i)}s((w=w.apply(n,e||[])).next())}))}const t={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 w(n){const e=[],w=Math.ceil(n.reduce((n,e)=>(n+e)/2,0));for(;n.length>0;){const o=n.splice(0,8).splice(0,7).map(n=>n<w?"n":"w").join("");e.push(t[o])}return e.join("")}const o=["212222","222122","222221","121223","121322","131222","122213","122312","132212","221213","221312","231212","112232","122132","122231","113222","123122","123221","223211","221132","221231","213212","223112","312131","311222","321122","321221","312212","322112","322211","212123","212321","232121","111323","131123","131321","112313","132113","132311","211313","231113","231311","112133","112331","132131","113123","113321","133121","313121","211331","231131","213113","213311","213131","311123","311321","331121","312113","312311","332111","314111","221411","431111","111224","111422","121124","121421","141122","141221","112214","112412","122114","122411","142112","142211","241211","221114","413111","241112","134111","111242","121142","121241","114212","124112","124211","411212","421112","421211","212141","214121","412121","111143","111341","131141","114113","114311","411113","411311","113141","114131","311141","411131","211412","211214","211232","233111","211133","2331112"],r=[" ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL","BS","HT","LF","VT","FF","CR","SO","SI","DLE","DC1","DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM","SUB","ESC","FS","GS","RS","US","FNC 3","FNC 2","Shift B","Code C","Code B","FNC 4","FNC 1","Code A","Code B","Code C","Stop","Reverse Stop"],c=[" ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","{","|","}","~","DEL","FNC 3","FNC 2","Shift A","Code C","FNC 4","Code A","FNC 1","Code A","Code B","Code C","Stop","Reverse Stop"],i=["00","01","02","03","04","05","06","07","08","09","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","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","Code B","Code A","FNC 1","Code A","Code B","Code C","Stop","Reverse Stop"];function s(n){const e=[];let t,w,s=c;const a=(n=>{const e=n.length-13,t=n.reduce((n,t,w)=>w>=e?n:n+t,0)/(11*Math.ceil(e/6));return n.map(n=>Math.round(n/t)||1)})(n);if(!a)return"";a.pop();for(let n=0;6*n<a.length-13;n+=1){t=a.slice(6*n,6*(n+1)).join("");const l=s[o.indexOf(t)];switch(l){case"Code A":s=r;break;case"Code B":s=c;break;case"Code C":s=i;break;case"FNC 4":break;default:l?("FNC 4"===w?e.push(l.charCodeAt(0)+128):e.push(l),w=l):e.push("?")}}return e.join("")}const a={nnnwwnwnn:"0",wnnwnnnnw:"1",nnwwnnnnw:"2",wnwwnnnnn:"3",nnnwwnnnw:"4",wnnwwnnnn:"5",nnwwwnnnn:"6",nnnwnnwnw:"7",wnnwnnwnn:"8",nnwwnnwnn:"9",wnnnnwnnw:"A",nnwnnwnnw:"B",wnwnnwnnn:"C",nnnnwwnnw:"D",wnnnwwnnn:"E",nnwnwwnnn:"F",nnnnnwwnw:"G",wnnnnwwnn:"H",nnwnnwwnn:"I",nnnnwwwnn:"J",wnnnnnnww:"K",nnwnnnnww:"L",wnwnnnnwn:"M",nnnnwnnww:"N",wnnnwnnwn:"O",nnwnwnnwn:"P",nnnnnnwww:"Q",wnnnnnwwn:"R",nnwnnnwwn:"S",nnnnwnwwn:"T",wwnnnnnnw:"U",nwwnnnnnw:"V",wwwnnnnnn:"W",nwnnwnnnw:"X",wwnnwnnnn:"Y",nwwnwnnnn:"Z",nwnnnnwnw:"-",wwnnnnwnn:".",nwwnnnwnn:" ",nwnwnwnnn:"$",nwnwnnnwn:"/",nwnnnwnwn:"+",nnnwnwnwn:"%",nwnnwnwnn:"*"};function l(n){const e=[],t=Math.ceil(n.reduce((n,e)=>n+e,0)/n.length);for(;n.length>0;){const w=n.splice(0,10).map(n=>n>t?"w":"n").slice(0,9).join("");e.push(a[w])}return"*"!==e.pop()||"*"!==e.shift()?"":e.join("")}const h=[{100010100:"0"},{101001e3:"1"},{101000100:"2"},{101000010:"3"},{100101e3:"4"},{100100100:"5"},{100100010:"6"},{10101e4:"7"},{100010010:"8"},{100001010:"9"},{110101e3:"A"},{110100100:"B"},{110100010:"C"},{110010100:"D"},{110010010:"E"},{110001010:"F"},{101101e3:"G"},{101100100:"H"},{101100010:"I"},{100110100:"J"},{100011010:"K"},{101011e3:"L"},{101001100:"M"},{101000110:"N"},{100101100:"O"},{100010110:"P"},{110110100:"Q"},{110110010:"R"},{110101100:"S"},{110100110:"T"},{110010110:"U"},{110011010:"V"},{101101100:"W"},{101100110:"X"},{100110110:"Y"},{100111010:"Z"},{100101110:"-"},{111010100:"."},{111010010:" "},{111001010:"$"},{101101110:"/"},{101110110:"+"},{110101110:"%"},{100100110:"($)"},{111011010:"(%)"},{111010110:"(/)"},{100110010:"(+)"},{101011110:"*"}];function f(n){const e=[],t=[];n.pop();const w=Math.ceil(n.reduce((n,e)=>n+e,0)/n.length),o=Math.ceil(n.reduce((n,e)=>e<w?(n+e)/2:n,0));for(let e=0;e<n.length;e+=1){let w=n[e];for(;w>0;)e%2==0?t.push(1):t.push(0),w-=o}for(let n=0;n<t.length;n+=9){const w=t.slice(n,n+9).join(""),o=h.filter(n=>Object.keys(n)[0]===w);e.push(o[0][w])}if("*"!==e.shift()||"*"!==e.pop())return"";const r=e.pop();let c,i,s=0;const a=n=>Object.values(n)[0]===c;for(let n=e.length-1;n>=0;n-=1)c=e[n],i=h.indexOf(h.filter(a)[0]),s+=i*(1+(e.length-(n+1))%20);if(Object.values(h[s%47])[0]!==r)return"";const l=e.pop();s=0;for(let n=e.length-1;n>=0;n-=1)c=e[n],i=h.indexOf(h.filter(a)[0]),s+=i*(1+(e.length-(n+1))%20);return Object.values(h[s%47])[0]!==l?"":e.join("")}const d=["nnwwn","wnnnw","nwnnw","wwnnn","nnwnw","wnwnn","nwwnn","nnnww","wnnwn","nwnwn"];function p(n,e){const t=[],w=Math.ceil(n.reduce((n,e)=>(n+e)/2,0));if("interleaved"===e){const e=n.splice(0,4).map(n=>n>w?"w":"n").join(""),o=n.splice(n.length-3,3).map(n=>n>w?"w":"n").join("");if("nnnn"!==e||"wnn"!==o)return"";for(;n.length>0;){const e=n.splice(0,10),o=e.filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join("");t.push(d.indexOf(o));const r=e.filter((n,e)=>e%2!=0).map(n=>n>w?"w":"n").join("");t.push(d.indexOf(r))}}else{const e=n.splice(0,6).filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join(""),o=n.splice(n.length-5,5).filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join("");if("wwn"!==e||"wnw"!==o)return"";for(;n.length>0;){const e=n.splice(0,10).filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join("");t.push(d.indexOf(e))}}return t.join("")}const u={3211:"0",2221:"1",2122:"2",1411:"3",1132:"4",1231:"5",1114:"6",1312:"7",1213:"8",3112:"9"};function C(n,e="13"){let t="";const w=(n[0]+n[1]+n[2])/3;n.shift(),n.shift(),n.shift(),n.pop(),n.pop(),n.pop(),"13"===e?n.splice(24,5):n.splice(16,5);for(let e=0;e<n.length;e+=4){const o=n.slice(e,e+4),r=[o[0]/w,o[1]/w,o[2]/w,o[3]/w].map(n=>1.5===n?1:Math.round(n)),c=u[r.join("")]||u[r.reverse().join("")];t+=c||"?"}return t}function g(n,e){if(""===n||""===e)return e;const t=n.split("");return e.split("").forEach((n,e)=>{t[e]&&"?"!==t[e]||n&&"?"!==n&&(t[e]=n)}),t.join("")}function m(n){const e=document.createElement("canvas"),t=e.getContext("2d");if(!t)throw new Error("Cannot create canvas 2d context");const w=n.naturalWidth,o=n.naturalHeight;return e.width=w,e.height=o,t.drawImage(n,0,0),t.getImageData(0,0,w,o)}const v="object"==typeof process&&process.release&&"node"===process.release.name;function E(n,e,t){const w=[],o=n.length/(e*t);let r=0,c=0;for(let i=0;i<e;i+=1){let s=0,a=0;for(let w=0;w<t;w+=1){const t=(w*e+i)*o;s+=Math.sqrt((Math.pow(n[t],2)+Math.pow(n[t+1],2)+Math.pow(n[t+2],2))/3)}a=s/t>=127?255:0,255===a&&0===r||(a===c?r+=1:(w.push(r),c=a,r=1),i===e-1&&0===a&&w.push(r))}return w}const b=process&&"test"===process.env.NODE_ENV;var j;function M({image:t,barcode:o,barcodeType:r,options:c}){return e(this,void 0,void 0,(function*(){let i;switch(o){case j.codabar:i=w;break;case j["code-128"]:i=s;break;case j["code-39"]:i=l;break;case j["code-93"]:i=f;break;case j["code-2of5"]:i=p;break;case j["ean-13"]:i=C,r="13";break;case j["ean-8"]:i=C,r="8";break;default:throw new Error(`Invalid barcode specified. Available decoders: ${j}.`)}const a=b||c&&c.singlePass||!1,{data:h,width:d,height:u}=(M=t).data&&M.width&&M.height?t:yield function(t){return e(this,void 0,void 0,(function*(){return new Promise((e,w)=>{if("string"==typeof t)if(t.startsWith("#")){const n=document.getElementById(t.substr(1));if(n instanceof HTMLImageElement&&e(m(n)),n instanceof HTMLCanvasElement){const t=n.getContext("2d");if(!t)throw new Error("Cannot create canvas 2d context");e(t.getImageData(0,0,n.width,n.height))}w(new Error("Invalid image source specified!"))}else if(!(o=t).startsWith("#")&&/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(o)){const n=new Image;n.onerror=w,n.onload=()=>e(m(n)),n.src=t}else v&&n(t,(n,t)=>{if(n)w(n);else{const{data:n,width:w,height:o}=t.bitmap;e({data:Uint8ClampedArray.from(n),width:w,height:o})}});else if(t instanceof HTMLImageElement)e(m(t));else if(t instanceof HTMLCanvasElement){const n=t.getContext("2d");if(!n)throw new Error("Cannot create canvas 2d context");e(n.getImageData(0,0,t.width,t.height))}var o})}))}(t);var M;const S=h.length/(d*u);let N="";c&&c.useAdaptiveThreshold&&function(n,e,t){const w=new Array(e*t).fill(0),o=n.length/(e*t),r=Math.floor(t),c=Math.floor(r/2);for(let r=0;r<e;r+=1){let c=0;for(let i=0;i<t;i+=1){const t=i*e+r,s=t*o,a=(n[s]+n[s+1]+n[s+2])/3;n[s]=a,n[s+1]=a,n[s+2]=a,c+=a,w[t]=0===r?c:w[t-1]+c}}for(let r=0;r<e;r+=1)for(let i=0;i<t;i+=1){const s=(i*e+r)*o;let a=r-c,l=r+c,h=i-c,f=i+c;a<0&&(a=0),l>=e&&(l=e-1),h<0&&(h=0),f>=t&&(f=t-1);const d=(l-a)*(f-h),p=w[f*e+l]-w[h*e+l]-w[f*e+a]+w[h*e+a];let u=255;n[s]*d<.85*p&&(u=0),n[s]=u,n[s+1]=u,n[s+2]=u}}(h,d,u);const A=[5,6,4,7,3,8,2,9,1],F=Math.round(u/A.length),O=Math.min(2,u);for(let n=0;n<A.length;n+=1){const e=S*d*Math.floor(F*A[n]),t=e+O*S*d,w=E(h.slice(e,t),d,O);if(0===w.length){if(a||n===A.length-1)throw new Error("Failed to detect lines in the image!");continue}const o=i(w,r);if(o){if(a||!o.includes("?"))return o;if(N=g(N,o),!N.includes("?"))return N}}return N}))}!function(n){n["code-128"]="code-128",n["code-2of5"]="code-2of5",n["code-39"]="code-39",n["code-93"]="code-93",n["ean-13"]="ean-13",n["ean-8"]="ean-8",n.codabar="codabar"}(j||(j={}));export{j as BARCODE_DECODERS,M as javascriptBarcodeReader};
//# sourceMappingURL=javascript-barcode-reader.es5.min.js.map
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('jimp')) :
typeof define === 'function' && define.amd ? define(['exports', 'jimp'], factory) :
(global = global || self, factory(global.javascriptBarcodeReader = {}, global.Jimp));
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('jimp')) :
typeof define === 'function' && define.amd ? define(['exports', 'jimp'], factory) :
(global = global || self, factory(global.javascriptBarcodeReader = {}, global.Jimp));
}(this, (function (exports, Jimp) { 'use strict';
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('');
}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
const WIDTH_TBL = [
'212222',
'222122',
'222221',
'121223',
'121322',
'131222',
'122213',
'122312',
'132212',
'221213',
'221312',
'231212',
'112232',
'122132',
'122231',
'113222',
'123122',
'123221',
'223211',
'221132',
'221231',
'213212',
'223112',
'312131',
'311222',
'321122',
'321221',
'312212',
'322112',
'322211',
'212123',
'212321',
'232121',
'111323',
'131123',
'131321',
'112313',
'132113',
'132311',
'211313',
'231113',
'231311',
'112133',
'112331',
'132131',
'113123',
'113321',
'133121',
'313121',
'211331',
'231131',
'213113',
'213311',
'213131',
'311123',
'311321',
'331121',
'312113',
'312311',
'332111',
'314111',
'221411',
'431111',
'111224',
'111422',
'121124',
'121421',
'141122',
'141221',
'112214',
'112412',
'122114',
'122411',
'142112',
'142211',
'241211',
'221114',
'413111',
'241112',
'134111',
'111242',
'121142',
'121241',
'114212',
'124112',
'124211',
'411212',
'421112',
'421211',
'212141',
'214121',
'412121',
'111143',
'111341',
'131141',
'114113',
'114311',
'411113',
'411311',
'113141',
'114131',
'311141',
'411131',
'211412',
'211214',
'211232',
'233111',
'211133',
'2331112',
];
const TBL_A = [
' ',
'!',
'"',
'#',
'$',
'%',
'&',
"'",
'(',
')',
'*',
'+',
',',
'-',
'.',
'/',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
':',
';',
'<',
'=',
'>',
'?',
'@',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'[',
'\\',
']',
'^',
'_',
'NUL',
'SOH',
'STX',
'ETX',
'EOT',
'ENQ',
'ACK',
'BEL',
'BS',
'HT',
'LF',
'VT',
'FF',
'CR',
'SO',
'SI',
'DLE',
'DC1',
'DC2',
'DC3',
'DC4',
'NAK',
'SYN',
'ETB',
'CAN',
'EM',
'SUB',
'ESC',
'FS',
'GS',
'RS',
'US',
'FNC 3',
'FNC 2',
'Shift B',
'Code C',
'Code B',
'FNC 4',
'FNC 1',
'Code A',
'Code B',
'Code C',
'Stop',
'Reverse Stop',
];
const TBL_B = [
' ',
'!',
'"',
'#',
'$',
'%',
'&',
"'",
'(',
')',
'*',
'+',
',',
'-',
'.',
'/',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
':',
';',
'<',
'=',
'>',
'?',
'@',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'[',
'\\',
']',
'^',
'_',
'`',
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'{',
'|',
'}',
'~',
'DEL',
'FNC 3',
'FNC 2',
'Shift A',
'Code C',
'FNC 4',
'Code A',
'FNC 1',
'Code A',
'Code B',
'Code C',
'Stop',
'Reverse Stop',
];
const TBL_C = [
'00',
'01',
'02',
'03',
'04',
'05',
'06',
'07',
'08',
'09',
'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',
'35',
'36',
'37',
'38',
'39',
'40',
'41',
'42',
'43',
'44',
'45',
'46',
'47',
'48',
'49',
'50',
'51',
'52',
'53',
'54',
'55',
'56',
'57',
'58',
'59',
'60',
'61',
'62',
'63',
'64',
'65',
'66',
'67',
'68',
'69',
'70',
'71',
'72',
'73',
'74',
'75',
'76',
'77',
'78',
'79',
'80',
'81',
'82',
'83',
'84',
'85',
'86',
'87',
'88',
'89',
'90',
'91',
'92',
'93',
'94',
'95',
'96',
'97',
'98',
'99',
'Code B',
'Code A',
'FNC 1',
'Code A',
'Code B',
'Code C',
'Stop',
'Reverse Stop',
];
const computeGroup = (lines) => {
const count = lines.length - 13;
const factor = lines.reduce((pre, item, i) => {
if (i >= count)
return pre;
return pre + item;
}, 0) /
(Math.ceil(count / 6) * 11);
return lines.map(item => Math.round(item / factor) || 1);
};
function decoder$1(lines) {
const code = [];
let lookupTBL = TBL_B;
// let sumOP = 0
let letterKey;
let letterCodePrev;
const computedLines = computeGroup(lines);
if (!computedLines)
return '';
// extract terminal bar
computedLines.pop();
// skip check code and stop code using -13
for (let i = 0; i * 6 < computedLines.length - 13; i += 1) {
letterKey = computedLines.slice(i * 6, (i + 1) * 6).join('');
const keyIndex = WIDTH_TBL.indexOf(letterKey);
const letterCode = lookupTBL[keyIndex];
// sumOP += i * keyIndex
switch (letterCode) {
case 'Code A':
lookupTBL = TBL_A;
break;
case 'Code B':
lookupTBL = TBL_B;
break;
case 'Code C':
lookupTBL = TBL_C;
break;
case 'FNC 4':
break;
default:
if (letterCode) {
if (letterCodePrev === 'FNC 4') {
code.push(letterCode.charCodeAt(0) + 128);
}
else {
code.push(letterCode);
}
letterCodePrev = letterCode;
}
else {
code.push('?');
}
break;
}
}
// letterKey = computedLines.slice(0, 6).join('')
// if (sumOP % 103 !== WIDTH_TBL.indexOf(letterKey)) return ''
return code.join('');
}
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
const CHAR_SET$1 = {
nnnwwnwnn: '0',
wnnwnnnnw: '1',
nnwwnnnnw: '2',
wnwwnnnnn: '3',
nnnwwnnnw: '4',
wnnwwnnnn: '5',
nnwwwnnnn: '6',
nnnwnnwnw: '7',
wnnwnnwnn: '8',
nnwwnnwnn: '9',
wnnnnwnnw: 'A',
nnwnnwnnw: 'B',
wnwnnwnnn: 'C',
nnnnwwnnw: 'D',
wnnnwwnnn: 'E',
nnwnwwnnn: 'F',
nnnnnwwnw: 'G',
wnnnnwwnn: 'H',
nnwnnwwnn: 'I',
nnnnwwwnn: 'J',
wnnnnnnww: 'K',
nnwnnnnww: 'L',
wnwnnnnwn: 'M',
nnnnwnnww: 'N',
wnnnwnnwn: 'O',
nnwnwnnwn: 'P',
nnnnnnwww: 'Q',
wnnnnnwwn: 'R',
nnwnnnwwn: 'S',
nnnnwnwwn: 'T',
wwnnnnnnw: 'U',
nwwnnnnnw: 'V',
wwwnnnnnn: 'W',
nwnnwnnnw: 'X',
wwnnwnnnn: 'Y',
nwwnwnnnn: 'Z',
nwnnnnwnw: '-',
wwnnnnwnn: '.',
nwwnnnwnn: ' ',
nwnwnwnnn: '$',
nwnwnnnwn: '/',
nwnnnwnwn: '+',
nnnwnwnwn: '%',
nwnnwnwnn: '*',
};
function decoder$2(lines) {
const code = [];
const barThreshold = Math.ceil(lines.reduce((pre, item) => pre + item, 0) / lines.length);
// Read one encoded character at a time.
while (lines.length > 0) {
const sequenceBar = lines
.splice(0, 10)
.map(line => (line > barThreshold ? 'w' : 'n'))
.slice(0, 9)
.join('');
code.push(CHAR_SET$1[sequenceBar]);
}
if (code.pop() !== '*' || code.shift() !== '*')
return '';
return code.join('');
}
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
const CHAR_SET$2 = [
{ '100010100': '0' },
{ '101001000': '1' },
{ '101000100': '2' },
{ '101000010': '3' },
{ '100101000': '4' },
{ '100100100': '5' },
{ '100100010': '6' },
{ '101010000': '7' },
{ '100010010': '8' },
{ '100001010': '9' },
{ '110101000': 'A' },
{ '110100100': 'B' },
{ '110100010': 'C' },
{ '110010100': 'D' },
{ '110010010': 'E' },
{ '110001010': 'F' },
{ '101101000': 'G' },
{ '101100100': 'H' },
{ '101100010': 'I' },
{ '100110100': 'J' },
{ '100011010': 'K' },
{ '101011000': 'L' },
{ '101001100': 'M' },
{ '101000110': 'N' },
{ '100101100': 'O' },
{ '100010110': 'P' },
{ '110110100': 'Q' },
{ '110110010': 'R' },
{ '110101100': 'S' },
{ '110100110': 'T' },
{ '110010110': 'U' },
{ '110011010': 'V' },
{ '101101100': 'W' },
{ '101100110': 'X' },
{ '100110110': 'Y' },
{ '100111010': 'Z' },
{ '100101110': '-' },
{ '111010100': '.' },
{ '111010010': ' ' },
{ '111001010': '$' },
{ '101101110': '/' },
{ '101110110': '+' },
{ '110101110': '%' },
{ '100100110': '($)' },
{ '111011010': '(%)' },
{ '111010110': '(/)' },
{ '100110010': '(+)' },
{ '101011110': '*' },
];
function decoder$3(lines) {
const code = [];
const binary = [];
// remove termination bar
lines.pop();
const barThreshold = Math.ceil(lines.reduce((pre, item) => pre + item, 0) / lines.length);
const minBarWidth = Math.ceil(lines.reduce((pre, item) => {
if (item < barThreshold)
return (pre + item) / 2;
return pre;
}, 0));
// leave the padded *
for (let i = 0; i < lines.length; i += 1) {
let segment = lines[i];
while (segment > 0) {
if (i % 2 === 0) {
binary.push(1);
}
else {
binary.push(0);
}
segment -= minBarWidth;
}
}
for (let i = 0; i < binary.length; i += 9) {
const searcKey = binary.slice(i, i + 9).join('');
const char = CHAR_SET$2.filter(item => Object.keys(item)[0] === searcKey);
code.push(char[0][searcKey]);
}
if (code.shift() !== '*' || code.pop() !== '*')
return '';
const K = code.pop();
let sum = 0;
let letter;
let Value;
const findValue = (item) => Object.values(item)[0] === letter;
for (let i = code.length - 1; i >= 0; i -= 1) {
letter = code[i];
Value = CHAR_SET$2.indexOf(CHAR_SET$2.filter(findValue)[0]);
sum += Value * (1 + ((code.length - (i + 1)) % 20));
}
if (Object.values(CHAR_SET$2[sum % 47])[0] !== K)
return '';
const C = code.pop();
sum = 0;
for (let i = code.length - 1; i >= 0; i -= 1) {
letter = code[i];
Value = CHAR_SET$2.indexOf(CHAR_SET$2.filter(findValue)[0]);
sum += Value * (1 + ((code.length - (i + 1)) % 20));
}
if (Object.values(CHAR_SET$2[sum % 47])[0] !== C)
return '';
return code.join('');
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
const CHAR_SET$3 = [
'nnwwn',
'wnnnw',
'nwnnw',
'wwnnn',
'nnwnw',
'wnwnn',
'nwwnn',
'nnnww',
'wnnwn',
'nwnwn',
];
function decoder$4(lines, type) {
const code = [];
const barThreshold = Math.ceil(lines.reduce((pre, item) => (pre + item) / 2, 0));
if (type === 'interleaved') {
// extract start/ends pair
const startChar = lines
.splice(0, 4)
.map((line) => (line > barThreshold ? 'w' : 'n'))
.join('');
const endChar = lines
.splice(lines.length - 3, 3)
.map((line) => (line > barThreshold ? 'w' : 'n'))
.join('');
if (startChar !== 'nnnn' || endChar !== 'wnn')
return '';
// Read one encoded character at a time.
while (lines.length > 0) {
const seg = lines.splice(0, 10);
const a = seg
.filter((item, index) => index % 2 === 0)
.map(line => (line > barThreshold ? 'w' : 'n'))
.join('');
code.push(CHAR_SET$3.indexOf(a));
const b = seg
.filter((item, index) => index % 2 !== 0)
.map(line => (line > barThreshold ? 'w' : 'n'))
.join('');
code.push(CHAR_SET$3.indexOf(b));
}
}
else {
// extract start/ends pair
const startChar = lines
.splice(0, 6)
.filter((item, index) => index % 2 === 0)
.map((line) => (line > barThreshold ? 'w' : 'n'))
.join('');
const endChar = lines
.splice(lines.length - 5, 5)
.filter((item, index) => index % 2 === 0)
.map((line) => (line > barThreshold ? 'w' : 'n'))
.join('');
if (startChar !== 'wwn' || endChar !== 'wnw')
return '';
// Read one encoded character at a time.
while (lines.length > 0) {
const a = lines
.splice(0, 10)
.filter((item, index) => index % 2 === 0)
.map(line => (line > barThreshold ? 'w' : 'n'))
.join('');
code.push(CHAR_SET$3.indexOf(a));
}
}
return code.join('');
}
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('');
}
const UPC_SET = {
'3211': '0',
'2221': '1',
'2122': '2',
'1411': '3',
'1132': '4',
'1231': '5',
'1114': '6',
'1312': '7',
'1213': '8',
'3112': '9',
};
function decoder$5(lines, type = '13') {
let code = '';
// start indicator/reference lines
const bar = (lines[0] + lines[1] + lines[2]) / 3;
// remove start pattern
lines.shift();
lines.shift();
lines.shift();
// remove end pattern
lines.pop();
lines.pop();
lines.pop();
// remove middle check pattern
// remove middle check pattern
if (type === '13') {
lines.splice(24, 5);
}
else {
lines.splice(16, 5);
}
for (let i = 0; i < lines.length; i += 4) {
const group = lines.slice(i, i + 4);
const digits = [group[0] / bar, group[1] / bar, group[2] / bar, group[3] / bar].map(digit => digit === 1.5 ? 1 : Math.round(digit));
const result = UPC_SET[digits.join('')] || UPC_SET[digits.reverse().join('')];
if (result) {
code += result;
}
else {
code += '?';
}
}
return code;
}
const WIDTH_TBL = [
'212222',
'222122',
'222221',
'121223',
'121322',
'131222',
'122213',
'122312',
'132212',
'221213',
'221312',
'231212',
'112232',
'122132',
'122231',
'113222',
'123122',
'123221',
'223211',
'221132',
'221231',
'213212',
'223112',
'312131',
'311222',
'321122',
'321221',
'312212',
'322112',
'322211',
'212123',
'212321',
'232121',
'111323',
'131123',
'131321',
'112313',
'132113',
'132311',
'211313',
'231113',
'231311',
'112133',
'112331',
'132131',
'113123',
'113321',
'133121',
'313121',
'211331',
'231131',
'213113',
'213311',
'213131',
'311123',
'311321',
'331121',
'312113',
'312311',
'332111',
'314111',
'221411',
'431111',
'111224',
'111422',
'121124',
'121421',
'141122',
'141221',
'112214',
'112412',
'122114',
'122411',
'142112',
'142211',
'241211',
'221114',
'413111',
'241112',
'134111',
'111242',
'121142',
'121241',
'114212',
'124112',
'124211',
'411212',
'421112',
'421211',
'212141',
'214121',
'412121',
'111143',
'111341',
'131141',
'114113',
'114311',
'411113',
'411311',
'113141',
'114131',
'311141',
'411131',
'211412',
'211214',
'211232',
'233111',
'211133',
'2331112',
];
const TBL_A = [
' ',
'!',
'"',
'#',
'$',
'%',
'&',
"'",
'(',
')',
'*',
'+',
',',
'-',
'.',
'/',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
':',
';',
'<',
'=',
'>',
'?',
'@',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'[',
'\\',
']',
'^',
'_',
'NUL',
'SOH',
'STX',
'ETX',
'EOT',
'ENQ',
'ACK',
'BEL',
'BS',
'HT',
'LF',
'VT',
'FF',
'CR',
'SO',
'SI',
'DLE',
'DC1',
'DC2',
'DC3',
'DC4',
'NAK',
'SYN',
'ETB',
'CAN',
'EM',
'SUB',
'ESC',
'FS',
'GS',
'RS',
'US',
'FNC 3',
'FNC 2',
'Shift B',
'Code C',
'Code B',
'FNC 4',
'FNC 1',
'Code A',
'Code B',
'Code C',
'Stop',
'Reverse Stop',
];
const TBL_B = [
' ',
'!',
'"',
'#',
'$',
'%',
'&',
"'",
'(',
')',
'*',
'+',
',',
'-',
'.',
'/',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
':',
';',
'<',
'=',
'>',
'?',
'@',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'[',
'\\',
']',
'^',
'_',
'`',
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'{',
'|',
'}',
'~',
'DEL',
'FNC 3',
'FNC 2',
'Shift A',
'Code C',
'FNC 4',
'Code A',
'FNC 1',
'Code A',
'Code B',
'Code C',
'Stop',
'Reverse Stop',
];
const TBL_C = [
'00',
'01',
'02',
'03',
'04',
'05',
'06',
'07',
'08',
'09',
'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',
'35',
'36',
'37',
'38',
'39',
'40',
'41',
'42',
'43',
'44',
'45',
'46',
'47',
'48',
'49',
'50',
'51',
'52',
'53',
'54',
'55',
'56',
'57',
'58',
'59',
'60',
'61',
'62',
'63',
'64',
'65',
'66',
'67',
'68',
'69',
'70',
'71',
'72',
'73',
'74',
'75',
'76',
'77',
'78',
'79',
'80',
'81',
'82',
'83',
'84',
'85',
'86',
'87',
'88',
'89',
'90',
'91',
'92',
'93',
'94',
'95',
'96',
'97',
'98',
'99',
'Code B',
'Code A',
'FNC 1',
'Code A',
'Code B',
'Code C',
'Stop',
'Reverse Stop',
];
const computeGroup = (lines) => {
const count = lines.length - 13;
const factor = lines.reduce((pre, item, i) => {
if (i >= count)
return pre;
return pre + item;
}, 0) /
(Math.ceil(count / 6) * 11);
return lines.map(item => Math.round(item / factor) || 1);
};
function decoder$1(lines) {
const code = [];
let lookupTBL = TBL_B;
// let sumOP = 0
let letterKey;
let letterCodePrev;
const computedLines = computeGroup(lines);
if (!computedLines)
return '';
// extract terminal bar
computedLines.pop();
// skip check code and stop code using -13
for (let i = 0; i * 6 < computedLines.length - 13; i += 1) {
letterKey = computedLines.slice(i * 6, (i + 1) * 6).join('');
const keyIndex = WIDTH_TBL.indexOf(letterKey);
const letterCode = lookupTBL[keyIndex];
// sumOP += i * keyIndex
switch (letterCode) {
case 'Code A':
lookupTBL = TBL_A;
break;
case 'Code B':
lookupTBL = TBL_B;
break;
case 'Code C':
lookupTBL = TBL_C;
break;
case 'FNC 4':
break;
default:
if (letterCode) {
if (letterCodePrev === 'FNC 4') {
code.push(letterCode.charCodeAt(0) + 128);
}
else {
code.push(letterCode);
}
letterCodePrev = letterCode;
}
else {
code.push('?');
}
break;
}
}
// letterKey = computedLines.slice(0, 6).join('')
// if (sumOP % 103 !== WIDTH_TBL.indexOf(letterKey)) return ''
return code.join('');
}
function applyAdaptiveThreshold(data, width, height) {
const integralImage = new Array(width * height).fill(0);
const channels = data.length / (width * height);
const t = 0.15; // threshold percentage
const s = Math.floor(height); // bracket size
const s2 = Math.floor(s / 2);
for (let i = 0; i < width; i += 1) {
let sum = 0;
for (let j = 0; j < height; j += 1) {
const pureIndex = j * width + i;
const index = pureIndex * channels;
// greyscale
const v = (data[index] + data[index + 1] + data[index + 2]) / 3;
data[index] = v;
data[index + 1] = v;
data[index + 2] = v;
sum += v;
if (i === 0) {
integralImage[pureIndex] = sum;
}
else {
integralImage[pureIndex] = integralImage[pureIndex - 1] + sum;
}
}
}
// skip edge rows
for (let i = 0; i < width; i += 1) {
for (let j = 0; j < height; j += 1) {
const pureIndex = j * width + i;
const index = pureIndex * channels;
// no. of pixels per window
let x1 = i - s2;
let x2 = i + s2;
let y1 = j - s2;
let y2 = j + s2;
if (x1 < 0)
x1 = 0;
if (x2 >= width)
x2 = width - 1;
if (y1 < 0)
y1 = 0;
if (y2 >= height)
y2 = height - 1;
const count = (x2 - x1) * (y2 - y1);
const sum = integralImage[y2 * width + x2] -
integralImage[y1 * width + x2] -
integralImage[y2 * width + x1] +
integralImage[y1 * width + x1];
let v = 255;
if (data[index] * count < sum * (1 - t)) {
v = 0;
}
data[index] = v;
data[index + 1] = v;
data[index + 2] = v;
}
}
return data;
}
const CHAR_SET$1 = {
nnnwwnwnn: '0',
wnnwnnnnw: '1',
nnwwnnnnw: '2',
wnwwnnnnn: '3',
nnnwwnnnw: '4',
wnnwwnnnn: '5',
nnwwwnnnn: '6',
nnnwnnwnw: '7',
wnnwnnwnn: '8',
nnwwnnwnn: '9',
wnnnnwnnw: 'A',
nnwnnwnnw: 'B',
wnwnnwnnn: 'C',
nnnnwwnnw: 'D',
wnnnwwnnn: 'E',
nnwnwwnnn: 'F',
nnnnnwwnw: 'G',
wnnnnwwnn: 'H',
nnwnnwwnn: 'I',
nnnnwwwnn: 'J',
wnnnnnnww: 'K',
nnwnnnnww: 'L',
wnwnnnnwn: 'M',
nnnnwnnww: 'N',
wnnnwnnwn: 'O',
nnwnwnnwn: 'P',
nnnnnnwww: 'Q',
wnnnnnwwn: 'R',
nnwnnnwwn: 'S',
nnnnwnwwn: 'T',
wwnnnnnnw: 'U',
nwwnnnnnw: 'V',
wwwnnnnnn: 'W',
nwnnwnnnw: 'X',
wwnnwnnnn: 'Y',
nwwnwnnnn: 'Z',
nwnnnnwnw: '-',
wwnnnnwnn: '.',
nwwnnnwnn: ' ',
nwnwnwnnn: '$',
nwnwnnnwn: '/',
nwnnnwnwn: '+',
nnnwnwnwn: '%',
nwnnwnwnn: '*',
};
function decoder$2(lines) {
const code = [];
const barThreshold = Math.ceil(lines.reduce((pre, item) => pre + item, 0) / lines.length);
// Read one encoded character at a time.
while (lines.length > 0) {
const sequenceBar = lines
.splice(0, 10)
.map(line => (line > barThreshold ? 'w' : 'n'))
.slice(0, 9)
.join('');
code.push(CHAR_SET$1[sequenceBar]);
}
if (code.pop() !== '*' || code.shift() !== '*')
return '';
return code.join('');
}
function combineAllPossible(finalResult, result) {
if (finalResult === '' || result === '') {
return result;
}
const finalResultArr = finalResult.split('');
const resultArr = result.split('');
resultArr.forEach((char, index) => {
if (!finalResultArr[index] || finalResultArr[index] === '?') {
if (char && char !== '?') {
finalResultArr[index] = char;
}
}
});
return finalResultArr.join('');
}
const CHAR_SET$2 = [
{ '100010100': '0' },
{ '101001000': '1' },
{ '101000100': '2' },
{ '101000010': '3' },
{ '100101000': '4' },
{ '100100100': '5' },
{ '100100010': '6' },
{ '101010000': '7' },
{ '100010010': '8' },
{ '100001010': '9' },
{ '110101000': 'A' },
{ '110100100': 'B' },
{ '110100010': 'C' },
{ '110010100': 'D' },
{ '110010010': 'E' },
{ '110001010': 'F' },
{ '101101000': 'G' },
{ '101100100': 'H' },
{ '101100010': 'I' },
{ '100110100': 'J' },
{ '100011010': 'K' },
{ '101011000': 'L' },
{ '101001100': 'M' },
{ '101000110': 'N' },
{ '100101100': 'O' },
{ '100010110': 'P' },
{ '110110100': 'Q' },
{ '110110010': 'R' },
{ '110101100': 'S' },
{ '110100110': 'T' },
{ '110010110': 'U' },
{ '110011010': 'V' },
{ '101101100': 'W' },
{ '101100110': 'X' },
{ '100110110': 'Y' },
{ '100111010': 'Z' },
{ '100101110': '-' },
{ '111010100': '.' },
{ '111010010': ' ' },
{ '111001010': '$' },
{ '101101110': '/' },
{ '101110110': '+' },
{ '110101110': '%' },
{ '100100110': '($)' },
{ '111011010': '(%)' },
{ '111010110': '(/)' },
{ '100110010': '(+)' },
{ '101011110': '*' },
];
function decoder$3(lines) {
const code = [];
const binary = [];
// remove termination bar
lines.pop();
const barThreshold = Math.ceil(lines.reduce((pre, item) => pre + item, 0) / lines.length);
const minBarWidth = Math.ceil(lines.reduce((pre, item) => {
if (item < barThreshold)
return (pre + item) / 2;
return pre;
}, 0));
// leave the padded *
for (let i = 0; i < lines.length; i += 1) {
let segment = lines[i];
while (segment > 0) {
if (i % 2 === 0) {
binary.push(1);
}
else {
binary.push(0);
}
segment -= minBarWidth;
}
}
for (let i = 0; i < binary.length; i += 9) {
const searcKey = binary.slice(i, i + 9).join('');
const char = CHAR_SET$2.filter(item => Object.keys(item)[0] === searcKey);
code.push(char[0][searcKey]);
}
if (code.shift() !== '*' || code.pop() !== '*')
return '';
const K = code.pop();
let sum = 0;
let letter;
let Value;
const findValue = (item) => Object.values(item)[0] === letter;
for (let i = code.length - 1; i >= 0; i -= 1) {
letter = code[i];
Value = CHAR_SET$2.indexOf(CHAR_SET$2.filter(findValue)[0]);
sum += Value * (1 + ((code.length - (i + 1)) % 20));
}
if (Object.values(CHAR_SET$2[sum % 47])[0] !== K)
return '';
const C = code.pop();
sum = 0;
for (let i = code.length - 1; i >= 0; i -= 1) {
letter = code[i];
Value = CHAR_SET$2.indexOf(CHAR_SET$2.filter(findValue)[0]);
sum += Value * (1 + ((code.length - (i + 1)) % 20));
}
if (Object.values(CHAR_SET$2[sum % 47])[0] !== C)
return '';
return code.join('');
}
function createImageData(image) {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
const width = image.naturalWidth;
const height = image.naturalHeight;
canvas.width = width;
canvas.height = height;
ctx.drawImage(image, 0, 0);
return ctx.getImageData(0, 0, width, height);
}
const CHAR_SET$3 = [
'nnwwn',
'wnnnw',
'nwnnw',
'wwnnn',
'nnwnw',
'wnwnn',
'nwwnn',
'nnnww',
'wnnwn',
'nwnwn',
];
function decoder$4(lines, type) {
const code = [];
const barThreshold = Math.ceil(lines.reduce((pre, item) => (pre + item) / 2, 0));
if (type === 'interleaved') {
// extract start/ends pair
const startChar = lines
.splice(0, 4)
.map((line) => (line > barThreshold ? 'w' : 'n'))
.join('');
const endChar = lines
.splice(lines.length - 3, 3)
.map((line) => (line > barThreshold ? 'w' : 'n'))
.join('');
if (startChar !== 'nnnn' || endChar !== 'wnn')
return '';
// Read one encoded character at a time.
while (lines.length > 0) {
const seg = lines.splice(0, 10);
const a = seg
.filter((item, index) => index % 2 === 0)
.map(line => (line > barThreshold ? 'w' : 'n'))
.join('');
code.push(CHAR_SET$3.indexOf(a));
const b = seg
.filter((item, index) => index % 2 !== 0)
.map(line => (line > barThreshold ? 'w' : 'n'))
.join('');
code.push(CHAR_SET$3.indexOf(b));
}
}
else {
// extract start/ends pair
const startChar = lines
.splice(0, 6)
.filter((item, index) => index % 2 === 0)
.map((line) => (line > barThreshold ? 'w' : 'n'))
.join('');
const endChar = lines
.splice(lines.length - 5, 5)
.filter((item, index) => index % 2 === 0)
.map((line) => (line > barThreshold ? 'w' : 'n'))
.join('');
if (startChar !== 'wwn' || endChar !== 'wnw')
return '';
// Read one encoded character at a time.
while (lines.length > 0) {
const a = lines
.splice(0, 10)
.filter((item, index) => index % 2 === 0)
.map(line => (line > barThreshold ? 'w' : 'n'))
.join('');
code.push(CHAR_SET$3.indexOf(a));
}
}
return code.join('');
}
function isUrl(s) {
const regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/;
if (s.startsWith('#'))
return false;
return regexp.test(s);
}
const UPC_SET = {
'3211': '0',
'2221': '1',
'2122': '2',
'1411': '3',
'1132': '4',
'1231': '5',
'1114': '6',
'1312': '7',
'1213': '8',
'3112': '9',
};
function decoder$5(lines, type = '13') {
let code = '';
// start indicator/reference lines
const bar = (lines[0] + lines[1] + lines[2]) / 3;
// remove start pattern
lines.shift();
lines.shift();
lines.shift();
// remove end pattern
lines.pop();
lines.pop();
lines.pop();
// remove middle check pattern
// remove middle check pattern
if (type === '13') {
lines.splice(24, 5);
}
else {
lines.splice(16, 5);
}
for (let i = 0; i < lines.length; i += 4) {
const group = lines.slice(i, i + 4);
const digits = [group[0] / bar, group[1] / bar, group[2] / bar, group[3] / bar].map(digit => digit === 1.5 ? 1 : Math.round(digit));
const result = UPC_SET[digits.join('')] || UPC_SET[digits.reverse().join('')];
if (result) {
code += result;
}
else {
code += '?';
}
}
return code;
}
const isNode = typeof process === 'object' && process.release && process.release.name === 'node';
async function getImageDataFromSource(source) {
return new Promise((resolve, reject) => {
if (typeof source === 'string') {
if (source.startsWith('#')) {
const imageElement = document.getElementById(source.substr(1));
if (imageElement instanceof HTMLImageElement) {
resolve(createImageData(imageElement));
}
if (imageElement instanceof HTMLCanvasElement) {
const ctx = imageElement.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
resolve(ctx.getImageData(0, 0, imageElement.width, imageElement.height));
}
reject(new Error('Invalid image source specified!'));
}
else if (isUrl(source)) {
const img = new Image();
img.onerror = reject;
img.onload = () => resolve(createImageData(img));
img.src = source;
}
else if (isNode) {
Jimp.read(source, (err, image) => {
if (err) {
reject(err);
}
else {
const { data, width, height } = image.bitmap;
resolve({
data: Uint8ClampedArray.from(data),
width,
height,
});
}
});
}
}
else if (source instanceof HTMLImageElement) {
resolve(createImageData(source));
}
else if (source instanceof HTMLCanvasElement) {
const ctx = source.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
resolve(ctx.getImageData(0, 0, source.width, source.height));
}
});
}
function applyAdaptiveThreshold(data, width, height) {
const integralImage = new Array(width * height).fill(0);
const channels = data.length / (width * height);
const t = 0.15; // threshold percentage
const s = Math.floor(height); // bracket size
const s2 = Math.floor(s / 2);
for (let i = 0; i < width; i += 1) {
let sum = 0;
for (let j = 0; j < height; j += 1) {
const pureIndex = j * width + i;
const index = pureIndex * channels;
// greyscale
const v = (data[index] + data[index + 1] + data[index + 2]) / 3;
data[index] = v;
data[index + 1] = v;
data[index + 2] = v;
sum += v;
if (i === 0) {
integralImage[pureIndex] = sum;
}
else {
integralImage[pureIndex] = integralImage[pureIndex - 1] + sum;
}
}
}
// skip edge rows
for (let i = 0; i < width; i += 1) {
for (let j = 0; j < height; j += 1) {
const pureIndex = j * width + i;
const index = pureIndex * channels;
// no. of pixels per window
let x1 = i - s2;
let x2 = i + s2;
let y1 = j - s2;
let y2 = j + s2;
if (x1 < 0)
x1 = 0;
if (x2 >= width)
x2 = width - 1;
if (y1 < 0)
y1 = 0;
if (y2 >= height)
y2 = height - 1;
const count = (x2 - x1) * (y2 - y1);
const sum = integralImage[y2 * width + x2] -
integralImage[y1 * width + x2] -
integralImage[y2 * width + x1] +
integralImage[y1 * width + x1];
let v = 255;
if (data[index] * count < sum * (1 - t)) {
v = 0;
}
data[index] = v;
data[index + 1] = v;
data[index + 2] = v;
}
}
return data;
}
function getLines(data, width, height) {
const lines = [];
const channels = data.length / (width * height);
let count = 0;
let columnAverageLast = 0;
for (let column = 0; column < width; column += 1) {
let columnSum = 0;
let columnAverage = 0;
for (let row = 0; row < height; row += 1) {
const index = (row * width + column) * channels;
columnSum += Math.sqrt((data[index] ** 2 + data[index + 1] ** 2 + data[index + 2] ** 2) / 3);
}
// pixels are same in column
columnAverage = columnSum / height >= 127 ? 255 : 0;
// skip white padding in the start & end
if (columnAverage === 255 && count === 0)
continue;
// count line width
if (columnAverage === columnAverageLast) {
count += 1;
}
else {
lines.push(count);
columnAverageLast = columnAverage;
count = 1;
}
// skip padding in the last
if (column === width - 1 && columnAverage === 0) {
lines.push(count);
}
}
return lines;
}
function combineAllPossible(finalResult, result) {
if (finalResult === '' || result === '') {
return result;
}
const finalResultArr = finalResult.split('');
const resultArr = result.split('');
resultArr.forEach((char, index) => {
if (!finalResultArr[index] || finalResultArr[index] === '?') {
if (char && char !== '?') {
finalResultArr[index] = char;
}
}
});
return finalResultArr.join('');
}
// available decoders
const isTestEnv = process && process.env.NODE_ENV === 'test';
(function (BARCODE_DECODERS) {
BARCODE_DECODERS["code-128"] = "code-128";
BARCODE_DECODERS["code-2of5"] = "code-2of5";
BARCODE_DECODERS["code-39"] = "code-39";
BARCODE_DECODERS["code-93"] = "code-93";
BARCODE_DECODERS["ean-13"] = "ean-13";
BARCODE_DECODERS["ean-8"] = "ean-8";
BARCODE_DECODERS["codabar"] = "codabar";
})(exports.BARCODE_DECODERS || (exports.BARCODE_DECODERS = {}));
function isImageLike(object) {
return object.data && object.width && object.height;
}
async function javascriptBarcodeReader({ image, barcode, barcodeType, options, }) {
let decoder$6;
switch (barcode) {
case exports.BARCODE_DECODERS.codabar:
decoder$6 = decoder;
break;
case exports.BARCODE_DECODERS['code-128']:
decoder$6 = decoder$1;
break;
case exports.BARCODE_DECODERS['code-39']:
decoder$6 = decoder$2;
break;
case exports.BARCODE_DECODERS['code-93']:
decoder$6 = decoder$3;
break;
case exports.BARCODE_DECODERS['code-2of5']:
decoder$6 = decoder$4;
break;
case exports.BARCODE_DECODERS['ean-13']:
decoder$6 = decoder$5;
barcodeType = '13';
break;
case exports.BARCODE_DECODERS['ean-8']:
decoder$6 = decoder$5;
barcodeType = '8';
break;
default:
throw new Error(`Invalid barcode specified. Available decoders: ${exports.BARCODE_DECODERS}.`);
}
const useSinglePass = isTestEnv || (options && options.singlePass) || false;
const { data, width, height } = isImageLike(image) ? image : await getImageDataFromSource(image);
const channels = data.length / (width * height);
let finalResult = '';
// apply adaptive threshold
if (options && options.useAdaptiveThreshold) {
applyAdaptiveThreshold(data, width, height);
}
// check points for barcode location
const searchPoints = [5, 6, 4, 7, 3, 8, 2, 9, 1];
const searchLineStep = Math.round(height / searchPoints.length);
const rowsToScan = Math.min(2, height);
for (let i = 0; i < searchPoints.length; i += 1) {
const start = channels * width * Math.floor(searchLineStep * searchPoints[i]);
const end = start + rowsToScan * channels * width;
const lines = getLines(data.slice(start, end), width, rowsToScan);
if (lines.length === 0) {
if (useSinglePass || i === searchPoints.length - 1) {
throw new Error('Failed to detect lines in the image!');
}
continue;
}
// Run the decoder
const result = decoder$6(lines, barcodeType);
if (!result)
continue;
else if (useSinglePass || !result.includes('?'))
return result;
finalResult = combineAllPossible(finalResult, result);
if (!finalResult.includes('?'))
return finalResult;
}
return finalResult;
}
function createImageData(image) {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
const width = image.naturalWidth;
const height = image.naturalHeight;
canvas.width = width;
canvas.height = height;
ctx.drawImage(image, 0, 0);
return ctx.getImageData(0, 0, width, height);
}
exports.javascriptBarcodeReader = javascriptBarcodeReader;
function isUrl(s) {
const regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/;
if (s.startsWith('#'))
return false;
return regexp.test(s);
}
Object.defineProperty(exports, '__esModule', { value: true });
const isNode = typeof process === 'object' && process.release && process.release.name === 'node';
function getImageDataFromSource(source) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
if (typeof source === 'string') {
if (source.startsWith('#')) {
const imageElement = document.getElementById(source.substr(1));
if (imageElement instanceof HTMLImageElement) {
resolve(createImageData(imageElement));
}
if (imageElement instanceof HTMLCanvasElement) {
const ctx = imageElement.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
resolve(ctx.getImageData(0, 0, imageElement.width, imageElement.height));
}
reject(new Error('Invalid image source specified!'));
}
else if (isUrl(source)) {
const img = new Image();
img.onerror = reject;
img.onload = () => resolve(createImageData(img));
img.src = source;
}
else if (isNode) {
Jimp.read(source, (err, image) => {
if (err) {
reject(err);
}
else {
const { data, width, height } = image.bitmap;
resolve({
data: Uint8ClampedArray.from(data),
width,
height,
});
}
});
}
}
else if (source instanceof HTMLImageElement) {
resolve(createImageData(source));
}
else if (source instanceof HTMLCanvasElement) {
const ctx = source.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
resolve(ctx.getImageData(0, 0, source.width, source.height));
}
});
});
}
function getLines(data, width, height) {
const lines = [];
const channels = data.length / (width * height);
let count = 0;
let columnAverageLast = 0;
for (let column = 0; column < width; column += 1) {
let columnSum = 0;
let columnAverage = 0;
for (let row = 0; row < height; row += 1) {
const index = (row * width + column) * channels;
columnSum += Math.sqrt((Math.pow(data[index], 2) + Math.pow(data[index + 1], 2) + Math.pow(data[index + 2], 2)) / 3);
}
// pixels are same in column
columnAverage = columnSum / height >= 127 ? 255 : 0;
// skip white padding in the start & end
if (columnAverage === 255 && count === 0)
continue;
// count line width
if (columnAverage === columnAverageLast) {
count += 1;
}
else {
lines.push(count);
columnAverageLast = columnAverage;
count = 1;
}
// skip padding in the last
if (column === width - 1 && columnAverage === 0) {
lines.push(count);
}
}
return lines;
}
const isTestEnv = process && process.env.NODE_ENV === 'test';
(function (BARCODE_DECODERS) {
BARCODE_DECODERS["code-128"] = "code-128";
BARCODE_DECODERS["code-2of5"] = "code-2of5";
BARCODE_DECODERS["code-39"] = "code-39";
BARCODE_DECODERS["code-93"] = "code-93";
BARCODE_DECODERS["ean-13"] = "ean-13";
BARCODE_DECODERS["ean-8"] = "ean-8";
BARCODE_DECODERS["codabar"] = "codabar";
})(exports.BARCODE_DECODERS || (exports.BARCODE_DECODERS = {}));
function isImageLike(object) {
return object.data && object.width && object.height;
}
function javascriptBarcodeReader({ image, barcode, barcodeType, options, }) {
return __awaiter(this, void 0, void 0, function* () {
let decoder$6;
switch (barcode) {
case exports.BARCODE_DECODERS.codabar:
decoder$6 = decoder;
break;
case exports.BARCODE_DECODERS['code-128']:
decoder$6 = decoder$1;
break;
case exports.BARCODE_DECODERS['code-39']:
decoder$6 = decoder$2;
break;
case exports.BARCODE_DECODERS['code-93']:
decoder$6 = decoder$3;
break;
case exports.BARCODE_DECODERS['code-2of5']:
decoder$6 = decoder$4;
break;
case exports.BARCODE_DECODERS['ean-13']:
decoder$6 = decoder$5;
barcodeType = '13';
break;
case exports.BARCODE_DECODERS['ean-8']:
decoder$6 = decoder$5;
barcodeType = '8';
break;
default:
throw new Error(`Invalid barcode specified. Available decoders: ${exports.BARCODE_DECODERS}.`);
}
const useSinglePass = isTestEnv || (options && options.singlePass) || false;
const { data, width, height } = isImageLike(image) ? image : yield getImageDataFromSource(image);
const channels = data.length / (width * height);
let finalResult = '';
// apply adaptive threshold
if (options && options.useAdaptiveThreshold) {
applyAdaptiveThreshold(data, width, height);
}
// check points for barcode location
const searchPoints = [5, 6, 4, 7, 3, 8, 2, 9, 1];
const searchLineStep = Math.round(height / searchPoints.length);
const rowsToScan = Math.min(2, height);
for (let i = 0; i < searchPoints.length; i += 1) {
const start = channels * width * Math.floor(searchLineStep * searchPoints[i]);
const end = start + rowsToScan * channels * width;
const lines = getLines(data.slice(start, end), width, rowsToScan);
if (lines.length === 0) {
if (useSinglePass || i === searchPoints.length - 1) {
throw new Error('Failed to detect lines in the image!');
}
continue;
}
// Run the decoder
const result = decoder$6(lines, barcodeType);
if (!result)
continue;
else if (useSinglePass || !result.includes('?'))
return result;
finalResult = combineAllPossible(finalResult, result);
if (!finalResult.includes('?'))
return finalResult;
}
return finalResult;
});
}
exports.javascriptBarcodeReader = javascriptBarcodeReader;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=javascript-barcode-reader.umd.js.map

@@ -1,2 +0,16 @@

!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("jimp")):"function"==typeof define&&define.amd?define(["exports","jimp"],e):e((n=n||self).javascriptBarcodeReader={},n.Jimp)}(this,(function(n,e){"use strict";const t={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 w(n){const e=[],w=Math.ceil(n.reduce((n,e)=>(n+e)/2,0));for(;n.length>0;){const o=n.splice(0,8).splice(0,7).map(n=>n<w?"n":"w").join("");e.push(t[o])}return e.join("")}const o=["212222","222122","222221","121223","121322","131222","122213","122312","132212","221213","221312","231212","112232","122132","122231","113222","123122","123221","223211","221132","221231","213212","223112","312131","311222","321122","321221","312212","322112","322211","212123","212321","232121","111323","131123","131321","112313","132113","132311","211313","231113","231311","112133","112331","132131","113123","113321","133121","313121","211331","231131","213113","213311","213131","311123","311321","331121","312113","312311","332111","314111","221411","431111","111224","111422","121124","121421","141122","141221","112214","112412","122114","122411","142112","142211","241211","221114","413111","241112","134111","111242","121142","121241","114212","124112","124211","411212","421112","421211","212141","214121","412121","111143","111341","131141","114113","114311","411113","411311","113141","114131","311141","411131","211412","211214","211232","233111","211133","2331112"],r=[" ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL","BS","HT","LF","VT","FF","CR","SO","SI","DLE","DC1","DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM","SUB","ESC","FS","GS","RS","US","FNC 3","FNC 2","Shift B","Code C","Code B","FNC 4","FNC 1","Code A","Code B","Code C","Stop","Reverse Stop"],s=[" ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","{","|","}","~","DEL","FNC 3","FNC 2","Shift A","Code C","FNC 4","Code A","FNC 1","Code A","Code B","Code C","Stop","Reverse Stop"],c=["00","01","02","03","04","05","06","07","08","09","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","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","Code B","Code A","FNC 1","Code A","Code B","Code C","Stop","Reverse Stop"];function i(n){const e=[];let t,w,i=s;const a=(n=>{const e=n.length-13,t=n.reduce((n,t,w)=>w>=e?n:n+t,0)/(11*Math.ceil(e/6));return n.map(n=>Math.round(n/t)||1)})(n);if(!a)return"";a.pop();for(let n=0;6*n<a.length-13;n+=1){t=a.slice(6*n,6*(n+1)).join("");const l=i[o.indexOf(t)];switch(l){case"Code A":i=r;break;case"Code B":i=s;break;case"Code C":i=c;break;case"FNC 4":break;default:l?("FNC 4"===w?e.push(l.charCodeAt(0)+128):e.push(l),w=l):e.push("?")}}return e.join("")}const a={nnnwwnwnn:"0",wnnwnnnnw:"1",nnwwnnnnw:"2",wnwwnnnnn:"3",nnnwwnnnw:"4",wnnwwnnnn:"5",nnwwwnnnn:"6",nnnwnnwnw:"7",wnnwnnwnn:"8",nnwwnnwnn:"9",wnnnnwnnw:"A",nnwnnwnnw:"B",wnwnnwnnn:"C",nnnnwwnnw:"D",wnnnwwnnn:"E",nnwnwwnnn:"F",nnnnnwwnw:"G",wnnnnwwnn:"H",nnwnnwwnn:"I",nnnnwwwnn:"J",wnnnnnnww:"K",nnwnnnnww:"L",wnwnnnnwn:"M",nnnnwnnww:"N",wnnnwnnwn:"O",nnwnwnnwn:"P",nnnnnnwww:"Q",wnnnnnwwn:"R",nnwnnnwwn:"S",nnnnwnwwn:"T",wwnnnnnnw:"U",nwwnnnnnw:"V",wwwnnnnnn:"W",nwnnwnnnw:"X",wwnnwnnnn:"Y",nwwnwnnnn:"Z",nwnnnnwnw:"-",wwnnnnwnn:".",nwwnnnwnn:" ",nwnwnwnnn:"$",nwnwnnnwn:"/",nwnnnwnwn:"+",nnnwnwnwn:"%",nwnnwnwnn:"*"};function l(n){const e=[],t=Math.ceil(n.reduce((n,e)=>n+e,0)/n.length);for(;n.length>0;){const w=n.splice(0,10).map(n=>n>t?"w":"n").slice(0,9).join("");e.push(a[w])}return"*"!==e.pop()||"*"!==e.shift()?"":e.join("")}const d=[{100010100:"0"},{101001e3:"1"},{101000100:"2"},{101000010:"3"},{100101e3:"4"},{100100100:"5"},{100100010:"6"},{10101e4:"7"},{100010010:"8"},{100001010:"9"},{110101e3:"A"},{110100100:"B"},{110100010:"C"},{110010100:"D"},{110010010:"E"},{110001010:"F"},{101101e3:"G"},{101100100:"H"},{101100010:"I"},{100110100:"J"},{100011010:"K"},{101011e3:"L"},{101001100:"M"},{101000110:"N"},{100101100:"O"},{100010110:"P"},{110110100:"Q"},{110110010:"R"},{110101100:"S"},{110100110:"T"},{110010110:"U"},{110011010:"V"},{101101100:"W"},{101100110:"X"},{100110110:"Y"},{100111010:"Z"},{100101110:"-"},{111010100:"."},{111010010:" "},{111001010:"$"},{101101110:"/"},{101110110:"+"},{110101110:"%"},{100100110:"($)"},{111011010:"(%)"},{111010110:"(/)"},{100110010:"(+)"},{101011110:"*"}];function f(n){const e=[],t=[];n.pop();const w=Math.ceil(n.reduce((n,e)=>n+e,0)/n.length),o=Math.ceil(n.reduce((n,e)=>e<w?(n+e)/2:n,0));for(let e=0;e<n.length;e+=1){let w=n[e];for(;w>0;)e%2==0?t.push(1):t.push(0),w-=o}for(let n=0;n<t.length;n+=9){const w=t.slice(n,n+9).join(""),o=d.filter(n=>Object.keys(n)[0]===w);e.push(o[0][w])}if("*"!==e.shift()||"*"!==e.pop())return"";const r=e.pop();let s,c,i=0;const a=n=>Object.values(n)[0]===s;for(let n=e.length-1;n>=0;n-=1)s=e[n],c=d.indexOf(d.filter(a)[0]),i+=c*(1+(e.length-(n+1))%20);if(Object.values(d[i%47])[0]!==r)return"";const l=e.pop();i=0;for(let n=e.length-1;n>=0;n-=1)s=e[n],c=d.indexOf(d.filter(a)[0]),i+=c*(1+(e.length-(n+1))%20);return Object.values(d[i%47])[0]!==l?"":e.join("")}const h=["nnwwn","wnnnw","nwnnw","wwnnn","nnwnw","wnwnn","nwwnn","nnnww","wnnwn","nwnwn"];function p(n,e){const t=[],w=Math.ceil(n.reduce((n,e)=>(n+e)/2,0));if("interleaved"===e){const e=n.splice(0,4).map(n=>n>w?"w":"n").join(""),o=n.splice(n.length-3,3).map(n=>n>w?"w":"n").join("");if("nnnn"!==e||"wnn"!==o)return"";for(;n.length>0;){const e=n.splice(0,10),o=e.filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join("");t.push(h.indexOf(o));const r=e.filter((n,e)=>e%2!=0).map(n=>n>w?"w":"n").join("");t.push(h.indexOf(r))}}else{const e=n.splice(0,6).filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join(""),o=n.splice(n.length-5,5).filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join("");if("wwn"!==e||"wnw"!==o)return"";for(;n.length>0;){const e=n.splice(0,10).filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join("");t.push(h.indexOf(e))}}return t.join("")}const u={3211:"0",2221:"1",2122:"2",1411:"3",1132:"4",1231:"5",1114:"6",1312:"7",1213:"8",3112:"9"};function C(n,e="13"){let t="";const w=(n[0]+n[1]+n[2])/3;n.shift(),n.shift(),n.shift(),n.pop(),n.pop(),n.pop(),"13"===e?n.splice(24,5):n.splice(16,5);for(let e=0;e<n.length;e+=4){const o=n.slice(e,e+4),r=[o[0]/w,o[1]/w,o[2]/w,o[3]/w].map(n=>1.5===n?1:Math.round(n)),s=u[r.join("")]||u[r.reverse().join("")];t+=s||"?"}return t}function E(n,e){if(""===n||""===e)return e;const t=n.split("");return e.split("").forEach((n,e)=>{t[e]&&"?"!==t[e]||n&&"?"!==n&&(t[e]=n)}),t.join("")}function g(n){const e=document.createElement("canvas"),t=e.getContext("2d");if(!t)throw new Error("Cannot create canvas 2d context");const w=n.naturalWidth,o=n.naturalHeight;return e.width=w,e.height=o,t.drawImage(n,0,0),t.getImageData(0,0,w,o)}const D="object"==typeof process&&process.release&&"node"===process.release.name;function m(n,e,t){const w=[],o=n.length/(e*t);let r=0,s=0;for(let c=0;c<e;c+=1){let i=0,a=0;for(let w=0;w<t;w+=1){const t=(w*e+c)*o;i+=Math.sqrt((n[t]**2+n[t+1]**2+n[t+2]**2)/3)}a=i/t>=127?255:0,255===a&&0===r||(a===s?r+=1:(w.push(r),s=a,r=1),c===e-1&&0===a&&w.push(r))}return w}const O=process&&"test"===process.env.NODE_ENV;var S;(S=n.BARCODE_DECODERS||(n.BARCODE_DECODERS={}))["code-128"]="code-128",S["code-2of5"]="code-2of5",S["code-39"]="code-39",S["code-93"]="code-93",S["ean-13"]="ean-13",S["ean-8"]="ean-8",S.codabar="codabar",n.javascriptBarcodeReader=async function({image:t,barcode:o,barcodeType:r,options:s}){let c;switch(o){case n.BARCODE_DECODERS.codabar:c=w;break;case n.BARCODE_DECODERS["code-128"]:c=i;break;case n.BARCODE_DECODERS["code-39"]:c=l;break;case n.BARCODE_DECODERS["code-93"]:c=f;break;case n.BARCODE_DECODERS["code-2of5"]:c=p;break;case n.BARCODE_DECODERS["ean-13"]:c=C,r="13";break;case n.BARCODE_DECODERS["ean-8"]:c=C,r="8";break;default:throw new Error(`Invalid barcode specified. Available decoders: ${n.BARCODE_DECODERS}.`)}const a=O||s&&s.singlePass||!1,{data:d,width:h,height:u}=(S=t).data&&S.width&&S.height?t:await async function(n){return new Promise((t,w)=>{if("string"==typeof n)if(n.startsWith("#")){const e=document.getElementById(n.substr(1));if(e instanceof HTMLImageElement&&t(g(e)),e instanceof HTMLCanvasElement){const n=e.getContext("2d");if(!n)throw new Error("Cannot create canvas 2d context");t(n.getImageData(0,0,e.width,e.height))}w(new Error("Invalid image source specified!"))}else if(!(o=n).startsWith("#")&&/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(o)){const e=new Image;e.onerror=w,e.onload=()=>t(g(e)),e.src=n}else D&&e.read(n,(n,e)=>{if(n)w(n);else{const{data:n,width:w,height:o}=e.bitmap;t({data:Uint8ClampedArray.from(n),width:w,height:o})}});else if(n instanceof HTMLImageElement)t(g(n));else if(n instanceof HTMLCanvasElement){const e=n.getContext("2d");if(!e)throw new Error("Cannot create canvas 2d context");t(e.getImageData(0,0,n.width,n.height))}var o})}(t);var S;const j=d.length/(h*u);let R="";s&&s.useAdaptiveThreshold&&function(n,e,t){const w=new Array(e*t).fill(0),o=n.length/(e*t),r=Math.floor(t),s=Math.floor(r/2);for(let r=0;r<e;r+=1){let s=0;for(let c=0;c<t;c+=1){const t=c*e+r,i=t*o,a=(n[i]+n[i+1]+n[i+2])/3;n[i]=a,n[i+1]=a,n[i+2]=a,s+=a,w[t]=0===r?s:w[t-1]+s}}for(let r=0;r<e;r+=1)for(let c=0;c<t;c+=1){const i=(c*e+r)*o;let a=r-s,l=r+s,d=c-s,f=c+s;a<0&&(a=0),l>=e&&(l=e-1),d<0&&(d=0),f>=t&&(f=t-1);const h=(l-a)*(f-d),p=w[f*e+l]-w[d*e+l]-w[f*e+a]+w[d*e+a];let u=255;n[i]*h<.85*p&&(u=0),n[i]=u,n[i+1]=u,n[i+2]=u}}(d,h,u);const A=[5,6,4,7,3,8,2,9,1],B=Math.round(u/A.length),b=Math.min(2,u);for(let n=0;n<A.length;n+=1){const e=j*h*Math.floor(B*A[n]),t=e+b*j*h,w=m(d.slice(e,t),h,b);if(0===w.length){if(a||n===A.length-1)throw new Error("Failed to detect lines in the image!");continue}const o=c(w,r);if(o){if(a||!o.includes("?"))return o;if(R=E(R,o),!R.includes("?"))return R}}return R},Object.defineProperty(n,"__esModule",{value:!0})}));
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("jimp")):"function"==typeof define&&define.amd?define(["exports","jimp"],e):e((n=n||self).javascriptBarcodeReader={},n.Jimp)}(this,(function(n,e){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function t(n,e,t,w){return new(t||(t=Promise))((function(o,r){function c(n){try{s(w.next(n))}catch(n){r(n)}}function i(n){try{s(w.throw(n))}catch(n){r(n)}}function s(n){n.done?o(n.value):new t((function(e){e(n.value)})).then(c,i)}s((w=w.apply(n,e||[])).next())}))}const w={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 o(n){const e=[],t=Math.ceil(n.reduce((n,e)=>(n+e)/2,0));for(;n.length>0;){const o=n.splice(0,8).splice(0,7).map(n=>n<t?"n":"w").join("");e.push(w[o])}return e.join("")}const r=["212222","222122","222221","121223","121322","131222","122213","122312","132212","221213","221312","231212","112232","122132","122231","113222","123122","123221","223211","221132","221231","213212","223112","312131","311222","321122","321221","312212","322112","322211","212123","212321","232121","111323","131123","131321","112313","132113","132311","211313","231113","231311","112133","112331","132131","113123","113321","133121","313121","211331","231131","213113","213311","213131","311123","311321","331121","312113","312311","332111","314111","221411","431111","111224","111422","121124","121421","141122","141221","112214","112412","122114","122411","142112","142211","241211","221114","413111","241112","134111","111242","121142","121241","114212","124112","124211","411212","421112","421211","212141","214121","412121","111143","111341","131141","114113","114311","411113","411311","113141","114131","311141","411131","211412","211214","211232","233111","211133","2331112"],c=[" ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL","BS","HT","LF","VT","FF","CR","SO","SI","DLE","DC1","DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM","SUB","ESC","FS","GS","RS","US","FNC 3","FNC 2","Shift B","Code C","Code B","FNC 4","FNC 1","Code A","Code B","Code C","Stop","Reverse Stop"],i=[" ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","{","|","}","~","DEL","FNC 3","FNC 2","Shift A","Code C","FNC 4","Code A","FNC 1","Code A","Code B","Code C","Stop","Reverse Stop"],s=["00","01","02","03","04","05","06","07","08","09","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","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","Code B","Code A","FNC 1","Code A","Code B","Code C","Stop","Reverse Stop"];function a(n){const e=[];let t,w,o=i;const a=(n=>{const e=n.length-13,t=n.reduce((n,t,w)=>w>=e?n:n+t,0)/(11*Math.ceil(e/6));return n.map(n=>Math.round(n/t)||1)})(n);if(!a)return"";a.pop();for(let n=0;6*n<a.length-13;n+=1){t=a.slice(6*n,6*(n+1)).join("");const l=o[r.indexOf(t)];switch(l){case"Code A":o=c;break;case"Code B":o=i;break;case"Code C":o=s;break;case"FNC 4":break;default:l?("FNC 4"===w?e.push(l.charCodeAt(0)+128):e.push(l),w=l):e.push("?")}}return e.join("")}const l={nnnwwnwnn:"0",wnnwnnnnw:"1",nnwwnnnnw:"2",wnwwnnnnn:"3",nnnwwnnnw:"4",wnnwwnnnn:"5",nnwwwnnnn:"6",nnnwnnwnw:"7",wnnwnnwnn:"8",nnwwnnwnn:"9",wnnnnwnnw:"A",nnwnnwnnw:"B",wnwnnwnnn:"C",nnnnwwnnw:"D",wnnnwwnnn:"E",nnwnwwnnn:"F",nnnnnwwnw:"G",wnnnnwwnn:"H",nnwnnwwnn:"I",nnnnwwwnn:"J",wnnnnnnww:"K",nnwnnnnww:"L",wnwnnnnwn:"M",nnnnwnnww:"N",wnnnwnnwn:"O",nnwnwnnwn:"P",nnnnnnwww:"Q",wnnnnnwwn:"R",nnwnnnwwn:"S",nnnnwnwwn:"T",wwnnnnnnw:"U",nwwnnnnnw:"V",wwwnnnnnn:"W",nwnnwnnnw:"X",wwnnwnnnn:"Y",nwwnwnnnn:"Z",nwnnnnwnw:"-",wwnnnnwnn:".",nwwnnnwnn:" ",nwnwnwnnn:"$",nwnwnnnwn:"/",nwnnnwnwn:"+",nnnwnwnwn:"%",nwnnwnwnn:"*"};function f(n){const e=[],t=Math.ceil(n.reduce((n,e)=>n+e,0)/n.length);for(;n.length>0;){const w=n.splice(0,10).map(n=>n>t?"w":"n").slice(0,9).join("");e.push(l[w])}return"*"!==e.pop()||"*"!==e.shift()?"":e.join("")}const d=[{100010100:"0"},{101001e3:"1"},{101000100:"2"},{101000010:"3"},{100101e3:"4"},{100100100:"5"},{100100010:"6"},{10101e4:"7"},{100010010:"8"},{100001010:"9"},{110101e3:"A"},{110100100:"B"},{110100010:"C"},{110010100:"D"},{110010010:"E"},{110001010:"F"},{101101e3:"G"},{101100100:"H"},{101100010:"I"},{100110100:"J"},{100011010:"K"},{101011e3:"L"},{101001100:"M"},{101000110:"N"},{100101100:"O"},{100010110:"P"},{110110100:"Q"},{110110010:"R"},{110101100:"S"},{110100110:"T"},{110010110:"U"},{110011010:"V"},{101101100:"W"},{101100110:"X"},{100110110:"Y"},{100111010:"Z"},{100101110:"-"},{111010100:"."},{111010010:" "},{111001010:"$"},{101101110:"/"},{101110110:"+"},{110101110:"%"},{100100110:"($)"},{111011010:"(%)"},{111010110:"(/)"},{100110010:"(+)"},{101011110:"*"}];function h(n){const e=[],t=[];n.pop();const w=Math.ceil(n.reduce((n,e)=>n+e,0)/n.length),o=Math.ceil(n.reduce((n,e)=>e<w?(n+e)/2:n,0));for(let e=0;e<n.length;e+=1){let w=n[e];for(;w>0;)e%2==0?t.push(1):t.push(0),w-=o}for(let n=0;n<t.length;n+=9){const w=t.slice(n,n+9).join(""),o=d.filter(n=>Object.keys(n)[0]===w);e.push(o[0][w])}if("*"!==e.shift()||"*"!==e.pop())return"";const r=e.pop();let c,i,s=0;const a=n=>Object.values(n)[0]===c;for(let n=e.length-1;n>=0;n-=1)c=e[n],i=d.indexOf(d.filter(a)[0]),s+=i*(1+(e.length-(n+1))%20);if(Object.values(d[s%47])[0]!==r)return"";const l=e.pop();s=0;for(let n=e.length-1;n>=0;n-=1)c=e[n],i=d.indexOf(d.filter(a)[0]),s+=i*(1+(e.length-(n+1))%20);return Object.values(d[s%47])[0]!==l?"":e.join("")}const p=["nnwwn","wnnnw","nwnnw","wwnnn","nnwnw","wnwnn","nwwnn","nnnww","wnnwn","nwnwn"];function u(n,e){const t=[],w=Math.ceil(n.reduce((n,e)=>(n+e)/2,0));if("interleaved"===e){const e=n.splice(0,4).map(n=>n>w?"w":"n").join(""),o=n.splice(n.length-3,3).map(n=>n>w?"w":"n").join("");if("nnnn"!==e||"wnn"!==o)return"";for(;n.length>0;){const e=n.splice(0,10),o=e.filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join("");t.push(p.indexOf(o));const r=e.filter((n,e)=>e%2!=0).map(n=>n>w?"w":"n").join("");t.push(p.indexOf(r))}}else{const e=n.splice(0,6).filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join(""),o=n.splice(n.length-5,5).filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join("");if("wwn"!==e||"wnw"!==o)return"";for(;n.length>0;){const e=n.splice(0,10).filter((n,e)=>e%2==0).map(n=>n>w?"w":"n").join("");t.push(p.indexOf(e))}}return t.join("")}const C={3211:"0",2221:"1",2122:"2",1411:"3",1132:"4",1231:"5",1114:"6",1312:"7",1213:"8",3112:"9"};function E(n,e="13"){let t="";const w=(n[0]+n[1]+n[2])/3;n.shift(),n.shift(),n.shift(),n.pop(),n.pop(),n.pop(),"13"===e?n.splice(24,5):n.splice(16,5);for(let e=0;e<n.length;e+=4){const o=n.slice(e,e+4),r=[o[0]/w,o[1]/w,o[2]/w,o[3]/w].map(n=>1.5===n?1:Math.round(n)),c=C[r.join("")]||C[r.reverse().join("")];t+=c||"?"}return t}function g(n,e){if(""===n||""===e)return e;const t=n.split("");return e.split("").forEach((n,e)=>{t[e]&&"?"!==t[e]||n&&"?"!==n&&(t[e]=n)}),t.join("")}function D(n){const e=document.createElement("canvas"),t=e.getContext("2d");if(!t)throw new Error("Cannot create canvas 2d context");const w=n.naturalWidth,o=n.naturalHeight;return e.width=w,e.height=o,t.drawImage(n,0,0),t.getImageData(0,0,w,o)}const m="object"==typeof process&&process.release&&"node"===process.release.name;function O(n,e,t){const w=[],o=n.length/(e*t);let r=0,c=0;for(let i=0;i<e;i+=1){let s=0,a=0;for(let w=0;w<t;w+=1){const t=(w*e+i)*o;s+=Math.sqrt((Math.pow(n[t],2)+Math.pow(n[t+1],2)+Math.pow(n[t+2],2))/3)}a=s/t>=127?255:0,255===a&&0===r||(a===c?r+=1:(w.push(r),c=a,r=1),i===e-1&&0===a&&w.push(r))}return w}const S=process&&"test"===process.env.NODE_ENV;var v;(v=n.BARCODE_DECODERS||(n.BARCODE_DECODERS={}))["code-128"]="code-128",v["code-2of5"]="code-2of5",v["code-39"]="code-39",v["code-93"]="code-93",v["ean-13"]="ean-13",v["ean-8"]="ean-8",v.codabar="codabar",n.javascriptBarcodeReader=function({image:w,barcode:r,barcodeType:c,options:i}){return t(this,void 0,void 0,(function*(){let s;switch(r){case n.BARCODE_DECODERS.codabar:s=o;break;case n.BARCODE_DECODERS["code-128"]:s=a;break;case n.BARCODE_DECODERS["code-39"]:s=f;break;case n.BARCODE_DECODERS["code-93"]:s=h;break;case n.BARCODE_DECODERS["code-2of5"]:s=u;break;case n.BARCODE_DECODERS["ean-13"]:s=E,c="13";break;case n.BARCODE_DECODERS["ean-8"]:s=E,c="8";break;default:throw new Error(`Invalid barcode specified. Available decoders: ${n.BARCODE_DECODERS}.`)}const l=S||i&&i.singlePass||!1,{data:d,width:p,height:C}=(v=w).data&&v.width&&v.height?w:yield function(n){return t(this,void 0,void 0,(function*(){return new Promise((t,w)=>{if("string"==typeof n)if(n.startsWith("#")){const e=document.getElementById(n.substr(1));if(e instanceof HTMLImageElement&&t(D(e)),e instanceof HTMLCanvasElement){const n=e.getContext("2d");if(!n)throw new Error("Cannot create canvas 2d context");t(n.getImageData(0,0,e.width,e.height))}w(new Error("Invalid image source specified!"))}else if(!(o=n).startsWith("#")&&/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(o)){const e=new Image;e.onerror=w,e.onload=()=>t(D(e)),e.src=n}else m&&e.read(n,(n,e)=>{if(n)w(n);else{const{data:n,width:w,height:o}=e.bitmap;t({data:Uint8ClampedArray.from(n),width:w,height:o})}});else if(n instanceof HTMLImageElement)t(D(n));else if(n instanceof HTMLCanvasElement){const e=n.getContext("2d");if(!e)throw new Error("Cannot create canvas 2d context");t(e.getImageData(0,0,n.width,n.height))}var o})}))}(w);var v;const j=d.length/(p*C);let R="";i&&i.useAdaptiveThreshold&&function(n,e,t){const w=new Array(e*t).fill(0),o=n.length/(e*t),r=Math.floor(t),c=Math.floor(r/2);for(let r=0;r<e;r+=1){let c=0;for(let i=0;i<t;i+=1){const t=i*e+r,s=t*o,a=(n[s]+n[s+1]+n[s+2])/3;n[s]=a,n[s+1]=a,n[s+2]=a,c+=a,w[t]=0===r?c:w[t-1]+c}}for(let r=0;r<e;r+=1)for(let i=0;i<t;i+=1){const s=(i*e+r)*o;let a=r-c,l=r+c,f=i-c,d=i+c;a<0&&(a=0),l>=e&&(l=e-1),f<0&&(f=0),d>=t&&(d=t-1);const h=(l-a)*(d-f),p=w[d*e+l]-w[f*e+l]-w[d*e+a]+w[f*e+a];let u=255;n[s]*h<.85*p&&(u=0),n[s]=u,n[s+1]=u,n[s+2]=u}}(d,p,C);const A=[5,6,4,7,3,8,2,9,1],B=Math.round(C/A.length),b=Math.min(2,C);for(let n=0;n<A.length;n+=1){const e=j*p*Math.floor(B*A[n]),t=e+b*j*p,w=O(d.slice(e,t),p,b);if(0===w.length){if(l||n===A.length-1)throw new Error("Failed to detect lines in the image!");continue}const o=s(w,c);if(o){if(l||!o.includes("?"))return o;if(R=g(R,o),!R.includes("?"))return R}}return R}))},Object.defineProperty(n,"__esModule",{value:!0})}));
//# sourceMappingURL=javascript-barcode-reader.umd.min.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -28,66 +37,68 @@ // available decoders

}
async function javascriptBarcodeReader({ image, barcode, barcodeType, options, }) {
let decoder;
switch (barcode) {
case BARCODE_DECODERS.codabar:
decoder = codabar.decoder;
break;
case BARCODE_DECODERS['code-128']:
decoder = code128.decoder;
break;
case BARCODE_DECODERS['code-39']:
decoder = code39.decoder;
break;
case BARCODE_DECODERS['code-93']:
decoder = code93.decoder;
break;
case BARCODE_DECODERS['code-2of5']:
decoder = code2of5.decoder;
break;
case BARCODE_DECODERS['ean-13']:
decoder = ean.decoder;
barcodeType = '13';
break;
case BARCODE_DECODERS['ean-8']:
decoder = ean.decoder;
barcodeType = '8';
break;
default:
throw new Error(`Invalid barcode specified. Available decoders: ${BARCODE_DECODERS}.`);
}
const useSinglePass = isTestEnv || (options && options.singlePass) || false;
const { data, width, height } = isImageLike(image) ? image : await getImageDataFromSource_1.getImageDataFromSource(image);
const channels = data.length / (width * height);
let finalResult = '';
// apply adaptive threshold
if (options && options.useAdaptiveThreshold) {
adaptiveThreshold_1.applyAdaptiveThreshold(data, width, height);
}
// check points for barcode location
const searchPoints = [5, 6, 4, 7, 3, 8, 2, 9, 1];
const searchLineStep = Math.round(height / searchPoints.length);
const rowsToScan = Math.min(2, height);
for (let i = 0; i < searchPoints.length; i += 1) {
const start = channels * width * Math.floor(searchLineStep * searchPoints[i]);
const end = start + rowsToScan * channels * width;
const lines = getLines_1.getLines(data.slice(start, end), width, rowsToScan);
if (lines.length === 0) {
if (useSinglePass || i === searchPoints.length - 1) {
throw new Error('Failed to detect lines in the image!');
function javascriptBarcodeReader({ image, barcode, barcodeType, options, }) {
return __awaiter(this, void 0, void 0, function* () {
let decoder;
switch (barcode) {
case BARCODE_DECODERS.codabar:
decoder = codabar.decoder;
break;
case BARCODE_DECODERS['code-128']:
decoder = code128.decoder;
break;
case BARCODE_DECODERS['code-39']:
decoder = code39.decoder;
break;
case BARCODE_DECODERS['code-93']:
decoder = code93.decoder;
break;
case BARCODE_DECODERS['code-2of5']:
decoder = code2of5.decoder;
break;
case BARCODE_DECODERS['ean-13']:
decoder = ean.decoder;
barcodeType = '13';
break;
case BARCODE_DECODERS['ean-8']:
decoder = ean.decoder;
barcodeType = '8';
break;
default:
throw new Error(`Invalid barcode specified. Available decoders: ${BARCODE_DECODERS}.`);
}
const useSinglePass = isTestEnv || (options && options.singlePass) || false;
const { data, width, height } = isImageLike(image) ? image : yield getImageDataFromSource_1.getImageDataFromSource(image);
const channels = data.length / (width * height);
let finalResult = '';
// apply adaptive threshold
if (options && options.useAdaptiveThreshold) {
adaptiveThreshold_1.applyAdaptiveThreshold(data, width, height);
}
// check points for barcode location
const searchPoints = [5, 6, 4, 7, 3, 8, 2, 9, 1];
const searchLineStep = Math.round(height / searchPoints.length);
const rowsToScan = Math.min(2, height);
for (let i = 0; i < searchPoints.length; i += 1) {
const start = channels * width * Math.floor(searchLineStep * searchPoints[i]);
const end = start + rowsToScan * channels * width;
const lines = getLines_1.getLines(data.slice(start, end), width, rowsToScan);
if (lines.length === 0) {
if (useSinglePass || i === searchPoints.length - 1) {
throw new Error('Failed to detect lines in the image!');
}
continue;
}
continue;
// Run the decoder
const result = decoder(lines, barcodeType);
if (!result)
continue;
else if (useSinglePass || !result.includes('?'))
return result;
finalResult = combineAllPossible_1.combineAllPossible(finalResult, result);
if (!finalResult.includes('?'))
return finalResult;
}
// Run the decoder
const result = decoder(lines, barcodeType);
if (!result)
continue;
else if (useSinglePass || !result.includes('?'))
return result;
finalResult = combineAllPossible_1.combineAllPossible(finalResult, result);
if (!finalResult.includes('?'))
return finalResult;
}
return finalResult;
return finalResult;
});
}
exports.javascriptBarcodeReader = javascriptBarcodeReader;
//# sourceMappingURL=index.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -7,49 +16,51 @@ const Jimp = require("jimp");

const isNode = typeof process === 'object' && process.release && process.release.name === 'node';
async function getImageDataFromSource(source) {
return new Promise((resolve, reject) => {
if (typeof source === 'string') {
if (source.startsWith('#')) {
const imageElement = document.getElementById(source.substr(1));
if (imageElement instanceof HTMLImageElement) {
resolve(createImageData_1.createImageData(imageElement));
function getImageDataFromSource(source) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
if (typeof source === 'string') {
if (source.startsWith('#')) {
const imageElement = document.getElementById(source.substr(1));
if (imageElement instanceof HTMLImageElement) {
resolve(createImageData_1.createImageData(imageElement));
}
if (imageElement instanceof HTMLCanvasElement) {
const ctx = imageElement.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
resolve(ctx.getImageData(0, 0, imageElement.width, imageElement.height));
}
reject(new Error('Invalid image source specified!'));
}
if (imageElement instanceof HTMLCanvasElement) {
const ctx = imageElement.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
resolve(ctx.getImageData(0, 0, imageElement.width, imageElement.height));
else if (isUrl_1.isUrl(source)) {
const img = new Image();
img.onerror = reject;
img.onload = () => resolve(createImageData_1.createImageData(img));
img.src = source;
}
reject(new Error('Invalid image source specified!'));
else if (isNode) {
Jimp.read(source, (err, image) => {
if (err) {
reject(err);
}
else {
const { data, width, height } = image.bitmap;
resolve({
data: Uint8ClampedArray.from(data),
width,
height,
});
}
});
}
}
else if (isUrl_1.isUrl(source)) {
const img = new Image();
img.onerror = reject;
img.onload = () => resolve(createImageData_1.createImageData(img));
img.src = source;
else if (source instanceof HTMLImageElement) {
resolve(createImageData_1.createImageData(source));
}
else if (isNode) {
Jimp.read(source, (err, image) => {
if (err) {
reject(err);
}
else {
const { data, width, height } = image.bitmap;
resolve({
data: Uint8ClampedArray.from(data),
width,
height,
});
}
});
else if (source instanceof HTMLCanvasElement) {
const ctx = source.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
resolve(ctx.getImageData(0, 0, source.width, source.height));
}
}
else if (source instanceof HTMLImageElement) {
resolve(createImageData_1.createImageData(source));
}
else if (source instanceof HTMLCanvasElement) {
const ctx = source.getContext('2d');
if (!ctx)
throw new Error('Cannot create canvas 2d context');
resolve(ctx.getImageData(0, 0, source.width, source.height));
}
});
});

@@ -56,0 +67,0 @@ }

@@ -13,3 +13,3 @@ "use strict";

const index = (row * width + column) * channels;
columnSum += Math.sqrt((data[index] ** 2 + data[index + 1] ** 2 + data[index + 2] ** 2) / 3);
columnSum += Math.sqrt((Math.pow(data[index], 2) + Math.pow(data[index + 1], 2) + Math.pow(data[index + 2], 2)) / 3);
}

@@ -16,0 +16,0 @@ // pixels are same in column

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -10,8 +19,10 @@ const Jimp = require("jimp");

const isUrl_1 = require("../src/utilities/isUrl");
async function loadImage(src) {
return new Promise((resolve, reject) => {
const img = new Image();
img.onerror = reject;
img.onload = () => resolve(img);
img.src = src;
function loadImage(src) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const img = new Image();
img.onerror = reject;
img.onload = () => resolve(img);
img.src = src;
});
});

@@ -24,8 +35,8 @@ }

const ctx = canvas.getContext('2d');
ctx?.drawImage(img, 0, 0);
ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(img, 0, 0);
return canvas;
}
beforeAll(async () => {
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
const imageUrl = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Code_93_wikipedia.png';
const img = await loadImage(imageUrl);
const img = yield loadImage(imageUrl);
img.id = 'Code_93_wikipedia_image';

@@ -36,7 +47,7 @@ const canvas = loadCanvas(img);

document.body.appendChild(canvas);
});
}));
describe('Count lines in an image', () => {
test('should detect lines in barcode image', async () => {
test('should detect lines in barcode image', () => __awaiter(void 0, void 0, void 0, function* () {
const rowsToScan = 3;
const image = await Jimp.read('./test/sample-images/small-padding.png');
const image = yield Jimp.read('./test/sample-images/small-padding.png');
const { data, width, height } = image.bitmap;

@@ -48,6 +59,6 @@ const channels = data.length / (width * height);

expect(lines.length).toBe(27);
});
test('should detect lines in barcode image without padding', async () => {
}));
test('should detect lines in barcode image without padding', () => __awaiter(void 0, void 0, void 0, function* () {
const rowsToScan = 3;
const image = await Jimp.read('./test/sample-images/small.png');
const image = yield Jimp.read('./test/sample-images/small.png');
const { data, width, height } = image.bitmap;

@@ -59,6 +70,6 @@ const channels = data.length / (width * height);

expect(lines.length).toBe(27);
});
test('should return zero lines with empty image', async () => {
}));
test('should return zero lines with empty image', () => __awaiter(void 0, void 0, void 0, function* () {
const rowsToScan = 3;
const image = await Jimp.read('./test/sample-images/empty.jpg');
const image = yield Jimp.read('./test/sample-images/empty.jpg');
const { data, width, height } = image.bitmap;

@@ -70,49 +81,49 @@ const channels = data.length / (width * height);

expect(lines.length).toBe(0);
});
}));
});
describe('get imageData from source', () => {
test('should get imageData from url', async () => {
test('should get imageData from url', () => __awaiter(void 0, void 0, void 0, function* () {
const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Code_93_wikipedia.png';
const dataSource = await getImageDataFromSource_1.getImageDataFromSource(url);
const dataSource = yield getImageDataFromSource_1.getImageDataFromSource(url);
expect(typeof dataSource.data).toBe('object');
expect(typeof dataSource.width).toBe('number');
expect(typeof dataSource.height).toBe('number');
});
test('should get imageData from file path', async () => {
}));
test('should get imageData from file path', () => __awaiter(void 0, void 0, void 0, function* () {
const url = path.resolve('./test/sample-images/codabar.jpg');
const dataSource = await getImageDataFromSource_1.getImageDataFromSource(url);
const dataSource = yield getImageDataFromSource_1.getImageDataFromSource(url);
expect(typeof dataSource.data).toBe('object');
expect(typeof dataSource.width).toBe('number');
expect(typeof dataSource.height).toBe('number');
});
test('should get imageData from HTMLImageElement id', async () => {
const dataSource = await getImageDataFromSource_1.getImageDataFromSource('#Code_93_wikipedia_image');
}));
test('should get imageData from HTMLImageElement id', () => __awaiter(void 0, void 0, void 0, function* () {
const dataSource = yield getImageDataFromSource_1.getImageDataFromSource('#Code_93_wikipedia_image');
expect(typeof dataSource.data).toBe('object');
expect(typeof dataSource.width).toBe('number');
expect(typeof dataSource.height).toBe('number');
});
test('should get imageData from HTMLCanvasElement id', async () => {
const dataSource = await getImageDataFromSource_1.getImageDataFromSource('#Code_93_wikipedia_canvas');
}));
test('should get imageData from HTMLCanvasElement id', () => __awaiter(void 0, void 0, void 0, function* () {
const dataSource = yield getImageDataFromSource_1.getImageDataFromSource('#Code_93_wikipedia_canvas');
expect(typeof dataSource.data).toBe('object');
expect(typeof dataSource.width).toBe('number');
expect(typeof dataSource.height).toBe('number');
});
test('should get imageData from HTMLImageElement', async () => {
}));
test('should get imageData from HTMLImageElement', () => __awaiter(void 0, void 0, void 0, function* () {
const imageElement = document.getElementById('Code_93_wikipedia_image');
if (!imageElement || !(imageElement instanceof HTMLImageElement))
return;
const dataSource = await getImageDataFromSource_1.getImageDataFromSource(imageElement);
const dataSource = yield getImageDataFromSource_1.getImageDataFromSource(imageElement);
expect(typeof dataSource.data).toBe('object');
expect(typeof dataSource.width).toBe('number');
expect(typeof dataSource.height).toBe('number');
});
test('should get imageData from HTMLCanvasElement', async () => {
}));
test('should get imageData from HTMLCanvasElement', () => __awaiter(void 0, void 0, void 0, function* () {
const imageElement = document.getElementById('Code_93_wikipedia_canvas');
if (!imageElement || !(imageElement instanceof HTMLCanvasElement))
return;
const dataSource = await getImageDataFromSource_1.getImageDataFromSource(imageElement);
const dataSource = yield getImageDataFromSource_1.getImageDataFromSource(imageElement);
expect(typeof dataSource.data).toBe('object');
expect(typeof dataSource.width).toBe('number');
expect(typeof dataSource.height).toBe('number');
});
}));
test('should throw with invalid source', () => {

@@ -139,4 +150,4 @@ getImageDataFromSource_1.getImageDataFromSource('Olalalala').catch(err => {

describe('extract barcode from local files', () => {
test('should detect barcode codabar', async () => {
const result = await index_1.javascriptBarcodeReader({
test('should detect barcode codabar', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/codabar.jpg'),

@@ -146,5 +157,5 @@ barcode: index_1.BARCODE_DECODERS.codabar,

expect(result).toBe('A40156C');
});
test('should detect barcode codabar', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode codabar', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/codabar.jpg'),

@@ -157,5 +168,5 @@ barcode: index_1.BARCODE_DECODERS.codabar,

expect(result).toBe('A40156C');
});
test('should detect barcode 2 of 5 standard', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode 2 of 5 standard', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/code-2of5.jpg'),

@@ -165,5 +176,5 @@ barcode: 'code-2of5',

expect(result).toBe('12345670');
});
test('should detect barcode 2 of 5 interleaved', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode 2 of 5 interleaved', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/code-2of5-interleaved.jpg'),

@@ -174,5 +185,5 @@ barcode: 'code-2of5',

expect(result).toBe('12345670');
});
test('should detect barcode 39', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode 39', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/code-39.jpg'),

@@ -182,5 +193,5 @@ barcode: 'code-39',

expect(result).toBe('10023');
});
test('should detect barcode 93', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode 93', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/code-93.jpg'),

@@ -190,5 +201,5 @@ barcode: 'code-93',

expect(result).toBe('123ABC');
});
test('should detect barcode 128: ABC-abc-1234', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode 128: ABC-abc-1234', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/code-128.jpg'),

@@ -198,3 +209,3 @@ barcode: 'code-128',

expect(result).toBe('ABC-abc-1234');
});
}));
// test('should detect barcode 128: eeb00f0c-0c7e-a937-1794-25685779ba0c', async () => {

@@ -214,4 +225,4 @@ // const result = await javascriptBarcodeReader({

// })
test('should detect barcode EAN-8', async () => {
const result = await index_1.javascriptBarcodeReader({
test('should detect barcode EAN-8', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/ean-8.jpg'),

@@ -224,5 +235,5 @@ barcode: 'ean-8',

expect(result).toBe('73127727');
});
test('should detect barcode EAN-13 small', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode EAN-13 small', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/ean-13-5901234123457.png'),

@@ -232,5 +243,5 @@ barcode: 'ean-13',

expect(result).toBe('901234123457');
});
test('should detect barcode EAN-13 large', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode EAN-13 large', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/ean-13.jpg'),

@@ -240,5 +251,5 @@ barcode: 'ean-13',

expect(result).toBe('901234123457');
});
test('should detect barcode 128 without padding white bars', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode 128 without padding white bars', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/code-128-no-padding.jpg'),

@@ -248,5 +259,5 @@ barcode: 'code-128',

expect(result).toBe('12ab#!');
});
test('should detect barcode 128 with multiple zeros', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode 128 with multiple zeros', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/code-128-000.jpg'),

@@ -256,5 +267,5 @@ barcode: 'code-128',

expect(result).toBe('79619647103200000134407005');
});
test('should detect barcode 128 with default start Code B', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode 128 with default start Code B', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/L89HE1806005080432.gif'),

@@ -264,5 +275,5 @@ barcode: 'code-128',

expect(result).toBe('L89HE1806005080432');
});
test('should detect barcode 93 without padding white bars', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode 93 without padding white bars', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/code-93-no-padding.jpg'),

@@ -272,7 +283,7 @@ barcode: 'code-93',

expect(result).toBe('WIKIPEDIA');
});
test('should detect barcode 93 with bitmap data', async () => {
const image = await Jimp.read('./test/sample-images/code-93-no-padding.jpg');
}));
test('should detect barcode 93 with bitmap data', () => __awaiter(void 0, void 0, void 0, function* () {
const image = yield Jimp.read('./test/sample-images/code-93-no-padding.jpg');
const { data, width, height } = image.bitmap;
const result = await index_1.javascriptBarcodeReader({
const result = yield index_1.javascriptBarcodeReader({
image: {

@@ -286,7 +297,7 @@ data: Uint8ClampedArray.from(data),

expect(result).toBe('WIKIPEDIA');
});
}));
});
describe('extract barcode after applying adaptive threhsold', () => {
test('should detect barcode codabar', async () => {
const result = await index_1.javascriptBarcodeReader({
test('should detect barcode codabar', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/codabar.jpg'),

@@ -299,5 +310,5 @@ barcode: 'codabar',

expect(result).toBe('A40156C');
});
test('should detect barcode 2 of 5', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode 2 of 5', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/code-2of5.jpg'),

@@ -310,5 +321,5 @@ barcode: 'code-2of5',

expect(result).toBe('12345670');
});
test('should detect barcode 2 of 5 interleaved', async () => {
const result = await index_1.javascriptBarcodeReader({
}));
test('should detect barcode 2 of 5 interleaved', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: path.resolve('./test/sample-images/code-2of5-interleaved.jpg'),

@@ -322,7 +333,7 @@ barcode: 'code-2of5',

expect(result).toBe('12345670');
});
}));
});
describe('extract barcode from remote URL', () => {
test('should detect barcode 93 from remote url', async () => {
const result = await index_1.javascriptBarcodeReader({
test('should detect barcode 93 from remote url', () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield index_1.javascriptBarcodeReader({
image: 'https://upload.wikimedia.org/wikipedia/en/a/a9/Code_93_wikipedia.png',

@@ -332,8 +343,8 @@ barcode: 'code-93',

expect(result).toBe('WIKIPEDIA');
});
}));
});
describe('Fails', () => {
test('throws when no barcode specified', async () => {
test('throws when no barcode specified', () => __awaiter(void 0, void 0, void 0, function* () {
try {
await index_1.javascriptBarcodeReader({
yield index_1.javascriptBarcodeReader({
image: 'https://upload.wikimedia.org/wikipedia/en/a/a9/Code_93_wikipedia.png',

@@ -346,6 +357,6 @@ barcode: 'oallal',

}
});
test('throws when invalid barcode specified', async () => {
}));
test('throws when invalid barcode specified', () => __awaiter(void 0, void 0, void 0, function* () {
try {
await index_1.javascriptBarcodeReader({
yield index_1.javascriptBarcodeReader({
image: './test/sample-images/empty.jpg',

@@ -358,6 +369,6 @@ barcode: 'none',

}
});
test('throws when no barcode found', async () => {
}));
test('throws when no barcode found', () => __awaiter(void 0, void 0, void 0, function* () {
try {
await index_1.javascriptBarcodeReader({
yield index_1.javascriptBarcodeReader({
image: './test/sample-images/empty.jpg',

@@ -370,4 +381,4 @@ barcode: 'code-93',

}
});
}));
});
//# sourceMappingURL=index.test.js.map
{
"author": "Muhammad Ubaid Raza <mubaidr@gmail.com>",
"browser": {
"dist/javascript-barcode-reader.es5.js": "dist/javascript-barcode-reader.es5.min.js",
"dist/javascript-barcode-reader.umd.js": "dist/javascript-barcode-reader.umd.min.js"
},
"commitlint": {

@@ -88,4 +92,4 @@ "extends": [

},
"main": "dist/javascript-barcode-reader.umd.min.js",
"module": "dist/javascript-barcode-reader.es5.min.js",
"main": "dist/javascript-barcode-reader.umd.js",
"module": "dist/javascript-barcode-reader.es5.js",
"name": "javascript-barcode-reader",

@@ -112,3 +116,3 @@ "repository": {

"typings": "dist/types/javascript-barcode-reader.d.ts",
"version": "0.6.6"
"version": "0.6.7"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc