Canvas-rendered barcodes blur at odd scaling factors inside thermal printers or PDF shipping labels. Emitting standalone vector <svg> rectangles directly from binary module bitstreams avoids Canvas, DOM APIs, and image artifacts while remaining lightweight for browser workers and Node CLIs.
We open-sourced the encoder powering the Sunasty Barcode Generator and CSV Label Sheet Builder as barcode128-svg on npm and JSR (@sunasty/code128-svg).
1. Automatic Subset B vs. Dense Numeric Subset C + Mod-103 Checksum
When an input payload contains four or more even-count digits, switching to Start Code C (105) packs two digits (00..99) per symbol instead of one character in Start Code B (104), halving barcode width while computing the weighted Mod-103 checksum:
export function computeCode128Checksum(text) {
const { startSymbol, dataValues } = resolveCode128Payload(text);
let sum = startSymbol;
for (let i = 0; i < dataValues.length; i += 1) {
sum += dataValues[i] * (i + 1);
}
return sum % 103;
}
2. Run-Length Merged Vector Bars & Bulk Label Batching
Instead of outputting separate 1-module <rect> nodes, modulesToBarSegments merges adjacent black bars before rendering crisp SVG rectangles (including optional ITF-14 GS1 bearer frames and quiet zones):
import { renderBarcodeSvg, parseBulkBarcodeText, buildBulkBarcodeZipEntries } from 'barcode128-svg';
const svg = renderBarcodeSvg('code128', 'ORD-2026-0042', {
moduleWidth: 2,
barHeight: 90,
quietZone: 11,
showText: true,
});
const items = parseBulkBarcodeText('ean13,400638133393\nSKU-9981-A');
const entries = buildBulkBarcodeZipEntries(items);
Web Tools & Registry Links
- SVG & PNG Barcode Generator: https://sunasty.com/barcode-generator/
- Shipping Label Sheet & QR Suite: https://sunasty.com/csv-label-sheet/, https://sunasty.com/qr-code/, https://sunasty.com/qr-scan/
- Source & packages: GitHub · npm · JSR
Top comments (0)