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

phomemo-protocol

v0.1.0

Published

Wire protocol encoder and Web Serial transport for Phomemo label printers (M02/M02 Pro/M02S/T02/M110/M120/M220)

Readme

phomemo-protocol

A small, dependency-free TypeScript library for talking to Phomemo label printers: it turns an image into the printer's raster wire format, and provides a Web Serial transport for sending it over USB or Bluetooth.

Supports two printer families:

  • M110 family (M110, M120, M220) — ESC N speed/darkness + 0x1f 0x11 media type header, 0x1f 0xf0 status footer.
  • M02 family (M02, M02 Pro, M02S, T02) — plain ESC/POS (ESC @ / ESC a / 0x1f 0x11 0x02 0x04 header, ESC d feed + 0x1f 0x11 status-query footer). Splits tall images into multiple 255-line raster blocks, since that's the hardware's per-block limit. Experimental / untested on real M02-family hardware.

Extracted from labelync so the protocol and transport logic can be reused outside that app.

Install

npm install phomemo-protocol

Usage

The core API (phomemo-protocol) is transport- and platform-agnostic — it just turns pixels into bytes:

import { rasterizeMonochrome, buildPrintCommands } from 'phomemo-protocol';

// image: { width, height, data } — e.g. from canvas.getContext('2d').getImageData(...)
const bitmap = rasterizeMonochrome(image);

const commands = buildPrintCommands(bitmap, {
  deviceModel: 'M110',
  darkness: 0x08, // 0x01–0x0f, M110 family only
  speed: 0x05,    // 0x01–0x05, M110 family only
  paperType: 0x0a // 0x0a "Label With Gaps" / 0x0b "Continuous" / 0x26 "Label With Marks", M110 family only
});

// `commands` is an ordered array of Uint8Array chunks — write each one to
// the printer's output stream in order (see the serial transport below, or
// bring your own transport, e.g. Node's `serialport` package).

For browsers, phomemo-protocol/serial wraps the Web Serial API with the settings Phomemo printers expect. This works both for USB-connected printers and for printers paired over Bluetooth, since Chromium exposes Bluetooth SPP connections as a serial port too — see Web Serial over Bluetooth.

import { openPhomemoSerialPort, writePrintCommands, getSerialDeviceId } from 'phomemo-protocol/serial';

const port = await navigator.serial.requestPort();
await openPhomemoSerialPort(port);

const deviceId = getSerialDeviceId(port); // stable id, e.g. for remembering per-printer settings

await writePrintCommands(port, commands);

SerialPortLike in phomemo-protocol/serial is a structural type, not tied to the DOM lib's global SerialPort — pass in whatever your environment gives you for navigator.serial, as long as it has writable, open() and getInfo().

A GATT-based Bluetooth transport (Web Bluetooth, for printers that don't expose an SPP serial port) could be added later as its own phomemo-protocol/ble submodule without changing the core API.

What this library does not do

  • Rendering labels/templates to an image — bring your own canvas/SVG rendering and pass the resulting pixels in.
  • Remembering printer settings, auto-reconnect UX, timeouts — these are application policy, not protocol, and are left to the caller.
  • Dithering — rasterizeMonochrome does simple black/white thresholding; dither the image yourself first if you want that.

Development

npm install
npm test
npm run build

Acknowledgments

License

MIT