JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 506
  • Score
    100M100P100Q92936F
  • License MIT

Zero-dependency barcode & QR code SVG generator. 20+ formats, styled QR codes, tree-shakeable. Pure TypeScript, works everywhere.

Package Exports

  • etiket
  • etiket/aztec
  • etiket/barcode
  • etiket/datamatrix
  • etiket/pdf417
  • etiket/qr

Readme


etiket

Zero-dependency barcode & QR code SVG generator.
20+ formats, styled QR codes, tree-shakeable. Pure TypeScript, works everywhere.

npm version npm downloads bundle size license

Quick Start

npm install etiket
import { barcode, qrcode } from "etiket";

const svg = barcode("Hello World");
const qr = qrcode("https://example.com", { dotType: "dots", ecLevel: "H" });

CLI

npx etiket qr "Hello World" -o qr.svg
npx etiket qr "Hello" --terminal
npx etiket qr "Hello" --size 300 --ec H --dot-type dots
npx etiket barcode "4006381333931" --type ean13 --show-text -o barcode.svg
npx etiket datamatrix "Hello" -o dm.svg
npx etiket pdf417 "Hello" -o pdf.svg
npx etiket aztec "Hello" -o aztec.svg
npx etiket wifi "MyNetwork" "secret123" -o wifi.svg

Tree Shaking

Import only what you need:

import { barcode } from "etiket/barcode"; // 1D barcodes only
import { qrcode } from "etiket/qr"; // QR codes only
import { datamatrix } from "etiket/datamatrix";
import { pdf417 } from "etiket/pdf417";
import { aztec } from "etiket/aztec";

Supported Formats

1D Barcodes

Format Type Description
Code 128 code128 Auto charset (A/B/C)
Code 39 code39 43-char set, optional check
Code 39 Ext code39ext Full ASCII
Code 93 code93 Higher density, 2 check digits
Code 93 Ext code93ext Full ASCII
EAN-13 ean13 Auto check digit
EAN-8 ean8 Auto check digit
EAN-5 ean5 Addon (book price)
EAN-2 ean2 Addon (issue number)
UPC-A upca 12-digit, auto check digit
UPC-E upce Compressed 8-digit
ITF itf Interleaved 2 of 5
ITF-14 itf14 14-digit with bearer bars
Codabar codabar Libraries, blood banks
MSI Plessey msi Mod10/11/1010/1110
Pharmacode pharmacode Pharmaceutical
Code 11 code11 Telecommunications
GS1-128 gs1-128 AI parsing, FNC1

2D Codes

Format Function Description
QR Code qrcode() Versions 1-40, all EC levels, all modes
Data Matrix datamatrix() ECC 200, 24 square + 6 rectangular sizes
PDF417 pdf417() Text/Byte/Numeric compaction, 9 EC levels
Aztec aztec() Compact + full-range, no quiet zone

Usage

Barcodes

import { barcode } from "etiket";

barcode("Hello World"); // Code 128 (default)
barcode("4006381333931", { type: "ean13", showText: true });
barcode("00012345678905", { type: "itf14", bearerBars: true });
barcode("(01)12345678901234(17)260101", { type: "gs1-128" });
barcode("HELLO", { type: "code39", code39CheckDigit: true });
Option Type Default Description
type BarcodeType 'code128' Barcode format
height number 80 Bar height in pixels
barWidth number 2 Width multiplier per module
color string '#000' Bar color
background string '#fff' Background color
showText boolean false Show human-readable text
textPosition 'bottom' | 'top' 'bottom' Text position
fontSize number 14 Text font size
fontFamily string 'monospace' Text font family
margin number 10 Margin around barcode
marginTop number margin Top margin
marginBottom number margin Bottom margin
marginLeft number margin Left margin
marginRight number margin Right margin
textAlign 'center' | 'left' | 'right' 'center' Text alignment
rotation 0 | 90 | 180 | 270 0 Barcode rotation
bearerBars boolean false Bearer bars (ITF-14)

QR Codes

import { qrcode } from "etiket";

qrcode("https://example.com");
qrcode("Hello", { size: 300, ecLevel: "H", dotType: "rounded" });

// With gradient
qrcode("Test", {
  color: {
    type: "linear",
    rotation: 45,
    stops: [
      { offset: 0, color: "#ff0000" },
      { offset: 1, color: "#0000ff" },
    ],
  },
});

// With corner styling
qrcode("Test", {
  dotType: "dots",
  corners: {
    topLeft: { outerShape: "rounded", innerShape: "dots", outerColor: "#ff0000" },
    topRight: { outerShape: "extra-rounded" },
    bottomLeft: { outerShape: "dots" },
  },
});
Option Type Default Description
size number 200 SVG size in pixels
ecLevel 'L' | 'M' | 'Q' | 'H' 'M' Error correction level
version number auto QR version (1-40)
mode 'numeric' | 'alphanumeric' | 'byte' | 'auto' 'auto' Encoding mode
mask 0-7 auto Mask pattern
color string | GradientOptions '#000' Module color
background string | GradientOptions '#fff' Background color
margin number 4 Quiet zone in modules
dotType DotType 'square' Module shape
dotSize number 1 Module size (0.1-1)
shape 'square' | 'circle' 'square' Overall QR shape
corners object Finder pattern styling
logo LogoOptions Center logo embedding
xmlDeclaration boolean false Add XML declaration

Dot types: square, rounded, dots, diamond, classy, classy-rounded, extra-rounded, vertical-line, horizontal-line, small-square, tiny-square

2D Codes

import { datamatrix, pdf417, aztec } from "etiket";

datamatrix("Hello World");
pdf417("Hello World", { ecLevel: 4, columns: 5 });
aztec("Hello World", { ecPercent: 33 });

Output Formats

import {
  barcode,
  qrcode,
  barcodeDataURI,
  qrcodeDataURI,
  barcodeBase64,
  qrcodeBase64,
  qrcodeTerminal,
} from "etiket";

const svg = qrcode("Hello"); // SVG string
const uri = qrcodeDataURI("Hello"); // data:image/svg+xml,...
const b64 = qrcodeBase64("Hello"); // data:image/svg+xml;base64,...
const term = qrcodeTerminal("Hello"); // Terminal (UTF-8 blocks)

Convenience Helpers

import { wifi, email, sms, geo, url, phone, vcard, mecard, event } from "etiket";

wifi("MyNetwork", "password123"); // WiFi QR
email("test@example.com"); // mailto: QR
sms("+1234567890", "Hello!"); // SMS QR
geo(37.7749, -122.4194); // Location QR
url("https://example.com"); // URL QR
phone("+1234567890"); // tel: QR

// vCard QR
vcard({
  firstName: "John",
  lastName: "Doe",
  phone: "+1234567890",
  email: "john@example.com",
  org: "Acme Inc",
});

// MeCard QR (simpler, used by Android)
mecard({ name: "John Doe", phone: "+1234567890", email: "john@example.com" });

// Calendar event QR
event({
  title: "Meeting",
  start: "2026-04-01T10:00:00",
  end: "2026-04-01T11:00:00",
  location: "Office",
});

Validation

import { validateBarcode, isValidInput, validateQRInput } from "etiket";

validateBarcode("4006381333931", "ean13"); // { valid: true }
validateBarcode("ABC", "ean13"); // { valid: false, error: '...' }
isValidInput("HELLO", "code39"); // true

Swiss QR Code

Generate QR-bill payment codes (mandatory in Switzerland since 2022):

import { swissQR } from "etiket";

swissQR({
  iban: "CH4431999123000889012",
  creditor: { name: "Max Muster", postalCode: "8000", city: "Zürich", country: "CH" },
  amount: 1949.75,
  currency: "CHF",
  reference: "210000000003139471430009017",
  referenceType: "QRR",
});

Raw Encoders

Access encoding functions directly for custom rendering:

import {
  encodeCode128,
  encodeEAN13,
  encodeQR,
  encodeDataMatrix,
  encodePDF417,
  encodeAztec,
  renderBarcodeSVG,
  renderQRCodeSVG,
  renderMatrixSVG,
} from "etiket";

const bars = encodeCode128("data"); // number[] (bar/space widths)
const matrix = encodeQR("data"); // boolean[][] (QR matrix)
const dm = encodeDataMatrix("data"); // boolean[][] (Data Matrix)

const svg = renderBarcodeSVG(bars, { height: 100 });
const qrSvg = renderQRCodeSVG(matrix, { size: 400, dotType: "dots" });

Features

  • Zero dependencies
  • Pure ESM
  • TypeScript-first with strict types
  • Tree-shakeable sub-path exports
  • CLI tool (npx etiket)
  • SVG string output (no DOM required)
  • Works in browser, Node.js, Deno, Bun, workers
  • ~24KB gzipped (full bundle)

Comparison

Feature etiket uqr bwip-js JsBarcode qr-code-styling
Zero dependencies ❌ (1.5MB+) ❌ (xmldom) ❌ (qrcode)
TypeScript-first Partial
Tree-shakeable
1D barcodes (18 types) ✅ (100+) ✅ (13)
QR Code (v1-40, all EC)
Data Matrix
PDF417
Aztec Code
QR dot styling (12 types)
QR gradients
QR corner styling
QR logo embedding
CLI tool
Terminal output
Convenience helpers (WiFi, vCard...)
Input validation
SVG output
PNG/Canvas output
Pure ESM ❌ (CJS) ❌ (CJS) ❌ (CJS)
Bundle size (gzip) ~24KB ~12KB ~160KB ~15KB ~30KB+deps

etiket is the only library that combines 1D barcodes + 2D codes + styled QR codes + zero dependencies + tree-shaking in a single package.

Inspiration & Credits

Built from scratch, inspired by these excellent libraries:

  • uqr — Pure SVG QR approach, terminal rendering
  • bwip-js — Comprehensive barcode format reference (100+ types)
  • JsBarcode — Encoding table validation, barcode rendering patterns
  • qr-code-styling — QR styling concepts (dot types, gradients, corners, logos)

Standards: ISO/IEC 15417 (Code 128), ISO/IEC 15420 (EAN/UPC), ISO/IEC 18004 (QR), ISO/IEC 16022 (Data Matrix), ISO/IEC 15438 (PDF417), ISO/IEC 24778 (Aztec).

License

Published under the MIT license.