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 🙏

© 2025 – Pkg Stats / Ryan Hefner

escpos-typescript

v1.0.1

Published

ESC/POS printer library for Node.js written in TypeScript

Readme

escpos-ts

A TypeScript library for printing receipts, barcodes, and QR codes on ESC/POS-compatible printers via USB or the OS print system.
Supports Windows, macOS, and Linux using native commands like lp or print.exe.


🚀 Features

✅ Print formatted text (alignment, bold, double width/height, underline)
✅ Print barcodes (EAN-13, CODE128, and more)
✅ Print QR codes (with size & error correction)
✅ Disable printing in tests with a flag
✅ Fully testable with a mock printer interface
✅ Works cross-platform (Windows, macOS, Linux)


📦 Installation

npm install escpos-ts

🖨️ Quick Start Demo

Create a file and use this library:

import {
  POSReceiptBuilder,
  POSTextBuilder,
  POSBarcodeBuilder,
  POSQRCodeBuilder,
  POSPrintStyle,
  POSTextAlignment,
  POSBarcodeType,
  POSBarcodeWidth,
  POSQRCodeSize,
  POSQRCodeErrorCorrection,
  POSPrinter
} from "escpos-ts";

const printer = new POSPrinter("Your_Printer_Name"); // name shown in system printer list

const receipt = new POSReceiptBuilder()
  .setTitle("ESC/POS PRINTER DEMO")
  .addFeed()
  .addComponent(new POSTextBuilder("Left").setAlignment(POSTextAlignment.LEFT).build())
  .addComponent(new POSTextBuilder("Center").setAlignment(POSTextAlignment.CENTER).build())
  .addComponent(new POSTextBuilder("Right").setAlignment(POSTextAlignment.RIGHT).build())
  .addComponent(new POSTextBuilder("Bold").setStyle(POSPrintStyle.BOLD).build())
  .addComponent(new POSTextBuilder("Underlined").setStyle(POSPrintStyle.UNDERLINE).build())
  .addItem("Product 1", 10.0)
  .addItem("Product 2", 5.5)
  .addComponent(
    new POSBarcodeBuilder("123456789012")
      .setType(POSBarcodeType.JAN13_EAN13)
      .setWidth(POSBarcodeWidth.THIN)
      .build()
  )
  .addComponent(
    new POSQRCodeBuilder("https://example.com")
      .setSize(POSQRCodeSize.LARGE)
      .setErrorCorrection(POSQRCodeErrorCorrection.HIGH)
      .build()
  )
  .addComponent(new POSTextBuilder("----------------------").build())
  .addComponent(new POSTextBuilder("Total: {EUR} 15.50").setStyle(POSPrintStyle.BOLD).build())
  .setFooter("Thank you!")
  .build();

printer.print(receipt);

🧪 Testing

🔹 Disable Real Printing (Globally)

import { POSConfig } from "escpos-ts";

POSConfig.setDisablePrinting(true);

🔹 Use a Mock Printer in Unit Tests

import { POSPrinterMock } from "escpos-ts";
import { POSReceiptBuilder } from "escpos-ts";
import { POSTextBuilder } from "escpos-ts";

test("mock printer captures output", () => {
  const mock = new POSPrinterMock();

  const receipt = new POSReceiptBuilder()
    .setTitle("Test Receipt")
    .addComponent(new POSTextBuilder("Line 1").build())
    .build();

  mock.print(receipt);

  expect(mock.getPrintedData().length).toBe(1);
  expect(mock.getPrintedData()[0].length).toBeGreaterThan(0);
});

🖨️ How It Works (Under the Hood)

  • Uses platform-native commands:
    • macOS/Linuxlp -o raw
    • Windowsprint.exe
  • Writes ESC/POS bytes to a temporary .bin file and prints it using these tools
  • Cross-platform compatible without native bindings

🧾 How to Find Your Printer Name

On macOS/Linux

lpstat -p

On Windows

Get-Printer | Select-Object Name

Use the exact name shown there in the constructor:

new POSPrinter("Printer_Name_From_List");

📜 License

MIT