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

@playwright-labs/barcode-core

v1.1.0

Published

1D barcode (EAN, Code128, UPC, ...) encode/decode primitives

Readme

@playwright-labs/barcode-core

1D barcode encode/decode primitives for Node.js — SVG encoder (jsbarcode) and multi-input decoder (javascript-barcode-reader).

What this package provides

@playwright-labs/barcode-core is the shared foundation used by @playwright-labs/fixture-barcode. It can also be used standalone in any Node.js project that needs:

  • BarcodeEncoder — renders EAN/Code128/UPC/... barcodes as SVG strings, no browser or canvas required
  • BarcodeDecoder — decodes barcodes from buffers, streams, files, base64 strings, or raw pixel data

Installation

pnpm add @playwright-labs/barcode-core

BarcodeEncoder

import { BarcodeEncoder } from '@playwright-labs/barcode-core';

// svg (default): resolves with the SVG string
const svg = await new BarcodeEncoder({ format: 'EAN13' }).encode('5901234123457');

// file: writes the SVG, resolves with the path
await new BarcodeEncoder({ format: 'EAN13', type: 'file', path: 'barcode.svg' })
  .encode('5901234123457');

// stream: pipes the SVG into the writable, resolves with ''
await new BarcodeEncoder({ format: 'EAN13', type: 'stream', writable })
  .encode('5901234123457');

// imagedata: resolves with raw RGBA pixels ({ data, width, height })
const image = await new BarcodeEncoder({ format: 'EAN13', type: 'imagedata' })
  .encode('5901234123457');

// buffer / uint8array / uint8clampedarray: SVG as UTF-8 bytes
const bytes = await new BarcodeEncoder({ format: 'EAN13', type: 'buffer' })
  .encode('5901234123457');

Constructor options: format (required), output target (type: svg | file | stream | imagedata | buffer | uint8array | uint8clampedarray, default svg) plus jsbarcode rendering options — width, height, displayValue, text, fontSize, margin, background, lineColor, flat.

imagedata renders pixels directly (no SVG involved), so it feeds straight into BarcodeDecoder.decode(type, image) — full roundtrip without a rasterizer. Text options (displayValue, text, fontSize) are ignored in this mode.

Supported formats (BarcodeFormat): CODE128 (+A/B/C), EAN13, EAN8, EAN5, EAN2, UPC, CODE39, ITF, ITF14, MSI (+variants), pharmacode, codabar.

Invalid values reject (e.g. wrong EAN-13 checksum digit).

Output is SVG only. Rasterizing to PNG needs a canvas implementation — out of scope for this package.

BarcodeDecoder

Barcode type is required per call (Barcode union is exported):

import { BarcodeDecoder } from '@playwright-labs/barcode-core';

const decoder = new BarcodeDecoder();

await decoder.decode('ean-13', pngBuffer);                   // Buffer / Uint8Array (PNG, JPEG, ...)
await decoder.decode('code-128', 'data:image/png;base64,...'); // data URL
await decoder.decode('code-128', rawBase64String);           // raw base64
await decoder.decode('upc-a', readableStream);               // Readable of an encoded image
await decoder.decode('ean-8', { data, width, height });      // raw RGBA pixels

// file via constructor options
await new BarcodeDecoder({ type: 'file', path: 'barcode.png' }).decode('ean-13');

Supported types (Barcode): ean-13, ean-8, upc-a, upc-e, code-39, code-93, code-2of5, code-128, codabar, msi, pharmacode.

Resolves with the decoded string. Unsupported input throws TypeError.

EAN-13 caveat: the underlying reader does not recover the leading digit (encoded via left-group parity, not bars) — expect the 12-digit tail.

Encoder and decoder format names differ (EAN13 vs ean-13) — they come from different underlying libraries.

Related packages

License

MIT