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

@madrimov/electron-pos-printer

v1.0.0

Published

A powerful thermal POS printer library for Electron applications. Supports 58mm and 80mm thermal printers with ESC/POS commands.

Readme

electron-pos-printer

A powerful thermal POS printer library for Electron applications. Supports 58mm and 80mm thermal printers with raw ESC/POS commands.

Features

  • Cross-platform: Works on Windows, macOS, and Linux
  • Raw ESC/POS printing: Direct thermal printer control
  • Support for 58mm and 80mm thermal printers
  • Fluent API for building receipts
  • Barcode and QR code support
  • Table formatting with automatic column widths
  • Full TypeScript support
  • Works with Electron 28+

Installation

npm install electron-pos-printer

Quick Start

1. Main Process (main.ts)

import { app, BrowserWindow, ipcMain } from 'electron';
import { buildESCPOSData, printRawData } from 'electron-pos-printer';

// IPC handler for getting printers
ipcMain.handle('get-printers', async (event) => {
  return await event.sender.getPrintersAsync();
});

// IPC handler for printing
ipcMain.handle('print', async (event, contents, printerName, paperWidth) => {
  const escposData = buildESCPOSData(contents, paperWidth);
  return await printRawData(escposData, printerName);
});

2. Preload Script (preload.ts)

import { contextBridge, ipcRenderer } from 'electron';

contextBridge.exposeInMainWorld('printer', {
  getPrinters: () => ipcRenderer.invoke('get-printers'),
  print: (contents, printerName, paperWidth) =>
    ipcRenderer.invoke('print', contents, printerName, paperWidth),
});

3. Renderer Process (renderer.ts)

// Get available printers
const printers = await window.printer.getPrinters();

// Build and print a receipt
const contents = [
  { type: 'text', value: 'MY STORE', style: { align: 'center', bold: true, size: 'double' } },
  { type: 'text', value: '123 Main Street', style: { align: 'center' } },
  { type: 'line' },
  { type: 'table', rows: [
    [{ text: 'Item', bold: true }, { text: 'Price', align: 'right', bold: true }],
    [{ text: 'Coffee' }, { text: '$4.50', align: 'right' }],
    [{ text: 'Sandwich' }, { text: '$8.99', align: 'right' }],
  ]},
  { type: 'line' },
  { type: 'table', rows: [
    [{ text: 'TOTAL:', bold: true }, { text: '$13.49', align: 'right', bold: true }],
  ]},
  { type: 'feed', lines: 1 },
  { type: 'qrcode', value: 'https://mystore.com/receipt/123' },
  { type: 'feed', lines: 3 },
  { type: 'cut' },
];

const result = await window.printer.print(contents, 'POS-80', 80);
console.log(result.success ? 'Printed!' : result.error);

Using ReceiptBuilder (Fluent API)

import { createReceipt, buildESCPOSData, printRawData } from 'electron-pos-printer';

const receipt = createReceipt(80) // 80mm paper
  .setCurrency({ symbol: '$', symbolPosition: 'before' })
  .title('MY STORE')
  .textCenter('123 Main Street')
  .textCenter('Tel: (555) 123-4567')
  .line()
  .tableRow([
    { text: 'Item', width: '60%', bold: true },
    { text: 'Price', width: '40%', align: 'right', bold: true },
  ])
  .dashedLine()
  .row('Coffee', '$4.50')
  .row('Sandwich', '$8.99')
  .doubleLine()
  .totalRow('TOTAL:', 13.49)
  .feed(2)
  .qrcode('https://receipt.example.com/123')
  .feed(3)
  .cut();

const escposData = buildESCPOSData(receipt.getContents(), 80);
await printRawData(escposData, 'POS-80');

API Reference

Content Types

| Type | Description | Properties | |------|-------------|------------| | text | Text content | value, style | | line | Line separator | character | | table | Table rows | rows | | feed | Paper feed | lines | | cut | Cut paper | partial | | barcode | Barcode | value, options | | qrcode | QR Code | value, options |

Text Styles

interface TextStyle {
  bold?: boolean;
  underline?: boolean;
  align?: 'left' | 'center' | 'right';
  size?: 'normal' | 'double-height' | 'double-width' | 'double';
  invert?: boolean;
}

ReceiptBuilder Methods

| Method | Description | |--------|-------------| | text(value, style?) | Add text | | textCenter(value) | Add centered text | | textBold(value) | Add bold text | | title(value) | Large centered bold text | | line(char?) | Line separator | | dashedLine() | Dashed line | | doubleLine() | Double line (===) | | feed(lines?) | Feed paper | | cut(partial?) | Cut paper | | tableRow(columns) | Add table row | | row(label, value) | Two-column row | | totalRow(label, amount) | Bold total row | | barcode(value, options?) | Add barcode | | qrcode(value, options?) | Add QR code |

Platform Support

| Platform | Method | Requirements | |----------|--------|--------------| | Linux | CUPS (lp command) | CUPS installed, printer configured | | macOS | CUPS (lp command) | Printer in System Preferences | | Windows | Print Spooler | Printer installed, PowerShell |

Paper Width

| Width | Characters per Line | |-------|---------------------| | 58mm | 32 | | 80mm | 48 |

Requirements

  • Node.js >= 18.0.0
  • Electron >= 28.0.0

License

MIT