boleto-barcode-svg
Version:
Generate brazilian boleto barcode in SVG
3 lines (2 loc) • 890 B
JavaScript
function n(n){return'<rect y="0" height="100%" fill="'+n.fill+'" width="'+n.width+'" x="'+n.x+'"></rect>'}var t=["11221","21112","12112","22111","11212","21211","12211","11122","21121","12121"];function r(n){for(var r=t[Math.floor(n/10)],i=t[n%10],e="",o=0;o<5;o+=1)e+=r[o],e+=i[o];return e}exports.boletoBarcodeSvg=function(t){return u=(i=function(n){return n.split("").map(Number)}(function(n){return"1111"+n.match(/(..?)/g).map(r).join("")+"211"}(t=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")}(t))).map((f=0,function(n,t){var r={x:f,width:4*n,fill:t%2?"#fff":"#000"};return f+=r.width,r}))).map(n),['<svg viewBox="0 0 '+((e=i[i.length-1]).width+e.x)+' 100">',(o=u,void 0===o&&(o=[]),o.map(function(n){return" "+n}).join("\n")),"</svg>"].join("\n");var i,e,o,u,f};
//# sourceMappingURL=boleto-barcode-svg.js.map