barcode-tool
Version:
lightweight npm package that facilitates barcode generation and detection. It leverages the Barcode Detection API for barcode scanning directly in web browsers and provides an intuitive interface for generating various barcode formats. Seamlessly integrat
1,199 lines (885 loc) • 122 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
async function detectBarcode({ image, formats }) {
if (!image) {
throw new Error('image property is not provided');
}
if ('BarcodeDetector' in window) {
const barcodeDetector = new window.BarcodeDetector({
formats,
});
const barcodes = await barcodeDetector.detect(image);
return barcodes.map((barcode) => ({
format: barcode.format,
rawValue: barcode.rawValue,
}));
}
throw new Error('Barcode Detection API is not supported in this browser');
}
const supportedBarcodeGeneratorFormats = [
"CODE39",
"CODE128", "CODE128A", "CODE128B", "CODE128C",
"EAN13", "EAN8", "EAN5", "EAN2", "UPC", "UPCE",
"ITF14",
"ITF",
"MSI", "MSI10", "MSI11", "MSI1010", "MSI1110",
"pharmacode",
"codabar",
"GenericBarcode",
];
async function getSupportedFormats() {
try {
const types = {
detector: [],
generator: supportedBarcodeGeneratorFormats,
};
// Check if BarcodeDetector is supported in the current environment
if ('BarcodeDetector' in window) {
// Retrieve supported formats using BarcodeDetector API
const detector = window.BarcodeDetector;
if (detector && typeof detector.getSupportedFormats === 'function') {
types.detector = await detector.getSupportedFormats();
}
}
return types;
}
catch (error) {
console.error('Error getting supported formats:', error.message);
throw error;
}
}
var barcodes = {};
var CODE39$1 = {};
var Barcode$1 = {};
Object.defineProperty(Barcode$1, "__esModule", {
value: true
});
function _classCallCheck$s(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Barcode = function Barcode(data, options) {
_classCallCheck$s(this, Barcode);
this.data = data;
this.text = options.text || data;
this.options = options;
};
Barcode$1.default = Barcode;
Object.defineProperty(CODE39$1, "__esModule", {
value: true
});
CODE39$1.CODE39 = undefined;
var _createClass$l = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _Barcode2$b = Barcode$1;
var _Barcode3$b = _interopRequireDefault$x(_Barcode2$b);
function _interopRequireDefault$x(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck$r(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn$n(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits$n(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// https://en.wikipedia.org/wiki/Code_39#Encoding
var CODE39 = function (_Barcode) {
_inherits$n(CODE39, _Barcode);
function CODE39(data, options) {
_classCallCheck$r(this, CODE39);
data = data.toUpperCase();
// Calculate mod43 checksum if enabled
if (options.mod43) {
data += getCharacter(mod43checksum(data));
}
return _possibleConstructorReturn$n(this, (CODE39.__proto__ || Object.getPrototypeOf(CODE39)).call(this, data, options));
}
_createClass$l(CODE39, [{
key: "encode",
value: function encode() {
// First character is always a *
var result = getEncoding("*");
// Take every character and add the binary representation to the result
for (var i = 0; i < this.data.length; i++) {
result += getEncoding(this.data[i]) + "0";
}
// Last character is always a *
result += getEncoding("*");
return {
data: result,
text: this.text
};
}
}, {
key: "valid",
value: function valid() {
return this.data.search(/^[0-9A-Z\-\.\ \$\/\+\%]+$/) !== -1;
}
}]);
return CODE39;
}(_Barcode3$b.default);
// All characters. The position in the array is the (checksum) value
var characters = ["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", "-", ".", " ", "$", "/", "+", "%", "*"];
// The decimal representation of the characters, is converted to the
// corresponding binary with the getEncoding function
var encodings = [20957, 29783, 23639, 30485, 20951, 29813, 23669, 20855, 29789, 23645, 29975, 23831, 30533, 22295, 30149, 24005, 21623, 29981, 23837, 22301, 30023, 23879, 30545, 22343, 30161, 24017, 21959, 30065, 23921, 22385, 29015, 18263, 29141, 17879, 29045, 18293, 17783, 29021, 18269, 17477, 17489, 17681, 20753, 35770];
// Get the binary representation of a character by converting the encodings
// from decimal to binary
function getEncoding(character) {
return getBinary(characterValue(character));
}
function getBinary(characterValue) {
return encodings[characterValue].toString(2);
}
function getCharacter(characterValue) {
return characters[characterValue];
}
function characterValue(character) {
return characters.indexOf(character);
}
function mod43checksum(data) {
var checksum = 0;
for (var i = 0; i < data.length; i++) {
checksum += characterValue(data[i]);
}
checksum = checksum % 43;
return checksum;
}
CODE39$1.CODE39 = CODE39;
var CODE128$2 = {};
var CODE128_AUTO = {};
var CODE128$1 = {};
var constants$2 = {};
Object.defineProperty(constants$2, "__esModule", {
value: true
});
var _SET_BY_CODE;
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
// constants for internal usage
var SET_A = constants$2.SET_A = 0;
var SET_B = constants$2.SET_B = 1;
var SET_C = constants$2.SET_C = 2;
// Special characters
constants$2.SHIFT = 98;
var START_A = constants$2.START_A = 103;
var START_B = constants$2.START_B = 104;
var START_C = constants$2.START_C = 105;
constants$2.MODULO = 103;
constants$2.STOP = 106;
constants$2.FNC1 = 207;
// Get set by start code
constants$2.SET_BY_CODE = (_SET_BY_CODE = {}, _defineProperty(_SET_BY_CODE, START_A, SET_A), _defineProperty(_SET_BY_CODE, START_B, SET_B), _defineProperty(_SET_BY_CODE, START_C, SET_C), _SET_BY_CODE);
// Get next set by code
constants$2.SWAP = {
101: SET_A,
100: SET_B,
99: SET_C
};
constants$2.A_START_CHAR = String.fromCharCode(208); // START_A + 105
constants$2.B_START_CHAR = String.fromCharCode(209); // START_B + 105
constants$2.C_START_CHAR = String.fromCharCode(210); // START_C + 105
// 128A (Code Set A)
// ASCII characters 00 to 95 (0–9, A–Z and control codes), special characters, and FNC 1–4
constants$2.A_CHARS = "[\x00-\x5F\xC8-\xCF]";
// 128B (Code Set B)
// ASCII characters 32 to 127 (0–9, A–Z, a–z), special characters, and FNC 1–4
constants$2.B_CHARS = "[\x20-\x7F\xC8-\xCF]";
// 128C (Code Set C)
// 00–99 (encodes two digits with a single code point) and FNC1
constants$2.C_CHARS = "(\xCF*[0-9]{2}\xCF*)";
// CODE128 includes 107 symbols:
// 103 data symbols, 3 start symbols (A, B and C), and 1 stop symbol (the last one)
// Each symbol consist of three black bars (1) and three white spaces (0).
constants$2.BARS = [11011001100, 11001101100, 11001100110, 10010011000, 10010001100, 10001001100, 10011001000, 10011000100, 10001100100, 11001001000, 11001000100, 11000100100, 10110011100, 10011011100, 10011001110, 10111001100, 10011101100, 10011100110, 11001110010, 11001011100, 11001001110, 11011100100, 11001110100, 11101101110, 11101001100, 11100101100, 11100100110, 11101100100, 11100110100, 11100110010, 11011011000, 11011000110, 11000110110, 10100011000, 10001011000, 10001000110, 10110001000, 10001101000, 10001100010, 11010001000, 11000101000, 11000100010, 10110111000, 10110001110, 10001101110, 10111011000, 10111000110, 10001110110, 11101110110, 11010001110, 11000101110, 11011101000, 11011100010, 11011101110, 11101011000, 11101000110, 11100010110, 11101101000, 11101100010, 11100011010, 11101111010, 11001000010, 11110001010, 10100110000, 10100001100, 10010110000, 10010000110, 10000101100, 10000100110, 10110010000, 10110000100, 10011010000, 10011000010, 10000110100, 10000110010, 11000010010, 11001010000, 11110111010, 11000010100, 10001111010, 10100111100, 10010111100, 10010011110, 10111100100, 10011110100, 10011110010, 11110100100, 11110010100, 11110010010, 11011011110, 11011110110, 11110110110, 10101111000, 10100011110, 10001011110, 10111101000, 10111100010, 11110101000, 11110100010, 10111011110, 10111101110, 11101011110, 11110101110, 11010000100, 11010010000, 11010011100, 1100011101011];
Object.defineProperty(CODE128$1, "__esModule", {
value: true
});
var _createClass$k = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _Barcode2$a = Barcode$1;
var _Barcode3$a = _interopRequireDefault$w(_Barcode2$a);
var _constants$a = constants$2;
function _interopRequireDefault$w(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck$q(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn$m(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits$m(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
// This is the master class,
// it does require the start code to be included in the string
var CODE128 = function (_Barcode) {
_inherits$m(CODE128, _Barcode);
function CODE128(data, options) {
_classCallCheck$q(this, CODE128);
// Get array of ascii codes from data
var _this = _possibleConstructorReturn$m(this, (CODE128.__proto__ || Object.getPrototypeOf(CODE128)).call(this, data.substring(1), options));
_this.bytes = data.split('').map(function (char) {
return char.charCodeAt(0);
});
return _this;
}
_createClass$k(CODE128, [{
key: 'valid',
value: function valid() {
// ASCII value ranges 0-127, 200-211
return (/^[\x00-\x7F\xC8-\xD3]+$/.test(this.data)
);
}
// The public encoding function
}, {
key: 'encode',
value: function encode() {
var bytes = this.bytes;
// Remove the start code from the bytes and set its index
var startIndex = bytes.shift() - 105;
// Get start set by index
var startSet = _constants$a.SET_BY_CODE[startIndex];
if (startSet === undefined) {
throw new RangeError('The encoding does not start with a start character.');
}
if (this.shouldEncodeAsEan128() === true) {
bytes.unshift(_constants$a.FNC1);
}
// Start encode with the right type
var encodingResult = CODE128.next(bytes, 1, startSet);
return {
text: this.text === this.data ? this.text.replace(/[^\x20-\x7E]/g, '') : this.text,
data:
// Add the start bits
CODE128.getBar(startIndex) +
// Add the encoded bits
encodingResult.result +
// Add the checksum
CODE128.getBar((encodingResult.checksum + startIndex) % _constants$a.MODULO) +
// Add the end bits
CODE128.getBar(_constants$a.STOP)
};
}
// GS1-128/EAN-128
}, {
key: 'shouldEncodeAsEan128',
value: function shouldEncodeAsEan128() {
var isEAN128 = this.options.ean128 || false;
if (typeof isEAN128 === 'string') {
isEAN128 = isEAN128.toLowerCase() === 'true';
}
return isEAN128;
}
// Get a bar symbol by index
}], [{
key: 'getBar',
value: function getBar(index) {
return _constants$a.BARS[index] ? _constants$a.BARS[index].toString() : '';
}
// Correct an index by a set and shift it from the bytes array
}, {
key: 'correctIndex',
value: function correctIndex(bytes, set) {
if (set === _constants$a.SET_A) {
var charCode = bytes.shift();
return charCode < 32 ? charCode + 64 : charCode - 32;
} else if (set === _constants$a.SET_B) {
return bytes.shift() - 32;
} else {
return (bytes.shift() - 48) * 10 + bytes.shift() - 48;
}
}
}, {
key: 'next',
value: function next(bytes, pos, set) {
if (!bytes.length) {
return { result: '', checksum: 0 };
}
var nextCode = void 0,
index = void 0;
// Special characters
if (bytes[0] >= 200) {
index = bytes.shift() - 105;
var nextSet = _constants$a.SWAP[index];
// Swap to other set
if (nextSet !== undefined) {
nextCode = CODE128.next(bytes, pos + 1, nextSet);
}
// Continue on current set but encode a special character
else {
// Shift
if ((set === _constants$a.SET_A || set === _constants$a.SET_B) && index === _constants$a.SHIFT) {
// Convert the next character so that is encoded correctly
bytes[0] = set === _constants$a.SET_A ? bytes[0] > 95 ? bytes[0] - 96 : bytes[0] : bytes[0] < 32 ? bytes[0] + 96 : bytes[0];
}
nextCode = CODE128.next(bytes, pos + 1, set);
}
}
// Continue encoding
else {
index = CODE128.correctIndex(bytes, set);
nextCode = CODE128.next(bytes, pos + 1, set);
}
// Get the correct binary encoding and calculate the weight
var enc = CODE128.getBar(index);
var weight = index * pos;
return {
result: enc + nextCode.result,
checksum: weight + nextCode.checksum
};
}
}]);
return CODE128;
}(_Barcode3$a.default);
CODE128$1.default = CODE128;
var auto = {};
Object.defineProperty(auto, "__esModule", {
value: true
});
var _constants$9 = constants$2;
// Match Set functions
var matchSetALength = function matchSetALength(string) {
return string.match(new RegExp('^' + _constants$9.A_CHARS + '*'))[0].length;
};
var matchSetBLength = function matchSetBLength(string) {
return string.match(new RegExp('^' + _constants$9.B_CHARS + '*'))[0].length;
};
var matchSetC = function matchSetC(string) {
return string.match(new RegExp('^' + _constants$9.C_CHARS + '*'))[0];
};
// CODE128A or CODE128B
function autoSelectFromAB(string, isA) {
var ranges = isA ? _constants$9.A_CHARS : _constants$9.B_CHARS;
var untilC = string.match(new RegExp('^(' + ranges + '+?)(([0-9]{2}){2,})([^0-9]|$)'));
if (untilC) {
return untilC[1] + String.fromCharCode(204) + autoSelectFromC(string.substring(untilC[1].length));
}
var chars = string.match(new RegExp('^' + ranges + '+'))[0];
if (chars.length === string.length) {
return string;
}
return chars + String.fromCharCode(isA ? 205 : 206) + autoSelectFromAB(string.substring(chars.length), !isA);
}
// CODE128C
function autoSelectFromC(string) {
var cMatch = matchSetC(string);
var length = cMatch.length;
if (length === string.length) {
return string;
}
string = string.substring(length);
// Select A/B depending on the longest match
var isA = matchSetALength(string) >= matchSetBLength(string);
return cMatch + String.fromCharCode(isA ? 206 : 205) + autoSelectFromAB(string, isA);
}
// Detect Code Set (A, B or C) and format the string
auto.default = function (string) {
var newString = void 0;
var cLength = matchSetC(string).length;
// Select 128C if the string start with enough digits
if (cLength >= 2) {
newString = _constants$9.C_START_CHAR + autoSelectFromC(string);
} else {
// Select A/B depending on the longest match
var isA = matchSetALength(string) > matchSetBLength(string);
newString = (isA ? _constants$9.A_START_CHAR : _constants$9.B_START_CHAR) + autoSelectFromAB(string, isA);
}
return newString.replace(/[\xCD\xCE]([^])[\xCD\xCE]/, // Any sequence between 205 and 206 characters
function (match, char) {
return String.fromCharCode(203) + char;
});
};
Object.defineProperty(CODE128_AUTO, "__esModule", {
value: true
});
var _CODE2$4 = CODE128$1;
var _CODE3$3 = _interopRequireDefault$v(_CODE2$4);
var _auto = auto;
var _auto2 = _interopRequireDefault$v(_auto);
function _interopRequireDefault$v(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck$p(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn$l(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits$l(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var CODE128AUTO = function (_CODE) {
_inherits$l(CODE128AUTO, _CODE);
function CODE128AUTO(data, options) {
_classCallCheck$p(this, CODE128AUTO);
// ASCII value ranges 0-127, 200-211
if (/^[\x00-\x7F\xC8-\xD3]+$/.test(data)) {
var _this = _possibleConstructorReturn$l(this, (CODE128AUTO.__proto__ || Object.getPrototypeOf(CODE128AUTO)).call(this, (0, _auto2.default)(data), options));
} else {
var _this = _possibleConstructorReturn$l(this, (CODE128AUTO.__proto__ || Object.getPrototypeOf(CODE128AUTO)).call(this, data, options));
}
return _possibleConstructorReturn$l(_this);
}
return CODE128AUTO;
}(_CODE3$3.default);
CODE128_AUTO.default = CODE128AUTO;
var CODE128A$1 = {};
Object.defineProperty(CODE128A$1, "__esModule", {
value: true
});
var _createClass$j = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _CODE2$3 = CODE128$1;
var _CODE3$2 = _interopRequireDefault$u(_CODE2$3);
var _constants$8 = constants$2;
function _interopRequireDefault$u(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck$o(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn$k(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits$k(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var CODE128A = function (_CODE) {
_inherits$k(CODE128A, _CODE);
function CODE128A(string, options) {
_classCallCheck$o(this, CODE128A);
return _possibleConstructorReturn$k(this, (CODE128A.__proto__ || Object.getPrototypeOf(CODE128A)).call(this, _constants$8.A_START_CHAR + string, options));
}
_createClass$j(CODE128A, [{
key: 'valid',
value: function valid() {
return new RegExp('^' + _constants$8.A_CHARS + '+$').test(this.data);
}
}]);
return CODE128A;
}(_CODE3$2.default);
CODE128A$1.default = CODE128A;
var CODE128B$1 = {};
Object.defineProperty(CODE128B$1, "__esModule", {
value: true
});
var _createClass$i = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _CODE2$2 = CODE128$1;
var _CODE3$1 = _interopRequireDefault$t(_CODE2$2);
var _constants$7 = constants$2;
function _interopRequireDefault$t(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck$n(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn$j(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits$j(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var CODE128B = function (_CODE) {
_inherits$j(CODE128B, _CODE);
function CODE128B(string, options) {
_classCallCheck$n(this, CODE128B);
return _possibleConstructorReturn$j(this, (CODE128B.__proto__ || Object.getPrototypeOf(CODE128B)).call(this, _constants$7.B_START_CHAR + string, options));
}
_createClass$i(CODE128B, [{
key: 'valid',
value: function valid() {
return new RegExp('^' + _constants$7.B_CHARS + '+$').test(this.data);
}
}]);
return CODE128B;
}(_CODE3$1.default);
CODE128B$1.default = CODE128B;
var CODE128C$1 = {};
Object.defineProperty(CODE128C$1, "__esModule", {
value: true
});
var _createClass$h = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _CODE2$1 = CODE128$1;
var _CODE3 = _interopRequireDefault$s(_CODE2$1);
var _constants$6 = constants$2;
function _interopRequireDefault$s(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck$m(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn$i(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits$i(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var CODE128C = function (_CODE) {
_inherits$i(CODE128C, _CODE);
function CODE128C(string, options) {
_classCallCheck$m(this, CODE128C);
return _possibleConstructorReturn$i(this, (CODE128C.__proto__ || Object.getPrototypeOf(CODE128C)).call(this, _constants$6.C_START_CHAR + string, options));
}
_createClass$h(CODE128C, [{
key: 'valid',
value: function valid() {
return new RegExp('^' + _constants$6.C_CHARS + '+$').test(this.data);
}
}]);
return CODE128C;
}(_CODE3.default);
CODE128C$1.default = CODE128C;
Object.defineProperty(CODE128$2, "__esModule", {
value: true
});
CODE128$2.CODE128C = CODE128$2.CODE128B = CODE128$2.CODE128A = CODE128$2.CODE128 = undefined;
var _CODE128_AUTO = CODE128_AUTO;
var _CODE128_AUTO2 = _interopRequireDefault$r(_CODE128_AUTO);
var _CODE128A = CODE128A$1;
var _CODE128A2 = _interopRequireDefault$r(_CODE128A);
var _CODE128B = CODE128B$1;
var _CODE128B2 = _interopRequireDefault$r(_CODE128B);
var _CODE128C = CODE128C$1;
var _CODE128C2 = _interopRequireDefault$r(_CODE128C);
function _interopRequireDefault$r(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
CODE128$2.CODE128 = _CODE128_AUTO2.default;
CODE128$2.CODE128A = _CODE128A2.default;
CODE128$2.CODE128B = _CODE128B2.default;
CODE128$2.CODE128C = _CODE128C2.default;
var EAN_UPC = {};
var EAN13$1 = {};
var constants$1 = {};
Object.defineProperty(constants$1, "__esModule", {
value: true
});
// Standard start end and middle bits
constants$1.SIDE_BIN = '101';
constants$1.MIDDLE_BIN = '01010';
constants$1.BINARIES = {
'L': [// The L (left) type of encoding
'0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111', '0001011'],
'G': [// The G type of encoding
'0100111', '0110011', '0011011', '0100001', '0011101', '0111001', '0000101', '0010001', '0001001', '0010111'],
'R': [// The R (right) type of encoding
'1110010', '1100110', '1101100', '1000010', '1011100', '1001110', '1010000', '1000100', '1001000', '1110100'],
'O': [// The O (odd) encoding for UPC-E
'0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111', '0001011'],
'E': [// The E (even) encoding for UPC-E
'0100111', '0110011', '0011011', '0100001', '0011101', '0111001', '0000101', '0010001', '0001001', '0010111']
};
// Define the EAN-2 structure
constants$1.EAN2_STRUCTURE = ['LL', 'LG', 'GL', 'GG'];
// Define the EAN-5 structure
constants$1.EAN5_STRUCTURE = ['GGLLL', 'GLGLL', 'GLLGL', 'GLLLG', 'LGGLL', 'LLGGL', 'LLLGG', 'LGLGL', 'LGLLG', 'LLGLG'];
// Define the EAN-13 structure
constants$1.EAN13_STRUCTURE = ['LLLLLL', 'LLGLGG', 'LLGGLG', 'LLGGGL', 'LGLLGG', 'LGGLLG', 'LGGGLL', 'LGLGLG', 'LGLGGL', 'LGGLGL'];
var EAN$1 = {};
var encoder = {};
Object.defineProperty(encoder, "__esModule", {
value: true
});
var _constants$5 = constants$1;
// Encode data string
var encode$1 = function encode(data, structure, separator) {
var encoded = data.split('').map(function (val, idx) {
return _constants$5.BINARIES[structure[idx]];
}).map(function (val, idx) {
return val ? val[data[idx]] : '';
});
if (separator) {
var last = data.length - 1;
encoded = encoded.map(function (val, idx) {
return idx < last ? val + separator : val;
});
}
return encoded.join('');
};
encoder.default = encode$1;
Object.defineProperty(EAN$1, "__esModule", {
value: true
});
var _createClass$g = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _constants$4 = constants$1;
var _encoder$4 = encoder;
var _encoder2$4 = _interopRequireDefault$q(_encoder$4);
var _Barcode2$9 = Barcode$1;
var _Barcode3$9 = _interopRequireDefault$q(_Barcode2$9);
function _interopRequireDefault$q(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck$l(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn$h(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits$h(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
// Base class for EAN8 & EAN13
var EAN = function (_Barcode) {
_inherits$h(EAN, _Barcode);
function EAN(data, options) {
_classCallCheck$l(this, EAN);
// Make sure the font is not bigger than the space between the guard bars
var _this = _possibleConstructorReturn$h(this, (EAN.__proto__ || Object.getPrototypeOf(EAN)).call(this, data, options));
_this.fontSize = !options.flat && options.fontSize > options.width * 10 ? options.width * 10 : options.fontSize;
// Make the guard bars go down half the way of the text
_this.guardHeight = options.height + _this.fontSize / 2 + options.textMargin;
return _this;
}
_createClass$g(EAN, [{
key: 'encode',
value: function encode() {
return this.options.flat ? this.encodeFlat() : this.encodeGuarded();
}
}, {
key: 'leftText',
value: function leftText(from, to) {
return this.text.substr(from, to);
}
}, {
key: 'leftEncode',
value: function leftEncode(data, structure) {
return (0, _encoder2$4.default)(data, structure);
}
}, {
key: 'rightText',
value: function rightText(from, to) {
return this.text.substr(from, to);
}
}, {
key: 'rightEncode',
value: function rightEncode(data, structure) {
return (0, _encoder2$4.default)(data, structure);
}
}, {
key: 'encodeGuarded',
value: function encodeGuarded() {
var textOptions = { fontSize: this.fontSize };
var guardOptions = { height: this.guardHeight };
return [{ data: _constants$4.SIDE_BIN, options: guardOptions }, { data: this.leftEncode(), text: this.leftText(), options: textOptions }, { data: _constants$4.MIDDLE_BIN, options: guardOptions }, { data: this.rightEncode(), text: this.rightText(), options: textOptions }, { data: _constants$4.SIDE_BIN, options: guardOptions }];
}
}, {
key: 'encodeFlat',
value: function encodeFlat() {
var data = [_constants$4.SIDE_BIN, this.leftEncode(), _constants$4.MIDDLE_BIN, this.rightEncode(), _constants$4.SIDE_BIN];
return {
data: data.join(''),
text: this.text
};
}
}]);
return EAN;
}(_Barcode3$9.default);
EAN$1.default = EAN;
Object.defineProperty(EAN13$1, "__esModule", {
value: true
});
var _createClass$f = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _get$1 = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _constants$3 = constants$1;
var _EAN2$2 = EAN$1;
var _EAN3$2 = _interopRequireDefault$p(_EAN2$2);
function _interopRequireDefault$p(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck$k(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn$g(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits$g(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Binary_encoding_of_data_digits_into_EAN-13_barcode
// Calculate the checksum digit
// https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Calculation_of_checksum_digit
var checksum$4 = function checksum(number) {
var res = number.substr(0, 12).split('').map(function (n) {
return +n;
}).reduce(function (sum, a, idx) {
return idx % 2 ? sum + a * 3 : sum + a;
}, 0);
return (10 - res % 10) % 10;
};
var EAN13 = function (_EAN) {
_inherits$g(EAN13, _EAN);
function EAN13(data, options) {
_classCallCheck$k(this, EAN13);
// Add checksum if it does not exist
if (data.search(/^[0-9]{12}$/) !== -1) {
data += checksum$4(data);
}
// Adds a last character to the end of the barcode
var _this = _possibleConstructorReturn$g(this, (EAN13.__proto__ || Object.getPrototypeOf(EAN13)).call(this, data, options));
_this.lastChar = options.lastChar;
return _this;
}
_createClass$f(EAN13, [{
key: 'valid',
value: function valid() {
return this.data.search(/^[0-9]{13}$/) !== -1 && +this.data[12] === checksum$4(this.data);
}
}, {
key: 'leftText',
value: function leftText() {
return _get$1(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'leftText', this).call(this, 1, 6);
}
}, {
key: 'leftEncode',
value: function leftEncode() {
var data = this.data.substr(1, 6);
var structure = _constants$3.EAN13_STRUCTURE[this.data[0]];
return _get$1(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'leftEncode', this).call(this, data, structure);
}
}, {
key: 'rightText',
value: function rightText() {
return _get$1(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'rightText', this).call(this, 7, 6);
}
}, {
key: 'rightEncode',
value: function rightEncode() {
var data = this.data.substr(7, 6);
return _get$1(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'rightEncode', this).call(this, data, 'RRRRRR');
}
// The "standard" way of printing EAN13 barcodes with guard bars
}, {
key: 'encodeGuarded',
value: function encodeGuarded() {
var data = _get$1(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'encodeGuarded', this).call(this);
// Extend data with left digit & last character
if (this.options.displayValue) {
data.unshift({
data: '000000000000',
text: this.text.substr(0, 1),
options: { textAlign: 'left', fontSize: this.fontSize }
});
if (this.options.lastChar) {
data.push({
data: '00'
});
data.push({
data: '00000',
text: this.options.lastChar,
options: { fontSize: this.fontSize }
});
}
}
return data;
}
}]);
return EAN13;
}(_EAN3$2.default);
EAN13$1.default = EAN13;
var EAN8$1 = {};
Object.defineProperty(EAN8$1, "__esModule", {
value: true
});
var _createClass$e = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _EAN2$1 = EAN$1;
var _EAN3$1 = _interopRequireDefault$o(_EAN2$1);
function _interopRequireDefault$o(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck$j(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn$f(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits$f(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// http://www.barcodeisland.com/ean8.phtml
// Calculate the checksum digit
var checksum$3 = function checksum(number) {
var res = number.substr(0, 7).split('').map(function (n) {
return +n;
}).reduce(function (sum, a, idx) {
return idx % 2 ? sum + a : sum + a * 3;
}, 0);
return (10 - res % 10) % 10;
};
var EAN8 = function (_EAN) {
_inherits$f(EAN8, _EAN);
function EAN8(data, options) {
_classCallCheck$j(this, EAN8);
// Add checksum if it does not exist
if (data.search(/^[0-9]{7}$/) !== -1) {
data += checksum$3(data);
}
return _possibleConstructorReturn$f(this, (EAN8.__proto__ || Object.getPrototypeOf(EAN8)).call(this, data, options));
}
_createClass$e(EAN8, [{
key: 'valid',
value: function valid() {
return this.data.search(/^[0-9]{8}$/) !== -1 && +this.data[7] === checksum$3(this.data);
}
}, {
key: 'leftText',
value: function leftText() {
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'leftText', this).call(this, 0, 4);
}
}, {
key: 'leftEncode',
value: function leftEncode() {
var data = this.data.substr(0, 4);
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'leftEncode', this).call(this, data, 'LLLL');
}
}, {
key: 'rightText',
value: function rightText() {
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'rightText', this).call(this, 4, 4);
}
}, {
key: 'rightEncode',
value: function rightEncode() {
var data = this.data.substr(4, 4);
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'rightEncode', this).call(this, data, 'RRRR');
}
}]);
return EAN8;
}(_EAN3$1.default);
EAN8$1.default = EAN8;
var EAN5$1 = {};
Object.defineProperty(EAN5$1, "__esModule", {
value: true
});
var _createClass$d = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _constants$2 = constants$1;
var _encoder$3 = encoder;
var _encoder2$3 = _interopRequireDefault$n(_encoder$3);
var _Barcode2$8 = Barcode$1;
var _Barcode3$8 = _interopRequireDefault$n(_Barcode2$8);
function _interopRequireDefault$n(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck$i(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn$e(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits$e(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// https://en.wikipedia.org/wiki/EAN_5#Encoding
var checksum$2 = function checksum(data) {
var result = data.split('').map(function (n) {
return +n;
}).reduce(function (sum, a, idx) {
return idx % 2 ? sum + a * 9 : sum + a * 3;
}, 0);
return result % 10;
};
var EAN5 = function (_Barcode) {
_inherits$e(EAN5, _Barcode);
function EAN5(data, options) {
_classCallCheck$i(this, EAN5);
return _possibleConstructorReturn$e(this, (EAN5.__proto__ || Object.getPrototypeOf(EAN5)).call(this, data, options));
}
_createClass$d(EAN5, [{
key: 'valid',
value: function valid() {
return this.data.search(/^[0-9]{5}$/) !== -1;
}
}, {
key: 'encode',
value: function encode() {
var structure = _constants$2.EAN5_STRUCTURE[checksum$2(this.data)];
return {
data: '1011' + (0, _encoder2$3.default)(this.data, structure, '01'),
text: this.text
};
}
}]);
return EAN5;
}(_Barcode3$8.default);
EAN5$1.default = EAN5;
var EAN2$1 = {};
Object.defineProperty(EAN2$1, "__esModule", {
value: true
});
var _createClass$c = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _constants$1 = constants$1;
var _encoder$2 = encoder;
var _encoder2$2 = _interopRequireDefault$m(_encoder$2);
var _Barcode2$7 = Barcode$1;
var _Barcode3$7 = _interopRequireDefault$m(_Barcode2$7);
function _interopRequireDefault$m(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck$h(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn$d(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits$d(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// https://en.wikipedia.org/wiki/EAN_2#Encoding
var EAN2 = function (_Barcode) {
_inherits$d(EAN2, _Barcode);
function EAN2(data, options) {
_classCallCheck$h(this, EAN2);
return _possibleConstructorReturn$d(this, (EAN2.__proto__ || Object.getPrototypeOf(EAN2)).call(this, data, options));
}
_createClass$c(EAN2, [{
key: 'valid',
value: function valid() {
return this.data.search(/^[0-9]{2}$/) !== -1;
}
}, {
key: 'encode',
value: function encode() {
// Choose the structure based on the number mod 4
var structure = _constants$1.EAN2_STRUCTURE[parseInt(this.data) % 4];
return {
// Start bits + Encode the two digits with 01 in between
data: '1011' + (0, _encoder2$2.default)(this.data, structure, '01'),
text: this.text
};
}
}]);
return EAN2;
}(_Barcode3$7.default);
EAN2$1.default = EAN2;
var UPC$1 = {};
Object.defineProperty(UPC$1, "__esModule", {
value: true
});
var _createClass$b = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
UPC$1.checksum = checksum$1;
var _encoder$1 = encoder;
var _encoder2$1 = _interopRequireDefault$l(_encoder$1);
var _Barcode2$6 = Barcode$1;
var _Barcode3$6 = _interopRequireDefault$l(_Barcode2$6);
function _interopRequireDefault$l(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck$g(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn$c(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits$c(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// https://en.wikipedia.org/wiki/Universal_Product_Code#Encoding
var UPC = function (_Barcode) {
_inherits$c(UPC, _Barcode);
function UPC(data, options) {
_classCallCheck$g(this, UPC);
// Add checksum if it does not exist
if (data.search(/^[0-9]{11}$/) !== -1) {
data += checksum$1(data);
}
var _this = _possibleConstructorReturn$c(this,