12 KiB
@suaveplan/barcode - Barcode generation and parsing for common 1D symbologies: Code 128, Code 39, EAN-13, EAN-8, UPC-A, UPC-E, ITF. Outputs SVG strings and pixel arrays.
Summary
Runtime-agnostic 1D barcode generation for seven symbologies — Code 128B, Code 39, EAN-13, EAN-8, UPC-A, UPC-E, and ITF. Outputs inline SVG strings and binary bar-pattern arrays with no canvas, no DOM, and no Node.js built-ins required, making it safe to use in Bun, Deno, edge runtimes, and browsers alike. Includes check-digit calculation, barcode validation, and human-readable text rendering. Use this package to generate product labels, shipping labels (ITF/GTIN-14), retail barcodes (EAN/UPC), and document barcodes (Code 128). For 2D barcodes (QR codes) use @suaveplan/qrcode. This package does not support barcode scanning/decoding from images — it is generation-only.
Documentation tree
- encoder — (no submodules)
- encoder — (no submodules)
- validator — (no submodules)
- validator — (no submodules)
- errors — (no submodules)
- barcode-error — (no submodules)
- code128 — Implements Code 128 Subset B encoding for the full printable ASCII range (characters 32–127). This module produces a bi…
- code39 — Implements Code 39 barcode encoding for the standard 43-character set: digits 0–9, uppercase letters A–Z, and the speci…
- ean13 — Implements EAN-13 (International Article Number, 13-digit variant) barcode encoding following the ISO/IEC 15420 and GS1…
- ean8 — Implements EAN-8 barcode encoding for small retail packages where space constraints make EAN-13 impractical. EAN-8 enco…
- itf — Implements ITF (Interleaved 2 of 5) barcode encoding for numeric-only data. ITF is widely used in logistics, shipping,…
- upca — Implements UPC-A barcode encoding and validation. UPC-A is the primary barcode format used in North American retail, en…
- upce — Implements UPC-E barcode encoding for the compressed 6-digit UPC symbology used on small retail packages where space fo…
- code39 — Implements Code 39 barcode encoding for the standard 43-character set: digits 0–9, uppercase letters A–Z, and the speci…
- ean13 — Implements EAN-13 (International Article Number, 13-digit variant) barcode encoding following the ISO/IEC 15420 and GS1…
- ean8 — Implements EAN-8 barcode encoding for small retail packages where space constraints make EAN-13 impractical. EAN-8 enco…
- itf — Implements ITF (Interleaved 2 of 5) barcode encoding for numeric-only data. ITF is widely used in logistics, shipping,…
- upca — Implements UPC-A barcode encoding and validation. UPC-A is the primary barcode format used in North American retail, en…
- upce — Implements UPC-E barcode encoding for the compressed 6-digit UPC symbology used on small retail packages where space fo…
- encoder — (no submodules)- validator — (no submodules)- validator — (no submodules)- errors — (no submodules)- barcode-error — (no submodules)- code128 — Implements Code 128 Subset B encoding for the full printable ASCII range (characters 32–127). This module produces a bi…
- code39 — Implements Code 39 barcode encoding for the standard 43-character set: digits 0–9, uppercase letters A–Z, and the speci…
- ean13 — Implements EAN-13 (International Article Number, 13-digit variant) barcode encoding following the ISO/IEC 15420 and GS1…
- ean8 — Implements EAN-8 barcode encoding for small retail packages where space constraints make EAN-13 impractical. EAN-8 enco…
- itf — Implements ITF (Interleaved 2 of 5) barcode encoding for numeric-only data. ITF is widely used in logistics, shipping,…
- upca — Implements UPC-A barcode encoding and validation. UPC-A is the primary barcode format used in North American retail, en…
- upce — Implements UPC-E barcode encoding for the compressed 6-digit UPC symbology used on small retail packages where space fo…
- encoder — (no submodules)- validator — (no submodules)- validator — (no submodules)- errors — (no submodules)- barcode-error — (no submodules)- code128 — Implements Code 128 Subset B encoding for the full printable ASCII range (characters 32–127). This module produces a bi…
- code39 — Implements Code 39 barcode encoding for the standard 43-character set: digits 0–9, uppercase letters A–Z, and the speci…
- ean13 — Implements EAN-13 (International Article Number, 13-digit variant) barcode encoding following the ISO/IEC 15420 and GS1…
- ean8 — Implements EAN-8 barcode encoding for small retail packages where space constraints make EAN-13 impractical. EAN-8 enco…
- itf — Implements ITF (Interleaved 2 of 5) barcode encoding for numeric-only data. ITF is widely used in logistics, shipping,…
- upca — Implements UPC-A barcode encoding and validation. UPC-A is the primary barcode format used in North American retail, en…
- upce — Implements UPC-E barcode encoding for the compressed 6-digit UPC symbology used on small retail packages where space fo…
- encoder — (no submodules)- validator — (no submodules) - validator — (no submodules)- errors — (no submodules) - barcode-error — (no submodules)- code128 — Implements Code 128 Subset B encoding for the full printable ASCII range (characters 32–127). This module produces a bi…
- code39 — Implements Code 39 barcode encoding for the standard 43-character set: digits 0–9, uppercase letters A–Z, and the speci…
- ean13 — Implements EAN-13 (International Article Number, 13-digit variant) barcode encoding following the ISO/IEC 15420 and GS1…
- ean8 — Implements EAN-8 barcode encoding for small retail packages where space constraints make EAN-13 impractical. EAN-8 enco…
- itf — Implements ITF (Interleaved 2 of 5) barcode encoding for numeric-only data. ITF is widely used in logistics, shipping,…
- upca — Implements UPC-A barcode encoding and validation. UPC-A is the primary barcode format used in North American retail, en…
- upce — Implements UPC-E barcode encoding for the compressed 6-digit UPC symbology used on small retail packages where space fo…
Symbologies
| Symbology | Key | Description |
|---|---|---|
| Code 128B | code128 |
ASCII 32–127; variable length; most versatile 1D format |
| Code 39 | code39 |
0–9, A–Z, special chars; industrial/logistics |
| EAN-13 | ean13 |
13-digit retail standard (ISBN-13, ISSN-13) |
| EAN-8 | ean8 |
8-digit compact retail for small packages |
| UPC-A | upca |
12-digit North American retail |
| UPC-E | upce |
8-digit compressed UPC-A for small packages |
| ITF | itf |
Interleaved 2 of 5; even-digit numeric; logistics/GTIN-14 |
Install
bun add @suaveplan/barcode
Quick Start
import { encode } from "@suaveplan/barcode";
const result = encode("Hello World", "code128");
console.log(result.svg); // <svg ...>...</svg>
console.log(result.width); // pixel width
API
encode(data, symbology, options?): BarcodeResult
Main encoding function. Dispatches to the per-symbology encoder and renders an SVG.
import { encode } from "@suaveplan/barcode";
const result = encode("5901234123457", "ean13", {
width: 3, // bar width multiplier (default 2)
height: 80, // bar height in pixels (default 100)
margin: 15, // quiet zone (default 10)
includeText: true, // render human-readable text (default true)
color: "#000000",
background: "#ffffff",
});
validateBarcode(data, symbology): boolean
import { validateBarcode } from "@suaveplan/barcode";
validateBarcode("5901234123457", "ean13"); // true
calculateCheckDigit(data, symbology): string
import { calculateCheckDigit } from "@suaveplan/barcode";
calculateCheckDigit("590123412345", "ean13"); // "7"
parse(data, symbology): ParseResult
import { parse } from "@suaveplan/barcode";
const r = parse("5901234123457", "ean13");
// { symbology: "ean13", data: "...", valid: true, checkDigit: "7" }
Module Docs
src/errors/barcode-error.md— Error class and code registrysrc/symbologies/code128.md— Code 128B encodingsrc/symbologies/code39.md— Code 39 encodingsrc/symbologies/ean13.md— EAN-13 encodingsrc/symbologies/ean8.md— EAN-8 encodingsrc/symbologies/upca.md— UPC-A encodingsrc/symbologies/upce.md— UPC-E encodingsrc/symbologies/itf.md— ITF encodingsrc/core/encoder/encoder.md— Central encoder and SVG renderersrc/core/validator/validator.md— Validation and parsing facade