UNPKG

javascript-barcode-reader

Version:
8 lines 3.55 kB
parcelRequire=function(e,r,n,t){function i(n,t){function o(e){return i(o.resolve(e))}function c(r){return e[n][1][r]||r}if(!r[n]){if(!e[n]){var l="function"==typeof parcelRequire&&parcelRequire;if(!t&&l)return l(n,!0);if(u)return u(n,!0);if(f&&"string"==typeof n)return f(n);var p=new Error("Cannot find module '"+n+"'");throw p.code="MODULE_NOT_FOUND",p}o.resolve=c;var a=r[n]=new i.Module(n);e[n][0].call(a.exports,o,a,a.exports,this)}return r[n].exports}function o(e){this.id=e,this.bundle=i,this.exports={}}var u="function"==typeof parcelRequire&&parcelRequire,f="function"==typeof require&&require;i.isParcelRequire=!0,i.Module=o,i.modules=e,i.cache=r,i.parent=u;for(var c=0;c<n.length;c++)i(n[c]);if(n.length){var l=i(n[n.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):t&&(this[t]=l)}return i}({3:[function(require,module,exports) { var n={10001:"1","01001":"2",11000:"3","00101":"4",10100:"5","01100":"6","00011":"7",10010:"8","01010":"9","00110":"10"},r={"01000":"0","00100":"10","00010":"20",10000:"30"},t=["1","2","3","4","5","6","7","8","9","0","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","-",".","␣","*"],e=function(e){e.push(3);for(var u="",o=function(o){var i=e.slice(o,o+10),c=Math.round(i.reduce(function(n,r){return n+r},0)/i.length),f=i.map(function(n){return n>c?1:0}),a=f.filter(function(n,r){return r%2==0}).join(""),l=f.filter(function(n,r){return r%2!=0}).join("");u+=t[parseInt(n[a],10)-1+parseInt(r[l],10)]},i=1;i<e.length;i+=10)o(i);return u.substring(1,u.length-1)};module.exports={decode:e}; },{}],5:[function(require,module,exports) { var r={3211:"0",2221:"1",2122:"2",1411:"3",1132:"4",1231:"5",1114:"6",1312:"7",1213:"8",3112:"9"},e=function(e){for(var n="",o=~~((e[1]+e[2]+e[3])/3),t=1;t<e.length;t+=1){var d=void 0;d=n.length<6?e.slice(4*t,4*t+4):e.slice(4*t+5,4*t+9);var a=[Math.round(d[0]/o),Math.round(d[1]/o),Math.round(d[2]/o),Math.round(d[3]/o)];if(12===(n+=r[a.join("")]||r[a.reverse().join("")]||"X").length)return n}return-1===n.indexOf("X")&&n||!1};module.exports={decode:e}; },{}],1:[function(require,module,exports) { var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=require("./code-93"),r=require("./code-39"),t=require("./ean-13"),a={"code-93":o,"code-39":r,"ean-13":t},n=function(o,r){var t=document,n="object"===(void 0===o?"undefined":e(o))?o:t.getElementById(o),d=n.naturalWidth,u=n.naturalHeight,f=t.createElement("canvas");f.width=d,f.height=u;var c=f.getContext("2d"),i=[1,9,2,8,3,7,4,6,5],p=i.length,y=u/(p+1);for(c.drawImage(n,0,0);p-=1;){for(var l=c.getImageData(0,y*i[p],d,2).data,m=[],v=0,b=0,s=0;s<2;s+=1)for(var g=0;g<d;g+=1){var h=4*(s*d+g),x=(3*l[h]+4*l[h+1]+2*l[h+2])/9,S=m[g];l[h]=x,l[h+1]=x,l[h+2]=x,m[g]=x+(void 0===S?0:S)}for(var q=0;q<d;q+=1){m[q]/=2;var D=m[q];D<v&&(v=D),D>b&&(b=D)}for(var I=v+(b-v)/2,w=[],E=0;E<d;E+=1){for(var j=0,B=0;B<2;B+=1)l[4*(B*d+E)]>I&&(j+=1);w.push(j>1)}for(var C=w[0],H=1,W=[],k=0;k<d;k+=1)w[k]===C?H+=1:(W.push(H),H=1,C=w[k]);return a[r.barcode].decode(W)}return!1};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=n,module.exports=n),exports.barcodeDecoder=n):root.barcodeDecoder=n; },{"./code-93":3,"./code-39":3,"./ean-13":5}]},{},[1], null) //# sourceMappingURL=/javascript-barcode-reader.map