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

labelprinterkit

v1.0.13

Published

Browser-ready label printing toolkit for Brother P-Touch devices using WebUSB/WebBluetooth.

Readme

Labelprinterkit (JavaScript, WebUSB/WebBluetooth)

Browser-ready label printing toolkit for Brother P-Touch devices. Everything is ESM (.mjs) and async/await friendly. Backends: WebUSB and WebBluetooth (for BLE-capable models or adapters).

Quickstart

npm install labelprinterkit
// main.mjs (served over https or localhost)
import {
    P700,
    Job,
    Media,
    Resolution,
    Label,
    TextItem,
    BoxItem,
    WebUSBBackend,
    WebBluetoothBackend,
    getLibraryVersion
} from 'labelprinterkit'

async function connectBackend(mode = 'usb') {
    if (mode === 'usb') {
        // USB printer class (07h). Must be triggered by a user gesture.
        return WebUSBBackend.requestDevice({ filters: [{ classCode: 7 }] })
    }
    if (mode === 'ble') {
        // Provide the BLE service/characteristic UUIDs for your device.
        return WebBluetoothBackend.requestDevice({
            serviceUuid: '0000xxxx-0000-1000-8000-00805f9b34fb',
            writeCharacteristicUuid: '0000yyyy-0000-1000-8000-00805f9b34fb',
            notifyCharacteristicUuid: '0000zzzz-0000-1000-8000-00805f9b34fb',
            filters: [{ namePrefix: 'PT-' }]
        })
    }
    throw new Error('Unknown backend mode')
}

async function printSample() {
    const backend = await connectBackend('usb') // or "ble"
    const media = Media.W12
    const resolution = Resolution.LOW

    // Row heights should sum to media.printArea so Job.addPage() accepts the page width.
    const rowAHeight = Math.floor(media.printArea * 0.58)
    const rowBHeight = media.printArea - rowAHeight
    const rowA = new BoxItem(rowAHeight, [new TextItem(rowAHeight, 'First line', '28px sans-serif')])
    const rowB = new BoxItem(rowBHeight, [new TextItem(rowBHeight, 'Second line', '22px sans-serif')])
    const label = new Label(resolution, rowA, rowB)

    const job = new Job(media, { resolution })
    job.addPage(label)

    const printer = new P700(backend) // P750W/E500/E550W are available shims too
    await printer.print(job)
}

printSample().catch(console.error)

Runtime version access:

import { getLibraryVersion } from 'labelprinterkit'

console.log(getLibraryVersion()) // "1.0.13"

For a richer layout with a QR code, see examples/complex_label_with_qrcode.mjs (uses the qrcode ESM from jsdelivr and exposes window.printLabel you can wire to a button). An interactive editor with drag-to-reorder, resizing, font/QR editing, and label size controls lives in examples/complex_label_with_frontend/index.html (served over https/localhost).

Run the web editor locally

npm install
PORT=3000 npm start
# then open http://localhost:3000/examples/complex_label_with_frontend/
npm test

The Express server (examples/server.mjs) serves the repo as static files; the editor is under /examples/complex_label_with_frontend/. Use a Chromium-based browser with WebUSB/WebBluetooth enabled. When using BLE, populate the UUID fields in the UI for your device. Printing still requires a user gesture (click) to grant device access. You can also set a custom media length (mm) in the UI; it converts to dots using the selected resolution’s Y DPI and enforces the protocol minimums.

The editor uses dedicated Web Workers for preview rendering (preview-render.worker.mjs) and raster/compression print preparation (print-prep.worker.mjs). If worker APIs are unavailable, it falls back to main-thread rendering/preparation.

API highlights

  • Label, TextItem, BoxItem (from src/label.mjs): Canvas-based layout helpers. You can also use Page.fromImageData(...) if you already have a bitmap.
  • Job (from src/job.mjs): Validates media width/resolution, supports auto-cut, chain printing, and special tape flags.
  • Printers (from src/printers.mjs): Implements the Brother raster protocol with PackBits compression.
  • Status.mediaDetails and PrinterErrorCode.MEDIA_MISMATCH (from src/printers.mjs): inspect unsupported loaded cassette details without parsing human-readable error strings.
  • getLibraryVersion() / LIBRARY_VERSION (from src/version.mjs): Runtime library version access.
  • Backends:
    • WebUSBBackend for USB printer class devices.
    • WebBluetoothBackend for BLE devices when you supply the service/characteristic UUIDs and enable notifications.

Documentation

Notes

  • WebUSB/WebBluetooth require a secure context (https or localhost) and a user gesture to request devices/ports.
  • Fonts come from whatever your page loads; adjust the CSS font stack you pass into TextItem.
  • If you need to debug output, use bitmapToImageData from src/page.mjs to visualize the raster data in a canvas.
  • Print mismatches now include structured error.details.loadedMedia / error.details.expectedMedia payloads so callers can localize or enrich tape mismatch messages.

License

This project is available under two licensing options:

1. Open-source license

Source code, examples, and tests are licensed under the GNU General Public License v3.0 or later (GPL-3.0-or-later).

You may use, modify, and distribute this project under the GPL. If you distribute modified versions or larger works based on this project, they must comply with the GPL, including source-code availability requirements.

Documentation is licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA-4.0) unless otherwise marked.

2. Commercial/proprietary license

For use in closed-source, proprietary, or otherwise GPL-incompatible products, a separate commercial license is required.

Commercial licensing contact: https://github.com/SunboX

Attribution / notices

Copyright (C) 2026 André Fiedler.

Copyright, license, attribution, and source-origin notices must be preserved as required by the GPL and the notice files in this repository. See NOTICE.md and COMMERCIAL-LICENSE.md for details.