JSFiddle - React, Tailwind, and code Playground

by Eric Miller

JavaScript

/**
 * Barcode Utilitry Class
 * @class
 * @property {string} _barcode - The barcode string
 * @property {string} ai - The GTIN Application Identiifer
 * @property {string} gtin - The GTIN-14 Product Lot Table
 * @property {string} exp_date_ai - The Exp Date AI
 * @property {string} exp_date - The Exp Date (format: YYMMDD)
 * @property {string} log_number_ai - The lot Number AI
 * @property {string} lot_number - The Lot Number
 * @property {string} serial_number_ai - The Serial Number AI
 * @property {string} serial_number - The Serial Number
 * @property {string} ai_regex - The GTIN Application Identiifer regex
 * @property {string} gtin_regex - The GTIN-14 Product Lot Table regex
 * @property {string} exp_date_ai_regex - The Exp Date AI regex
 * @property {string} exp_date_regex - The Exp Date (format: YYMMDD) regex
 * @property {string} log_number_ai_regex - The lot Number AI regex
 * @property {string} lot_number_regex - The Lot Number regex
 * @property {string} serial_number_ai_regex - The Serial Number AI regex
 * @property {string} serial_number_regex - The Serial Number regex
 * @property {string} DEFAULT_FORMAT - The default barcode format regex
 * @method _decode - Decode the barcode string
 * @method isValid - Determine if the barcode is valid
*/
class Barcode {
    _barcode;
    
    ai; //  GTIN Application Identiifer
    ai_regex = /^([0-9]{2})/;
    gtin; // ([0-9]{14}) GTIN-14 PRoduct Lot Table
    gtin_regex = /^(?:.{2})([0-9]{14})/;
    exp_date_ai; // ([0-9]{2}) EXp Date AI
    exp_date_ai_regex = /^(?:.{16})([0-9]{2})/;
    exp_date; // ([0-9]{6}) Exp Date (format: YYMMDD)
    exp_date_regex = /^(?:.{18})([0-9]{6})/;
    log_number_ai;// ([0-9]{2}) lot Number AI
    log_number_ai_regex = /^(?:.{24})([0-9]{2})/;
    lot_number; // ([0-9]{7}) Lot Number
    lot_number_regex = /^(?:.{26})([0-9]{7})/;
    serial_number_ai; // ([0-9]{2}) Serial Number AI
    serial_number_ai_regex = /^(?:.{33})([0-9]{2})/;
    serial_number; // ([0-9]{0,20})...