boleto-barcode-svg
Version:
Generate brazilian boleto barcode in SVG
3 lines (2 loc) • 1.08 kB
JavaScript
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n=n||self).boletoBarcodeSvg={})}(this,function(n){function t(n){return'<rect y="0" height="100%" fill="'+n.fill+'" width="'+n.width+'" x="'+n.x+'"></rect>'}var e=["11221","21112","12112","22111","11212","21211","12211","11122","21121","12121"];function o(n){for(var t=e[Math.floor(n/10)],o=e[n%10],r="",i=0;i<5;i+=1)r+=t[i],r+=o[i];return r}n.boletoBarcodeSvg=function(n){return f=(e=function(n){return n.split("").map(Number)}(function(n){return"1111"+n.match(/(..?)/g).map(o).join("")+"211"}(n=function(n){return n.replace(/\D/g,"").replace(/^(\d{4})(\d{5})\d{1}(\d{10})\d{1}(\d{10})\d{1}(\d{15})$/,"$1$5$2$3$4")}(n))).map((d=0,function(n,t){var e={x:d,width:4*n,fill:t%2?"#fff":"#000"};return d+=e.width,e}))).map(t),['<svg viewBox="0 0 '+((r=e[e.length-1]).width+r.x)+' 100">',(i=f,void 0===i&&(i=[]),i.map(function(n){return" "+n}).join("\n")),"</svg>"].join("\n");var e,r,i,f,d}});
//# sourceMappingURL=boleto-barcode-svg.umd.js.map