UNPKG

ll-package

Version:

2 lines (1 loc) 2.72 kB
"use strict";const l=require("../../../../../_virtual/CODE128.js");require("../Barcode.js");require("./constants.js");const d=require("../../../../../_virtual/constants.js"),v=require("../../../../../_virtual/Barcode.js");Object.defineProperty(l.__exports,"__esModule",{value:!0});var s=function(){function r(t,o){for(var e=0;e<o.length;e++){var n=o[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(t,o,e){return o&&r(t.prototype,o),e&&r(t,e),t}}(),x=v.__exports,E=g(x),u=d.__exports;function g(r){return r&&r.__esModule?r:{default:r}}function O(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}function B(r,t){if(!r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t&&(typeof t=="object"||typeof t=="function")?t:r}function p(r,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function, not "+typeof t);r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(r,t):r.__proto__=t)}var w=function(r){p(t,r);function t(o,e){O(this,t);var n=B(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,o.substring(1),e));return n.bytes=o.split("").map(function(i){return i.charCodeAt(0)}),n}return s(t,[{key:"valid",value:function(){return/^[\x00-\x7F\xC8-\xD3]+$/.test(this.data)}},{key:"encode",value:function(){var e=this.bytes,n=e.shift()-105,i=u.SET_BY_CODE[n];if(i===void 0)throw new RangeError("The encoding does not start with a start character.");this.shouldEncodeAsEan128()===!0&&e.unshift(u.FNC1);var a=t.next(e,1,i);return{text:this.text===this.data?this.text.replace(/[^\x20-\x7E]/g,""):this.text,data:t.getBar(n)+a.result+t.getBar((a.checksum+n)%u.MODULO)+t.getBar(u.STOP)}}},{key:"shouldEncodeAsEan128",value:function(){var e=this.options.ean128||!1;return typeof e=="string"&&(e=e.toLowerCase()==="true"),e}}],[{key:"getBar",value:function(e){return u.BARS[e]?u.BARS[e].toString():""}},{key:"correctIndex",value:function(e,n){if(n===u.SET_A){var i=e.shift();return i<32?i+64:i-32}else return n===u.SET_B?e.shift()-32:(e.shift()-48)*10+e.shift()-48}},{key:"next",value:function(e,n,i){if(!e.length)return{result:"",checksum:0};var a=void 0,f=void 0;if(e[0]>=200){f=e.shift()-105;var c=u.SWAP[f];c!==void 0?a=t.next(e,n+1,c):((i===u.SET_A||i===u.SET_B)&&f===u.SHIFT&&(e[0]=i===u.SET_A?e[0]>95?e[0]-96:e[0]:e[0]<32?e[0]+96:e[0]),a=t.next(e,n+1,i))}else f=t.correctIndex(e,i),a=t.next(e,n+1,i);var h=t.getBar(f),_=f*n;return{result:h+a.result,checksum:_+a.checksum}}}]),t}(E.default);l.__exports.default=w;