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

@makgabri/react-native-sunmi-printer

v0.1.1

Published

react native adaptation for sunmi printers

Readme

React-Native-Sunmi-Printer

Sunmi devices have built in printers. This library extends the java code such that the functions can be used in react native. More over, all sunmi devices(at least printers) run on android so this library is only available for android.

To implement after V1:

✓ Basic printer connection ✓ Test printing ✓ Get printer status and specs ✓ Print text, set align and bold ✓ Print images ✗ Set bold ✗ Print bar code ✗ Print tables ✗ Print QR codes ✗ Checking params for printing qrcode, tables and barcode

Installation

Using npm:

npm install --save @makgabri/react-native-sunmi-printer

or using yarn:

yarn add @makgabri/react-native-sunmi-printer

Example Import

import { SPrinter, Constants } from '@makgabri/react-native-sunmi-printer';

// ...
await SPrinter.connect();
await SPrinter.testPrint();
await SPrinter.disconnect();

Below is the api documentation to execute other functions in the library including printing

  • texts
  • images
  • setting align/bold
  • ...etc

Function returns

All functions run async as the printer may need time to respond. When successful or a json object is returned such as the case for getting specs, the promise will resolve an object. Example:

try {
    // Successful response
    await SPrinter.connect();
    // { successful: true }

    // Successfull spec response
    await SPrinter.getPrinterSpecs();
    //{DeviceModel: 'T2-GPIOINT\n', PrintPaper: '80mm', PrinterVersion: '1.05\n', SerialNo: 'XXXXXXXXXXXXXXXXXXXX'}
} catch(e) {
    console.log(e.code) // Code for error
    console.log(e.message) // Message for error
}

Errors

| Error Code | Error Message | |------------|---------------| | -1 | Printer service empty, please connect printer first| | -2 | Remote exception error(refer to message to get more details) |

Table of Contents

connect

This function connects to the printer

Examples

// returns { success: true }
await SPrinter.connect();

Returns Promise<any> success message.

disconnect

This function disconnects the printer

Examples

// returns { success: true }
await SPrinter.disconnect();

Returns Promise<any> success message.

reset

This function resets any printing adjustments sent(e.g align or font size)

Examples

// returns { success: true }
await SPrinter.reset();

Returns Promise<any> success message.

testPrint

This function runs the default test print

Examples

// returns { success: true }
await SPrinter.testPrint();

Returns Promise<any> success message.

getPrinterSpecs

This function returns the printer specs including model, paper, printer version and serial no

Examples

// returns {DeviceModel: 'T2-GPIOINT\n', PrintPaper: '80mm', PrinterVersion: '1.05\n', SerialNo: 'XXXXXXXXXXXXXXXXXXXX'}
await SPrinter.getPrinterSpecs();

Returns Promise<any> Spec object.

getPrinterStatus

This function returns the printer current status such as printing or running

Examples

// returns "Printer is running"
await SPrinter.getPrinterStatus();

Returns Promise<String> success message.

cutPaper

This function cuts the paper

Examples

// returns { success: true }
await SPrinter.cutPaper();

Returns Promise<any> success message.

printText

This function prints a given text

Parameters

Examples

// returns { success: true }
await SPrinter.printText("Example of printing");

Returns Promise<any> success message.

printTextCustom

This function prints a given text with styling of text

Parameters

  • text String text to print
  • size Number size of text
  • isBold boolean whether text is bold
  • isUnderline boolean whether text is underelined
  • typeface String typeface of text

Examples

// returns { success: true }
await SPrinter.printTextCustom("Example of custom printing", "28", true, true, "gh");

Returns Promise<any> success message.

printEmptyLines

This function prints a number of empty lines

Parameters

Examples

// returns { success: true }
await SPrinter.printEmptyLines(3);

Returns Promise<any> success message.

setAlign

This function sets the alignment of next print

Parameters

  • align ALIGN align to set

Examples

// returns { success: true }
await SPrinter.setAlign(Constants.Align.CENTER);

Returns Promise<any> success message.

setFontSize

This function sets the font size of next print

Parameters

  • fontSize Number font size to set

Examples

// returns { success: true }
await SPrinter.setFontSize(28);

Returns Promise<any> success message.

printBarCode

This function prints a barcode given data

Parameters

  • data String data of barcode
  • symbology BARCODE_TYPE symbol of barcode type
  • height Number height of barcode
  • width Number width of barcode
  • textPosition BARCODE_TEXT_POSITION position of text

Examples

// returns { success: true }
await SPrinter.printBarCode("SecretABC", Constants.Barcode.CODE39, 90, 10, Constants.BarcodeText.ABOVE);

Returns Promise<any> success message.

printQRCode

This function prints a qr code given data

Parameters

  • data String data of qr code
  • modulesize Number module size of qr code
  • errorlevel QR_ERROR_LEVEL error level of qr code

Examples

// returns { success: true }
await SPrinter.printQRCode("URL TO SOME SECRET", 10, 15);

Returns Promise<any> success message.

printTable

This function prints a table given data

Parameters

  • texts Array<String> an array of texts to print
  • width Array<Number> an array defining width of corresponding text
  • align Array<Number> an array defining align of corresponding text

Examples

// returns { success: true }
await SPrinter.printTable(['a','b','c'], [3,3,5], [1,2,0]);

Returns Promise<any> success message.

printBase64Image

This function prints an image given the base 64 string

Parameters

  • base64 String base64 string of image

Examples

// returns { success: true }
await SPrinter.printBase64Image('some base 64 image string');

Returns Promise<any> success message.

ALIGN_CONSTANTS

Type: ALIGN

LEFT

Type: Number

CENTER

Type: Number

RIGHT

Type: Number

BARCODE_TYPE_CONSTANTS

Type: BARCODE_TYPE

UPCA

Type: Number

UPCE

Type: Number

JAN13

Type: Number

JAN8

Type: Number

CODE39

Type: Number

ITF

Type: Number

CODABAR

Type: Number

CODE93

Type: Number

CODE128

Type: Number

BARCODE_TEXT_POSITION_CONSTANTS

Type: BARCODE_TEXT_POSITION

NO_PRINT

Type: Number

ABOVE

Type: Number

BELOW

Type: Number

BOTH

Type: Number

QR_ERROR_LEVEL_CONSTANTS

Type: QR_ERROR_LEVEL

L

Type: Number

M

Type: Number

Q

Type: Number

H

Type: Number

License

MIT