Open Barcode for JavaScript
An ES module package with a subpath export for linear barcodes. Works in Node.js and in browsers.
Install
npm install @openbarcode/javascriptGenerate a barcode
import { UPC } from "@openbarcode/javascript/linear";
const bars = new UPC("03600029145").barcode(); // 95 modulesThe example encodes UPC-A 03600029145, which gets check digit 2 and produces 95 modules. The same input gives the same modules in every Open Barcode library.
More examples
Each example uses the same modules as the tests, so the output matches the other languages.
import { UPC, EAN, Code39 } from "@openbarcode/javascript/linear";
const upc = new UPC("03600029145").barcode(); // 95 modules
const ean = new EAN("400638133393").barcode(); // 95 modules
const code39 = new Code39("CODE39").barcode(); // 103 modulesimport { UPC } from "@openbarcode/javascript/linear";
try {
new UPC("036000291453"); // the check digit should be 2
} catch (err) {
console.error(err.message);
}Source and tests
The source, tests and release workflow are in the JavaScript repository on GitHub.