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

@netgencustomsoftware/react-native-esc-pos

v1.0.1

Published

A React Native ESC/POS module to help you connect to your ESC/POS printer easily.

Downloads

3

Readme

React Native ESC/POS module

A React Native ESC/POS module to help you connect to your ESC/POS printer easily. It also has provide an intuitive way to design your layout, check below example to see how easy to get your layout ready!

Getting started

$ yarn add @leesiongchan/react-native-esc-pos

** NOTE: Skip below installation guide if you are using React Native >= 0.60 **

Mostly automatic installation

$ react-native link @leesiongchan/react-native-esc-pos

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modules@leesiongchanreact-native-esc-pos and add EscPos.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libEscPos.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import leesiongchan.reactnativeescpos.EscPosPackage; to the imports at the top of the file
  • Add new EscPosPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-esc-pos'
    project(':react-native-esc-pos').projectDir = new File(rootProject.projectDir, 	'../node_modules/@leesiongchan/react-native-esc-pos/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-esc-pos')

Usage

import EscPos from "@leesiongchan/react-native-esc-pos";

const design = `
D0004           {<>}           Table #: A1
------------------------------------------
[ ] Espresso
    - No sugar, Regular 9oz, Hot
                              {H3} {R} x 1
------------------------------------------
[ ] Blueberry Cheesecake
    - Slice
                              {H3} {R} x 1

{QR[Where are the aliens?]}
`;

async function testPrinter() {
  try {
    // Can be `network` or `bluetooth`
    EscPos.setConfig({ type: "network" });

    // Connects to your printer
    // If you use `bluetooth`, second parameter is not required.
    await EscPos.connect("10.10.10.10", 9100);

    // Once connected, you can setup your printing size, either `PRINTING_SIZE_58_MM` or `PRINTING_SIZE_80_MM`
    EscPos.setPrintingSize(EscPos.PRINTING_SIZE_80_MM);
    // 0 to 8 (0-3 = smaller, 4 = default, 5-8 = larger)
    EscPos.setTextDensity(9);
    // Test Print
    await EscPos.printSample();
    // Cut half!
    await EscPos.cutPart();
    // You can also print image!
    await EscPos.printImage(file.uri);
    // Print your design!
    await EscPos.printDesign(design);
    // Print QR Code, you can specify the size
    await EscPos.printQRCOde("Proxima b is the answer!", 200);
    // Cut full!
    await EscPos.cutFull();
    // Beep!
    await EscPos.beep();
    // Kick the drawer! Can be either `kickCashDrawerPin2` or `kickCashDrawerPin5`
    await EscPos.kickCashDrawerPin2();
    // Disconnect
    await EscPos.disconnect();
  } catch (error) {
    console.error(error);
  }
}

Scan For Bluetooth Devices

To scan for available bluetooth in range

EscPos.scanDevices();

To stop scan

EscPos.stopScan();

Register callback events to receive device found:-

EscPos.addListener("bluetoothDeviceFound", (event: any) => {
  if (event.state === EscPos.BLUETOOTH_DEVICE_FOUND) {
    console.log("Device Found!");
    console.log("Device Name : " + event.deviceInfo.name);
    console.log("Device MAC Address : " + event.deviceInfo.macAddress);
  }

Events

To listen to bluetooth state change

EscPos.addListener("bluetoothStateChanged", (event: any) => {
  if (event.state === EscPos.BLUETOOTH_CONNECTED) {
    console.log("Device Connected!");
    console.log("Device Name : " + event.deviceInfo.name);
    console.log("Device MAC Address : " + event.deviceInfo.macAddress);
  }
});

To get Bluetooth Conenction State:

  • EscPos.BLUETOOTH_CONNECTED
  • EscPos.BLUETOOTH_DISCONNECTED

To get Connected / Disconnected Bluetooth Device Info Device Name:

  • event.deviceInfo.name

Device MAC Address:

  • event.deviceInfo.macAddress

New Feature

  • You can now easily duplicate a string or character and print onto your design.
  • Introducing Repeat feature:

Main tag {RP: number of times to duplicate required: string or character to duplicate} Example: Input {RP:5:*} Output: *****

If you have few characters to duplicate in a line and some text within the line you wouldn't want to disturb, you can do it as per below: Example: Input: {RP:3:= }This is a test string{RP:2:@@} Output: = = = This is a test string@@@_@

Important note: this feature does not support repetitive printing of Closing Curly Bracket }.

TODO

  • [x] Android support
  • [ ] iOS support
  • [ ] Print barcode
  • [ ] Add TypeScript support
  • [x] Bluetooth support
  • [ ] Serial port support
  • [ ] Add test
  • [x] Listen to the connection status