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 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-epson-tm

v0.1.1

Published

A simple Cordova plugin for printing receipts from an Epson TM printer.

Downloads

22

Readme

Epson TM Printer Service

A simple Cordova plugin for printing receipts from an Epson TM printer. 🧾🖨️

This plugin defines a global EpsonTM object, which is available after the deviceready event.

IMPORTANT: If you are building an app with this plugin for a simulator on a Mac with Apple Silicon, then you may encounter a build error. To resolve the issue, exclude arm64 for the simulator SDK under both <Project>.xcodeproj and CordovaLib.xcodeproj. See technote TN3117 for more details.

Installation

cordova plugin add cordova-plugin-epson-tm

API

The EpsonTM object has constants for the following compatible printer models:

  • m10
  • m30
  • P20
  • P60
  • P60II
  • P80
  • T20
  • T60
  • T70
  • T81
  • T82
  • T83
  • T88
  • T90
  • T90KP
  • U220
  • U330
  • L90
  • H6000
  • T83III
  • T100

Additionally, but most importantly, the EpsonTM object has three methods. Ideally, they should be used in the same component (yes, this plugin is UI-library-agnostic).

  • printReceipt(args, success, error)
  • startPrinterSearch(success, error)
  • stopPrinterSearch(success, error)

printReceipt(args, success, error)

Prints a receipt using the specified args.

Parameters:

  • args — An object that contains the following properties:
    • model — The Epson TM printer model (e.g., EpsonTM.m30).
    • lines — The lines on the receipt.
    • includeCustomerCopy — Indicates whether a second copy of the receipt will be printed. The default is false.
  • success — A callback to invoke when the receipt is printed. It passes true.
  • error — A callback to invoke when there is an error. It passes one of the following errors:
    • PRINTER_NOT_FOUND — An Epson TM printer was not found by the service.
    • INVALID_PRINTER_MODEL — The Epson TM printer model is invalid.
    • CANNOT_CONNECT_PRINTER — The service cannot connect to an Epson TM printer.
    • BLANK_RECEIPT — The receipt is blank.
EpsonTM.printReceipt(
    {
        model: EpsonTM.m30,
        lines: [
            "        BUSINESS NAME         ",
            "       1234 Main Street       ",
            "        City, ST 54321        ",
            "        1(123)456-7890        ",
            "------------------------------",
            "Lorem ipsum              $1.25",
            "Dolor sit amet           $7.99",
            "Consectetur             $26.70",
            "Adipiscing elit         $15.49",
            "Sed semper              $18.79",
            "Accumsan ante           $42.99",
            "Non laoreet              $9.99",
            "Dui dapibus eu          $27.50\n",

            "Sub Total              $150.70",
            "Sales Tax                $5.29",
            "------------------------------",
            "TOTAL                  $155.99",
        ],
        includeCustomerCopy: true,
    },
    (result) => console.log(`Success? ${result}`),
    (error) => {
        if (error === EpsonTM.Error.CANNOT_CONNECT_PRINTER) {
            console.log("Cannot connect to a printer.")
        }
    }
)

startPrinterSearch(success, error)

Starts searching for an Epson TM printer.

This method will keep running in the background until either a printer is found or the stopPrinterSearch method is called. Ideally, it should be called when the component is created.

Parameters:

  • success — A callback to invoke when the printer search is started. It passes true.
  • error — A callback to invoke when there is an error. It passes the error CANNOT_START_PRINTER_SEARCH.
EpsonTM.startPrinterSearch(
    (result) => console.log(`Success? ${result}`),
    (error) => {
        if (error === EpsonTM.Error.CANNOT_START_PRINTER_SEARCH) {
            console.log("Cannot start printer search.")
        }
    }
)

stopPrinterSearch(success, error)

Stops searching for an Epson TM printer.

Ideally, this method should be called when the component is destroyed.

Parameters:

  • success — A callback to invoke when the printer search is stopped. It passes true.
  • error — A callback to invoke when there is an error. It passes the error CANNOT_STOP_PRINTER_SEARCH.
EpsonTM.stopPrinterSearch(
    (result) => console.log(`Success? ${result}`),
    (error) => {
        if (error === EpsonTM.Error.CANNOT_STOP_PRINTER_SEARCH) {
            console.log("Cannot stop printer search.")
        }
    }
)

Component Example

Here is how one would use the plugin in a Svelte component:

<script>
    import {onDestroy, onMount} from "svelte"

    const printReceipt = () => {
        EpsonTM.printReceipt(
            {
                model: EpsonTM.m30,
                lines: receiptLines,
                includeCustomerCopy: true,
            },
            (result) => {},
            (error) => {
                // Handle the error here.
            }
        )
    }

    onMount(
        () => EpsonTM.startPrinterSearch()
    )

    onDestroy(
        () => EpsonTM.stopPrinterSearch()
    )
</script>

<button on:click={printReceipt}>
    Print Receipt
</button>

For a more concrete example, please check out this repo.