npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

svelte-barcode-gen

v1.0.2

Published

Svelte 5 wrapper for JsBarcode - Generate barcodes with full TypeScript support!

Downloads

90

Readme

svelte-barcode-gen

A Svelte 5 wrapper for JsBarcode - Generate barcodes in your Svelte applications with full TypeScript support.

📺 Live Demo | 📦 GitHub Repository

Features

  • 🎯 Full TypeScript support with type definitions
  • 🔧 Supports all JsBarcode formats (CODE128, EAN, UPC, CODE39, ITF, MSI, Pharmacode, Codabar, CODE93)
  • 🎨 Customizable styling (colors, fonts, margins)
  • 🖼️ Multiple rendering targets (SVG, Canvas, Image)
  • ✅ Built-in validation with callbacks
  • 🔗 Advanced chaining API support

Installation

npm install svelte-barcode-gen
# or
pnpm add svelte-barcode-gen

Basic Usage

<script>
	import { Barcode } from 'svelte-barcode-gen';
</script>

<Barcode value="Hello World" />

Advanced Usage

With Custom Options

<script>
	import { Barcode } from 'svelte-barcode-gen';
</script>

<Barcode
	value="1234567890128"
	elementTag="svg"
	options={{
		format: 'EAN13',
		width: 2,
		height: 100,
		displayValue: true,
		fontSize: 20,
		lineColor: '#000000',
		background: '#ffffff',
		margin: 10
	}}
/>

With Validation

<script>
	import { Barcode } from 'svelte-barcode-gen';

	let isValid = $state(true);

	function handleValidation(valid) {
		isValid = valid;
		if (!valid) {
			console.error('Invalid barcode value');
		}
	}
</script>

{#if !isValid}
	<p>Invalid barcode value for the selected format</p>
{/if}

<Barcode
	value="123"
	options={{
		format: 'EAN13',
		valid: handleValidation
	}}
/>

Multiple Barcodes with Chaining (Advanced)

<script>
	import { BarcodeAdvanced } from 'svelte-barcode-gen';

	const operations = [
		{
			type: 'options',
			options: { font: 'OCR-B' }
		},
		{
			type: 'barcode',
			format: 'EAN13',
			value: '1234567890128',
			options: { fontSize: 18, textMargin: 0 }
		},
		{
			type: 'blank',
			size: 20
		},
		{
			type: 'barcode',
			format: 'EAN5',
			value: '12345',
			options: { height: 85, textPosition: 'top' }
		}
	];
</script>

<BarcodeAdvanced {operations} elementTag="svg" />

Supported Barcode Formats

  • CODE128 - CODE128 (auto mode), CODE128A, CODE128B, CODE128C
  • EAN/UPC - EAN13, EAN8, EAN5, EAN2, UPC
  • CODE39
  • ITF - ITF, ITF14
  • MSI - MSI, MSI10, MSI11, MSI1010, MSI1110
  • Pharmacode
  • Codabar
  • CODE93

API Reference

<Barcode>

Main component for generating single barcodes.

Props

| Prop | Type | Default | Description | | ------------ | ---------------------------- | -------- | ------------------------------- | | value | string | required | The value to encode | | elementTag | 'svg' \| 'canvas' \| 'img' | 'img' | HTML element type for rendering | | options | JsBarcodeOptions | {} | Configuration options |

<BarcodeAdvanced>

Component for advanced use cases with method chaining.

Props

| Prop | Type | Default | Description | | ------------------- | ---------------------------- | ------- | ---------------------------- | | elementTag | 'svg' \| 'canvas' \| 'img' | 'svg' | HTML element type | | chainedOperations | ChainedOperation[] | [] | Array of operations to chain |

JsBarcodeOptions

| Option | Type | Default | Description | | -------------- | ------------------------------- | ------------- | -------------------------------- | | format | BarcodeFormat | 'CODE128' | Barcode format | | width | number | 2 | Width of a single bar | | height | number | 100 | Height of the barcode | | displayValue | boolean | true | Show text below/above barcode | | text | string | undefined | Override display text | | fontOptions | string | '' | Font styling ('bold', 'italic') | | font | string | 'monospace' | Font family | | textAlign | 'left' \| 'center' \| 'right' | 'center' | Text alignment | | textPosition | 'top' \| 'bottom' | 'bottom' | Text position | | textMargin | number | 2 | Space between barcode and text | | fontSize | number | 20 | Font size | | background | string | '#ffffff' | Background color | | lineColor | string | '#000000' | Bar color | | margin | number | 10 | Margin on all sides | | marginTop | number | undefined | Top margin (overrides margin) | | marginBottom | number | undefined | Bottom margin (overrides margin) | | marginLeft | number | undefined | Left margin (overrides margin) | | marginRight | number | undefined | Right margin (overrides margin) | | valid | (valid: boolean) => void | undefined | Validation callback |

TypeScript Support

This package includes full TypeScript definitions. Import types as needed:

import type {
    BarcodeFormat,
    JsBarcodeOptions,
    BarcodeProps,
    ElementTag,
} from "svelte-barcode-gen";

Examples

Check out the live interactive demo or view the source code in /src/routes/+page.svelte in the GitHub repository.

Development

# Install dependencies
pnpm install

# Start development server
pnpm dev

# Build library
pnpm build

# Check types
pnpm check

License

MIT

Credits

Built on top of JsBarcode by Johan Lindell.