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

sdk-printer

v0.0.7

Published

printer for kiosk

Readme

sdk-printer

printer for kiosk

Install

npm install sdk-printer
npx cap sync

API

connect()

connect() => Promise<{ success: boolean; message: string; }>

Returns: Promise<{ success: boolean; message: string; }>


close()

close() => Promise<void>

resetFont()

resetFont() => Promise<void>

getStatus()

getStatus() => Promise<{ status1: number; status2: number; }>

Returns: Promise<{ status1: number; status2: number; }>


outputString(...)

outputString(options: { str: string; }) => Promise<void>

| Param | Type | | ------------- | ----------------------------- | | options | { str: string; } |


outputStringLn(...)

outputStringLn(options: { str: string; }) => Promise<void>

| Param | Type | | ------------- | ----------------------------- | | options | { str: string; } |


printBarcode(...)

printBarcode(options: { type: number; str: string; }) => Promise<void>

| Param | Type | | ------------- | ------------------------------------------- | | options | { type: number; str: string; } |


printQRcode(...)

printQRcode(options: { data: string; }) => Promise<void>

| Param | Type | | ------------- | ------------------------------ | | options | { data: string; } |


cutPaper()

cutPaper() => Promise<void>

printFormattedText(...)

printFormattedText(options: { text: string; }) => Promise<void>

| Param | Type | | ------------- | ------------------------------ | | options | { text: string; } |


printText(...)

printText(options: { text: string; logoBase64?: string; }) => Promise<void>

| Param | Type | | ------------- | --------------------------------------------------- | | options | { text: string; logoBase64?: string; } |


doFunction(...)

doFunction(options: { func: number; param1: number; param2: number; }) => Promise<void>

| Param | Type | | ------------- | -------------------------------------------------------------- | | options | { func: number; param1: number; param2: number; } |


Constants for doFunction

export const TX_CONSTANTS = {
  // --- TRẠNG THÁI ON/OFF ---
  TX_ON: 1,
  TX_OFF: 0,

  // --- 1. CỠ CHỮ (TX_FONT_SIZE) ---
  // param1: Chiều rộng (0-7), param2: Chiều cao (0-7)
  // 0: Bình thường (1x), 1: 2x, 2: 3x ... 7: 8x
  TX_FONT_SIZE: 1,
  TX_SIZE_1X: 0,
  TX_SIZE_2X: 1,
  TX_SIZE_3X: 2,
  TX_SIZE_4X: 3,
  TX_SIZE_8X: 7,

  // --- 2. GẠCH CHÂN (TX_FONT_ULINE) ---
  TX_FONT_ULINE: 2,

  // --- 3. IN ĐẬM (TX_FONT_BOLD) ---
  TX_FONT_BOLD: 3,

  // --- 4. CHỌN FONT (TX_SEL_FONT) ---
  TX_SEL_FONT: 4,
  TX_FONT_A: 0, // 12x24 (Font chuẩn)
  TX_FONT_B: 1, // 9x17 (Font nhỏ)

  // --- 5. XOAY 90 ĐỘ (TX_FONT_ROTATE) ---
  TX_FONT_ROTATE: 5,

  // --- 6. CĂN LỀ (TX_ALIGN) ---
  TX_ALIGN: 6,
  TX_ALIGN_LEFT: 0,
  TX_ALIGN_CENTER: 1,
  TX_ALIGN_RIGHT: 2,

  // --- 7. CHẾ ĐỘ TIẾNG VIỆT/TRUNG (TX_CHINESE_MODE) ---
  TX_CHINESE_MODE: 7,

  // --- 10. ĐẨY GIẤY (TX_FEED) ---
  // Đơn vị: 0.125mm (Ví dụ feed 10mm thì param1 = 80)
  TX_FEED: 10,

  // --- 12. CẮT GIẤY (TX_CUT) ---
  TX_CUT: 12,
  TX_CUT_FULL: 0, // Cắt đứt hoàn toàn (Có check black mark)
  TX_CUT_PARTIAL: 1, // Cắt 1 phần (Có check black mark)
  TX_PURECUT_FULL: 2, // Cắt đứt hoàn toàn (Không check black mark - Thường dùng cái này)
  TX_PURECUT_PARTIAL: 3, // Cắt 1 phần (Không check black mark)

  // --- 14. KHOẢNG CÁCH DÒNG (TX_LINE_SP) ---
  TX_LINE_SP: 14,

  // --- 15. ĐẢO MÀU ĐEN TRẮNG (TX_BW_REVERSE) ---
  TX_BW_REVERSE: 15,

  // --- 16. LỘN NGƯỢC ĐẦU (TX_UPSIDE_DOWN) ---
  TX_UPSIDE_DOWN: 16,

  // --- 22. IN LOGO (TX_PRINT_LOGO) ---
  TX_PRINT_LOGO: 22,
  TX_LOGO_1X1: 0, // Kích thước thật

  // --- 23. MÃ VẠCH (BARCODE) ---
  TX_BARCODE_HEIGHT: 23, // Chiều cao
  TX_BARCODE_WIDTH: 24, // Độ rộng nét (>=2)
  TX_BARCODE_FONT: 25, // Vị trí chữ số HRI
  TX_BAR_FONT_NONE: 0,
  TX_BAR_FONT_UP: 1,
  TX_BAR_FONT_DOWN: 2, // Chữ nằm dưới mã vạch
  TX_BAR_FONT_BOTH: 3,

  // --- 26. ĐẨY GIẤY NGƯỢC (TX_FEED_REV) ---
  TX_FEED_REV: 26,

  // --- 27. QR CODE SIZE (TX_QR_DOTSIZE) ---
  TX_QR_DOTSIZE: 27, // 2 < param1 < 10 (Thường dùng 6)

  // --- 28. QR ERROR LEVEL (TX_QR_ERRLEVEL) ---
  TX_QR_ERRLEVEL: 28,
  TX_QR_ERRLEVEL_L: 0x31,
  TX_QR_ERRLEVEL_M: 0x32, // Trung bình (Thường dùng)
  TX_QR_ERRLEVEL_Q: 0x33,
  TX_QR_ERRLEVEL_H: 0x34, // Cao nhất
};

Examples

Kết nối máy in

const connectPrinter = async () => {
  try {
    const res = await PrinterPlugin.connect();
    if (res.success) {
      console.log('✅ Kết nối thành công:', res.message);
    }
  } catch (err: any) {
    console.error('❌ Kết nối thất bại:', err.message);
  }
};

In hóa đơn

// Hàm helper in 2 cột căn đều
const printTwoCol = async (left: string, right: string) => {
  const TOTAL_WIDTH = 32;
  const spaceLen = Math.max(0, TOTAL_WIDTH - left.length - right.length);
  const line = left + ' '.repeat(spaceLen) + right;
  await PrinterPlugin.outputStringLn({ str: line });
};

// In hóa đơn mẫu
const printReceipt = async () => {
  try {
    await PrinterPlugin.resetFont();

    // Header - Center, Bold, Large
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_ALIGN,
      param1: TX_CONSTANTS.TX_ALIGN_CENTER,
      param2: 0,
    });
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FONT_BOLD,
      param1: TX_CONSTANTS.TX_ON,
      param2: 0,
    });
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FONT_SIZE,
      param1: TX_CONSTANTS.TX_SIZE_2X,
      param2: TX_CONSTANTS.TX_SIZE_2X,
    });
    await PrinterPlugin.outputStringLn({ str: 'RECEIPT' });

    // Reset size & bold
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FONT_SIZE,
      param1: TX_CONSTANTS.TX_SIZE_1X,
      param2: TX_CONSTANTS.TX_SIZE_1X,
    });
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FONT_BOLD,
      param1: TX_CONSTANTS.TX_OFF,
      param2: 0,
    });
    await PrinterPlugin.outputStringLn({ str: 'Date: 20/12/2025' });

    // Items
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_ALIGN,
      param1: TX_CONSTANTS.TX_ALIGN_LEFT,
      param2: 0,
    });
    await PrinterPlugin.outputStringLn({ str: '--------------------------------' });
    await printTwoCol('Item', 'Price');
    await PrinterPlugin.outputStringLn({ str: '--------------------------------' });

    const items = [
      { name: 'Coffee', price: 50000 },
      { name: 'Tea', price: 30000 },
    ];

    for (const item of items) {
      await printTwoCol(item.name, item.price.toString());
    }

    // Total
    await PrinterPlugin.outputStringLn({ str: '--------------------------------' });
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FONT_BOLD,
      param1: TX_CONSTANTS.TX_ON,
      param2: 0,
    });
    await printTwoCol('Total', '80000');
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FONT_BOLD,
      param1: TX_CONSTANTS.TX_OFF,
      param2: 0,
    });

    // Footer
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_ALIGN,
      param1: TX_CONSTANTS.TX_ALIGN_CENTER,
      param2: 0,
    });
    await PrinterPlugin.outputStringLn({ str: 'Thank you!' });

    // Cut paper
    await PrinterPlugin.doFunction({
      func: TX_CONSTANTS.TX_FEED,
      param1: 100,
      param2: 0,
    });
    await PrinterPlugin.cutPaper();

    console.log('✅ In thành công');
  } catch (err: any) {
    console.error('❌ Lỗi in:', err.message);
  }
};