UNPKG

@darthmaim/barcode

Version:
44 lines 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.encode = exports.isValid = void 0; const ean13_1 = require("./ean13"); const ean8_1 = require("./ean8"); function getFormat(format, data) { if (format !== 'auto') { return format; } return data.length === 13 ? 'ean13' : data.length === 8 ? 'ean8' : undefined; } function isValid(data, { format = 'auto' } = {}) { const encodeFormat = getFormat(format, data); if (!encodeFormat) { throw new Error(`Unable to determine format of EAN value`); } if (encodeFormat === 'ean13') { return (0, ean13_1.isValid)(data); } else if (encodeFormat === 'ean8') { return (0, ean8_1.isValid)(data); } else { throw Error(`Format ${encodeFormat} not supported`); } } exports.isValid = isValid; function encode(data, { format = 'auto' } = {}) { const encodeFormat = getFormat(format, data); if (!encodeFormat) { throw new Error(`Unable to determine format of EAN value`); } if (encodeFormat === 'ean13') { return (0, ean13_1.encode)(data); } else if (encodeFormat === 'ean8') { return (0, ean8_1.encode)(data); } else { throw Error(`Format ${encodeFormat} not supported`); } } exports.encode = encode; //# sourceMappingURL=index.js.map