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

nn-printer

v0.2.4

Published

NN Printer

Downloads

24

Readme

NNPrinter Module

Overview

The NNPrinter module provides functionalities for network service discovery and network printing via TCP connections. It supports discovering devices using mDNS (Bonjour) and printing text to network printers. This module is designed to be used with React Native applications.

Permissions

To use network service discovery and network printing, your application needs to request appropriate permissions. This section covers the necessary permissions for both Android and iOS.

Android Permissions

Add the following permissions to your app.json file under the android section:

{
  "expo": {
    ...
    "android": {
      "permissions": [
        "INTERNET",
        "ACCESS_NETWORK_STATE",
        "CHANGE_NETWORK_STATE",
        "ACCESS_WIFI_STATE",
        "CHANGE_WIFI_STATE",
        "NEARBY_WIFI_DEVICES",
        "BLUETOOTH",
        "BLUETOOTH_ADMIN",
        "BLUETOOTH_SCAN",
        "BLUETOOTH_ADVERTISE",
        "BLUETOOTH_CONNECT",
        "ACCESS_FINE_LOCATION",
        "ACCESS_COARSE_LOCATION"
      ],
      "package": "com.yourcompany.yourapp"
    },
    "ios": {
      ...
      "infoPlist": {
        "NSBluetoothAlwaysUsageDescription": "Allow SimpleVen to use bluetooth",
        "NSBonjourServices": [
          "_http._tcp",
          "_ipp._tcp" 
        ],
        "NSLocalNetworkUsageDescription": "This app requires access to the local network to discover and communicate with local devices."     
      }
    },
  }
}

## Usage

### Import and Initialize the Module

```javascript
import NNPrinter from 'nn-printer';

Example Usage

Start Scanning for Devices

NNPrinter.onScanStart().then((status) => {
  console.log('Scan started');
 //status : {"status": "started"}
}).catch(error => {
  console.error('Scan start failed', error);
});

Stop Scanning for Devices

NNPrinter.onScanStop().then((status) => {
  console.log('Scan stopped');
  //{"status": "stopped"}
}).catch(error => {
  console.error('Scan stop failed', error);
});

Listen for Detected Devices

const subscription = NNPrinter.onScanDetected((result) => {
  console.log('Device found:', result.ipAddress);
  //{"ipAddress": "192.168.1.2", "serviceName": "EPSON TM-m30III", "serviceType": "._http._tcp", "status": "found"}
});

// Remember to unsubscribe when no longer needed
subscription.remove();

Print Text to a Network Printer

const const printText =
  "[C]<img>https://drive.usercontent.google.com/u/0/uc?id=1GQOzB8MP3iWXV3k53pFumA5H5s0cpjha&export=download</img>\n"
  +
  NNPrinter.prepareColumn(
    [24],
    ['C'],
    ['SIMPLEVEN TEST'],
    { fontWeight: "bold", fontSize: "big" }
  )
  +
  NNPrinter.prepareColumn(
    [48],
    ['C'],
    ['07/07/2024 18:30']
  ) +
  NNPrinter.prepareColumn(
    [48],
    ['C'],
    ['Accepted by']
  ) +
  NNPrinter.prepareColumn(
    [24],
    ['C'],
    ['Bar'],
    { fontWeight: "bold", fontSize: "big" }
  ) +
  NNPrinter.prepareColumn(
    [48],
    ['C'],
    ['07/07/2024 18:30']
  )
  +
  NNPrinter.prepareColumn(
    [18, 10, 10, 10],
    ['L', 'R', 'R', 'R'],
    ['Item', 'Size', 'Qty', 'Price'],
    { fontWeight: "bold" }
  ) +
  NNPrinter.prepareColumn(
    [18, 10, 10, 10],
    ['L', 'R', 'R', 'R'],
    ['Albabi Odense Pilsner 4.6%', 'Lille', '23', '1058 DKK'],
  ) +
  NNPrinter.prepareColumn(
    [18, 10, 10, 10],
    ['L', 'R', 'R', 'R'],
    ['Pepsi', 'Mellem', '2', '88 DKK'],
  ) +
  NNPrinter.prepareColumn(
    [18, 10, 10, 10],
    ['L', 'R', 'R', 'R'],
    ['Premium Party Starter', '', '1', '799 DKK'],
  ) +
  /** */
  NNPrinter.prepareColumn(
    [48],
    ['L'],
    ['   20x Smirnoff Ice'],
  ) +
  NNPrinter.prepareColumn(
    [48],
    ['L'],
    ['   1x Breezer Original'],
  ) +
  NNPrinter.prepareColumn(
    [48],
    ['L'],
    ['   2x Breezer Pinapple'],
  ) +
  NNPrinter.prepareColumn(
    [48],
    ['L'],
    ['All prices include VAT where applicable'],
  ) +
  NNPrinter.prepareColumn(
    [38, 10],
    ['L', 'R'],
    ['Total', '7147 DKK'],
  ) +
  NNPrinter.prepareColumn(
    [48],
    ['C'],
    ['!!!Disclaimer!!!'],
    { fontWeight: "bold" }
  ) +
  NNPrinter.prepareColumn(
    [48],
    ['C'],
    ['This is a staff-only receipt for internal use only. Please provide official receipts to customers if needed.'],
  )
NNPrinter.print(
  '192.168.1.100', // IP address of the printer
  9100,            // Port
  text, // Text to print
  true,            // Auto cut
  'medium'         // Printer type (as defined in PrinterConfig)
).then(() => {
  console.log('Print successful');
}).catch(error => {
  console.error('Print failed', error);
});

Conclusion

The NNPrinter module provides easy-to-use functionalities for network service discovery and network printing. Ensure you have the required permissions set up correctly for the module to function as expected on both Android and iOS.