Open Barcode for JavaScript

An ES module package with a subpath export for linear barcodes. Works in Node.js and in browsers.

Package registrynpm
RuntimeNode.js 18 or newer, and modern browsers as ES modules
LicenseApache-2.0

Install

Installbash
npm install @openbarcode/javascript

Generate a barcode

Examplejavascript
import { UPC } from "@openbarcode/javascript/linear";
const bars = new UPC("03600029145").barcode(); // 95 modules

The 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.

Three barcode typesjavascript
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 modules
Wrong check digitjavascript
import { 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.

Other languages