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

printhub

v1.0.4

Published

A javascript plugin for Bluetooth & USB printers.

Downloads

129

Readme

PrintHub

npm version License: MIT

PrintHub

PrintHub adalah plugin JavaScript untuk mencetak teks menggunakan printer thermal Bluetooth atau USB Printer. Plugin ini mendukung dua ukuran kertas: "58mm" dan "80mm".

Fitur

  1. Mencetak teks dengan berbagai opsi seperti huruf tebal, garis bawah, perataan, dan ukuran teks.
  2. Mencetak teks dengan dua kolom.
  3. Mencetak garis putus-putus.
  4. Mencetak baris baru.
  5. Mendukung dua ukuran kertas: "58mm" dan "80mm".
  6. Mendukung koneksi ke printer thermal Bluetooth.
  7. Mendukung browser modern seperti Chrome, Firefox, dan Edge.
  8. Mendukung Node.js.
  9. Mendukung penggunaan CDN.
  10. Mendukung penggunaan NPM.
  11. Mendukung penggunaan ES6.

Instalasi

Menggunakan NPM

npm install printhub

import atau require PrintHub ke dalam proyek Anda.

import PrintHub from "printhub";

or

const PrintHub = require("printhub");

Menggunakan CDN

<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/index.min.js"></script>

Penggunaan

Membuat Instance dari PrintHub

Anda dapat membuat instance dari PrintHub dengan atau tanpa menentukan ukuran kertas yang diinginkan. Ukuran kertas yang didukung adalah "58mm" dan "80mm". Jika ukuran kertas tidak ditentukan, ukuran kertas default adalah "58mm".

  1. Membuat Instance PrintHub dengan Ukuran Kertas "80mm"
let printer = new PrintHub({
  paperSize: "80mm",
});
  1. Membuat Instance PrintHub dengan Ukuran Kertas "58mm"
let printer = new PrintHub();

Memilih Jenis Printer

Anda dapat memilih jenis printer yang akan digunakan. Jenis printer yang didukung adalah "bluetooth" dan "usb". Jika jenis printer tidak ditentukan, jenis printer default adalah "bluetooth".

  1. Memilih Jenis Printer "bluetooth"
let printer = new PrintHub({
  printerType: "bluetooth",
});
  1. Memilih Jenis Printer "usb"
let printer = new PrintHub({
  printerType: "usb",
});

Menghubungkan ke Printer dan Mencetak Teks

Gunakan metode connectToPrint untuk menghubungkan ke printer Bluetooth dan mencetak teks. Anda perlu menyediakan dua fungsi callback: onReady dan onFailed.

| Callback | Deskripsi | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------- | | onReady | Dipanggil ketika koneksi ke printer berhasil. Anda dapat menggunakan objek print yang diteruskan ke callback ini untuk mencetak teks. | | onFailed | Dipanggil ketika koneksi ke printer gagal. Anda dapat menggunakan parameter message untuk mendapatkan pesan error. |

Cara Menggunakan PrintHub

  1. Hubungkan ke printer dan cetak teks.

    printer.connectToPrint({
      onReady: async (print) => {
        await print.writeText("Hello, World!");
      },
      onFailed: (message) => {
        console.log(message);
      },
    });
  2. Cetak teks dengan huruf tebal.

    printer.connectToPrint({
      onReady: async (print) => {
        await print.writeText("Hello, World!", { bold: true });
      },
      onFailed: (message) => {
        console.log(message);
      },
    });
  3. Cetak teks dengan garis bawah.

    printer.connectToPrint({
      onReady: async (print) => {
        await print.writeText("Hello, World!", { underline: true });
      },
      onFailed: (message) => {
        console.log(message);
      },
    });
  4. Cetak teks dengan perataan.

    printer.connectToPrint({
      onReady: async (print) => {
        await print.writeText("Hello, World!", { align: "center" });
      },
      onFailed: (message) => {
        console.log(message);
      },
    });
  5. Cetak teks dengan ukuran teks.

    printer.connectToPrint({
      onReady: async (print) => {
        await print.writeText("Hello, World!", { size: "double" });
      },
      onFailed: (message) => {
        console.log(message);
      },
    });
  6. Cetak teks dengan dua kolom.

    printer.connectToPrint({
      onReady: async (print) => {
        await print.writeTextWith2Column("Name", "John Doe");
      },
      onFailed: (message) => {
        console.log(message);
      },
    });
  7. Cetak garis putus-putus.

    printer.connectToPrint({
      onReady: async (print) => {
        await print.writeDashLine();
      },
      onFailed: (message) => {
        console.log(message);
      },
    });
  8. Cetak baris baru.

    printer.connectToPrint({
      onReady: async (print) => {
        await print.writeLineBreak();
      },
      onFailed: (message) => {
        console.log(message);
      },
    });
  9. Cetak teks dengan berbagai opsi.

    printer.connectToPrint({
      onReady: async (print) => {
        await print.writeText("Hello, World!", {
          bold: true,
          underline: true,
          align: "center",
          size: "double",
        });
      },
      onFailed: (message) => {
        console.log(message);
      },
    });
  10. Cetak teks dengan berbagai opsi dan dua kolom.

    printer.connectToPrint({
      onReady: async (print) => {
        await print.writeTextWith2Column("Name", "John Doe", {
          bold: true,
          underline: true,
          align: "center",
          size: "double",
        });
      },
      onFailed: (message) => {
        console.log(message);
      },
    });

API

| Metode | Deskripsi | | --------------------------------------------- | -------------------------------------------------------------------------- | | writeLineBreak({ count = 1 }) | Menulis baris baru. | | writeDashLine() | Menulis garis putus-putus. | | writeTextWith2Column(text1, text2, options) | Menulis teks dengan dua kolom. | | writeText(text, options) | Menulis teks. | | connectToPrint({ onReady, onFailed }) | Menghubungkan ke printer dan memanggil callback onReady atau onFailed. |

Opsi untuk Metode writeText dan writeTextWith2Column

| Opsi | Deskripsi | Default | | ----------- | ------------------------------------------------------------------------- | ---------- | | bold | Menentukan apakah teks dicetak dengan huruf tebal. | false | | underline | Menentukan apakah teks dicetak dengan garis bawah. | false | | align | Menentukan perataan teks. Nilai yang didukung: "left", "center", "right". | "left" | | size | Menentukan ukuran teks. Nilai yang didukung: "normal", "double". | "normal" |

Requirements for USB Printer

Windows

  1. Install Zadig.
  2. Connect USB Printer to your computer.
  3. Open Zadig and select your USB Printer.
  4. Install WinUSB driver for your USB Printer.
  5. Done.

Linux

  1. Connect USB Printer to your computer.
  2. Open terminal and run lsusb.
  3. Find your USB Printer and note the vendor id and product id.
  4. Run sudo modprobe usblp.
  5. Run sudo echo "ATTRS{idVendor}=="YOUR_VENDOR_ID", ATTRS{idProduct}=="YOUR_PRODUCT_ID", MODE="0666", GROUP="plugdev" > /etc/udev/rules.d/99-usb-printer.rules.
  6. Run sudo udevadm control --reload-rules.
  7. Run sudo udevadm trigger.
  8. Done.

macOS

  1. Connect USB Printer to your computer.
  2. Open terminal and run ls /dev/cu.*.
  3. Find your USB Printer and note the device name.
  4. Run `sudo chmod
  5. Run `sudo chown
  6. Done.

Browser Support

Desktop

| Browser | Version | Status | | ------- | ------- | ------ | | Chrome | 61 | ✔️ | | Firefox | No | ❌ | | Edge | 79 | ✔️ | | Safari | No | ❌ | | Opera | 48 | ✔️ |

Mobile

| Browser | Version | Status | | ------- | ------- | ------ | | Chrome | 61 | ✔️ | | Firefox | No | ❌ | | Safari | No | ❌ | | Opera | 45 | ✔️ | | Samsung | 8.0 | ✔️ | | WebView | No | ❌ |

Change Log

v1.0.4

  • Add instructions for USB Printer on Windows, Linux, and macOS

v1.0.3

  • Fix USB Printer not working