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

@ctrlemo/epos-react-hook

v1.0.9

Published

React hook for managing Epson ePOS printer connections with TypeScript support

Downloads

21

Readme

Epson ePOS React Hook

A React hook for managing Epson ePOS thermal printer connections. In the future this package will include more functionality for printing and support for other ePOS printer brands.

Installation

npm install @ctrlemo/epos-react-hook

Usage

First you need to download the Epson ePOS SDK from Epson's official website and host the epos-sdk.js file in your public site directory or a CDN. You will also find the API documentation there for your particular printer model.

Then you can use the hook in your React component as follows:

import { useEposPrinter, PRINTER_STATUS } from "@ctrlemo/epos-react-hook";

function PrinterComponent() {
  const { printer, status, connect, disconnect, error } = useEposPrinter(
    "192.168.1.100", // printer IP or hostname
    "/path/to/epos-sdk.js", // path to epos-sdk.js
    8043 // port (optional)
  );

  const handleConnect = async () => {
    const printerObj = await connect();
    if (printerObj) {
      console.log("Printer connected!");
    }
  };

  return (
    <div>
      <p>Status: {status}</p>
      {status === PRINTER_STATUS.IDLE && (
        <button onClick={handleConnect}>Connect</button>
      )}
      {status === PRINTER_STATUS.CONNECTED && (
        <button onClick={disconnect}>Disconnect</button>
      )}
    </div>
  );
}

TypeScript Support

This package includes full TypeScript support with comprehensive type definitions. Both JavaScript and TypeScript consumers can use the package seamlessly.

TypeScript Usage

import {
  useEposPrinter,
  EposClient,
  PRINTER_STATUS,
  type PrinterStatus,
  type UseEposPrinterReturn,
  type EposClientOptions,
} from "@ctrlemo/epos-react-hook";

// Hook usage with full type safety
function MyPrinterComponent(): JSX.Element {
  const {
    printer,
    status,
    error,
    connect,
    disconnect,
    isConnected,
  }: UseEposPrinterReturn = useEposPrinter(
    "192.168.1.100", // IP address
    "/epos-sdk.js", // SDK URL
    8043 // Port (optional)
  );

  // Type-safe status handling
  const handleStatusChange = (newStatus: PrinterStatus): void => {
    switch (newStatus) {
      case PRINTER_STATUS.IDLE:
        console.log("Printer is idle");
        break;
      case PRINTER_STATUS.CONNECTING:
        console.log("Connecting...");
        break;
      case PRINTER_STATUS.CONNECTED:
        console.log("Connected");
        break;
      case PRINTER_STATUS.ERROR:
        console.log("Error occurred");
        break;
    }
  };

  const handleConnect = async (): Promise<void> => {
    try {
      const printerInstance = await connect();
      if (printerInstance) {
        console.log("Connected successfully");
      }
    } catch (err) {
      console.error("Connection failed:", err);
    }
  };

  return (
    <div>
      <p>Status: {status}</p>
      {error && <p>Error: {error}</p>}
      <button onClick={handleConnect} disabled={isConnected()}>
        Connect
      </button>
    </div>
  );
}

// Direct client usage with TypeScript
class TypeSafePrinterService {
  private client: EposClient;

  constructor(config: EposClientOptions) {
    this.client = new EposClient(config);
  }

  async initialize(): Promise<void> {
    await this.client.loadSdk();
  }

  async connect(): Promise<any> {
    await this.client.connect();
    return await this.client.createPrinter();
  }

  isConnected(): boolean {
    return this.client.isConnected();
  }

  async disconnect(): Promise<void> {
    await this.client.disconnect();
  }
}

Available Types

  • PrinterStatus: Union type of all possible printer status values
  • UseEposPrinterReturn: Interface for the hook's return value
  • EposClientOptions: Configuration interface for EposClient
  • EposEndpoint: Interface for printer endpoint information

Type Validation

The package includes utility functions for runtime type validation:

import { isValidPrinterStatus, PRINTER_STATUS } from "@ctrlemo/epos-react-hook";

// Type guard function
function handleUnknownStatus(status: unknown) {
  if (isValidPrinterStatus(status)) {
    // TypeScript now knows status is PrinterStatus
    console.log("Valid status:", status);
  }
}

API Reference

useEposPrinter Hook

function useEposPrinter(
  ip: string,
  sdkUrl: string,
  port?: number
): UseEposPrinterReturn;

Parameters:

  • ip: Printer IP address or hostname
  • sdkUrl: Path to the Epson ePOS SDK JavaScript file
  • port: Printer port (optional, defaults to 8043)

Returns:

  • printer: The printer instance (null when not connected)
  • status: Current connection status
  • error: Error message (null when no error)
  • connect(): Function to establish connection
  • disconnect(): Function to close connection
  • isConnected(): Function to check connection status

EposClient Class

class EposClient {
  constructor(options: EposClientOptions);
  loadSdk(): Promise<void>;
  connect(): Promise<void>;
  createPrinter(): Promise<any>;
  getEndpoint(): EposEndpoint;
  isConnected(): boolean;
  disconnect(): Promise<void>;
}

Constants

const PRINTER_STATUS: {
  readonly IDLE: "idle";
  readonly CONNECTING: "connecting";
  readonly CONNECTED: "connected";
  readonly ERROR: "error";
};

const PRINTER_STATUS_LABELS: {
  readonly idle: "Idle";
  readonly connecting: "Connecting...";
  readonly connected: "Connected";
  readonly error: "Error";
};