條形碼生成器:JavaScript 程式庫
18 種條形碼(Code 128、Code 39、EAN、UPC、ITF、MSI、Pharmacode、Codabar),支援標籤文字、校驗位、批次編號、CSV 和可列印標籤頁。可匯出為 SVG、PNG、JPEG、WebP、PDF 和 ZIP。
@openlibsdev/barcode-generator- v1.0.0
- ES module
- MIT
安裝
使用打包工具或 Node 風格的匯入:
npm install @openlibsdev/barcode-generatorimport BarcodeGenerator from "@openlibsdev/barcode-generator";或直接在頁面中使用,無須建置(jsDelivr 會解析相依套件):
<script type="module">
import BarcodeGenerator from "https://cdn.jsdelivr.net/npm/@openlibsdev/barcode-generator@1.0.0/+esm";
</script>用法
import BarcodeGenerator from "@openlibsdev/barcode-generator";
const s = BarcodeGenerator.normalize({ format: "EAN13", data: "590123412345" });
console.log(BarcodeGenerator.isValid(s, s.data)); // true
const svg = BarcodeGenerator.svgFor(s, s.data); // SVG markup as a string
document.body.insertAdjacentHTML("beforeend", svg);
await BarcodeGenerator.exportFile(s, "png"); // downloads the fileAPI
BarcodeGenerator.normalize(input)
由部分設定物件生成完整設定:缺少的欄位使用預設值。
BarcodeGenerator.isValid(s, value)
按所選條碼型別校驗數值(長度、字元、校驗位)。
BarcodeGenerator.svgFor(s, value)
帶標籤文字的條形碼,SVG 標記形式。
BarcodeGenerator.drawSVG(s, value, svg)
在已有的 <svg> 元素中繪製條形碼。
BarcodeGenerator.canvasFor(s, value, opts)
<canvas> 形式的條形碼。
BarcodeGenerator.exportFile(s, kind, opts)
下載單個條碼或整批:svg、png、jpeg、webp、pdf、zip。
BarcodeGenerator.printLayout(s)
生成用於列印的標籤頁。
BarcodeGenerator.values(s)
整批的所有數值:單個值、列表或自動編號。
BarcodeGenerator.autonumber(o)
從起始值按步長和字首生成編號。
BarcodeGenerator.csvValues(text)
從 CSV 文字讀取數值。
BarcodeGenerator.toCsv(vals)
將數值寫為 CSV 文字。
BarcodeGenerator.contrastOk(s)
條和背景的顏色對比度是否足以被掃描器識別。
BarcodeGenerator.FORMATS
條形碼型別及其規則。
BarcodeGenerator.PRESETS
現成的標籤樣式。
BarcodeGenerator.DEFAULTS
預設設定。
BarcodeGenerator.findNamedColor(text, lang)
按指定語言的顏色名稱查詢命名顏色(“深藍色”→ #00008b)。
BarcodeGenerator.listNamedColors(lang)
列出命名顏色及其在指定語言中的名稱。
BarcodeGenerator.APP
庫的名稱、版本和釋出日期:{name, version, created}。
BarcodeGenerator.BACKDROPS
按 id 排列的現成背景,為 SVG 影像。
BarcodeGenerator.BACKDROP_GROUPS
按組排列的背景:[組, [[id, 英文名, 設定], …]]。
BarcodeGenerator.FORMAT_GROUPS
按組排列的條碼型別:通用、零售、其他。
BarcodeGenerator.LH
比例為 1 時標籤的高度(像素)。
BarcodeGenerator.LW
比例為 1 時標籤的寬度(像素)。
BarcodeGenerator.MAX_VALUES
一批中最多的值數(200)。
BarcodeGenerator.backdropSrc(s)
所選背景的影像(現成的或上傳的圖片),或空字串。
BarcodeGenerator.cardOn(s)
是否在碼下繪製白色卡片(在背景上時取決於開關,在標籤上始終繪製)。
BarcodeGenerator.contrastRatio(a, b)
兩種顏色的對比度(1–21,與 WCAG 相同)。
BarcodeGenerator.fileName(s, value, ext)
某個值的檔名:型別_值.副檔名,檔名中不允許的字元會被替換。
BarcodeGenerator.hasBackdrop(s)
是否已選擇背景。
BarcodeGenerator.hasLabel(s)
標籤是否有標題、價格或徽標。
BarcodeGenerator.isPicture(s)
結果是否為圖片(背景或標籤),而不只是碼本身。
BarcodeGenerator.namedColorTexts(lang)
指定語言的顏色欄位標籤(取色器的文本),缺少該語言時為英文。
BarcodeGenerator.textFontData
文本和字型區塊的資料:字型列表、載入字形樣式、新增字型檔案、某種語言的區塊標籤以及預設值。
BarcodeGenerator.validValues(s)
該批中對所選型別有效的值。
相依套件
程式庫載入的內容與其授權(全部列於「授權條款」頁面)。
| 名稱 | 版本 | 授權 | 檔案 |
|---|---|---|---|
| @openlibsdev/font-forge | 1.0.0 | MIT | GitHub |
| @openlibsdev/image-forge | 1.0.0 | MIT | GitHub |
| @imagemagick/magick-wasm | 0.0.35 | Apache-2.0 | 授權 · 原始碼 |
| @imagemagick/magick-wasm | 0.0.35 | Apache-2.0 | 授權 · 原始碼 |
| @simonwep/pickr | 1.10.2 | MIT | 授權 · 原始碼 |
| @simonwep/pickr | 1.10.2 | MIT | 授權 · 原始碼 |
| dejavu-fonts-ttf | 2.37.3 | Bitstream Vera Fonts License (free, redistributable); DejaVu changes are public domain | 授權 · 原始碼 |
| imagetracerjs | 1.2.6 | Unlicense | 授權 · 原始碼 |
| jsbarcode | 3.11.6 | MIT | 授權 · 原始碼 |
| jspdf | 2.5.2 | MIT | 授權 · 原始碼 |
| jszip | 3.10.1 | (MIT OR GPL-3.0-or-later) | 授權 · 原始碼 |