Skip to content

About

Open Barcode for JavaScript: barcode generation library (Code 39, EAN, UPC)

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

10 Commits

Folders and files

Repository files navigation

Open Barcode by Floms

Barcodes, made open.

Open Barcode for JavaScript

Barcode generation library for JavaScript (Code 39, EAN, UPC).

The library has no runtime dependencies. It runs on Node.js 18 and later and in modern browsers, as an ES module.

Install

npm install @openbarcode/javascript

Usage

The package is ES-module only. Use import in Node.js, or <script type="module"> in the browser. require() is not supported.

In Node.js:

import { UPC, EAN, Code39 } from '@openbarcode/javascript/linear';

const upc = new UPC('03600029145');  // 11 digits: the check digit is computed
upc.code();                          // '036000291452'
upc.barcode();                       // [1, 0, 1, 0, 0, 0, 1, 1, ...] (95 modules)

new EAN('4006381333931');            // 13 digits: the check digit is verified
new Code39('Hello World');           // stored as 'HELLO WORLD'

In the browser, import the module directly from a CDN:

<script type="module">
  import { UPC } from 'https://cdn.jsdelivr.net/npm/@openbarcode/javascript@2.0.0/src/linear/index.js';

  const modules = new UPC('03600029145').barcode();
  // Draw each module: 1 = bar, 0 = space.
</script>

API

The linear (one-dimensional) barcodes are exported from @openbarcode/javascript/linear.

  • new UPC(code): UPC-A. Accepts 11 digits (the check digit is computed) or 12 digits (the check digit is verified).
  • new EAN(code): EAN-13. Accepts 12 digits (the check digit is computed) or 13 digits (the check digit is verified).
  • new Code39(text): Code 39. Lowercase letters are uppercased. Allowed characters are 0-9, A-Z, space, -, ., $, /, + and %.
  • barcode(): returns a new array of 0 and 1 values, where 1 is a bar and 0 is a space.
  • code(): returns the full code text, including the check digit.

Invalid input throws an Error. A non-string argument throws a TypeError.

Testing

npm test

The tests use Node's built-in test runner (node --test), so there is nothing to install beyond the package itself. CI runs them on Node.js 18, 20 and 22.

Open Barcode in other languages

Open Barcode is available in several languages:

Project homepage: https://openbarcode.dev

This repository was split from the original multi-language project at https://github.com/floms/Open-Barcode. The commit history was preserved with git-filter-repo; commit hashes differ from the original.

Copyright 2013 Floms, LLC. (Yoel Nunez)

Copyright 2026 Floms, Inc.

Licensed under the Apache License, Version 2.0. See LICENSE.md for details.

About

Open Barcode for JavaScript: barcode generation library (Code 39, EAN, UPC)

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages