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

bluetooth-print-js

v1.0.2

Published

A javascript plugin for Bluetooth printers.

Downloads

24

Readme

PrintPlugin

npm version License: MIT

PrintPlugin adalah plugin JavaScript untuk mencetak teks menggunakan printer thermal Bluetooth. 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 bluetooth-print-js

import atau require PrintPlugin ke dalam proyek Anda.

import PrintPlugin from "bluetooth-print-js";

or

const PrintPlugin = require("bluetooth-print-js");

Menggunakan CDN

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

Penggunaan

Membuat Instance dari PrintPlugin

Anda dapat membuat instance dari PrintPlugin 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".

// Create instance with paper size "80mm"
let printer = new PrintPlugin("80mm");

or

// Create instance with default paper size "58mm"
let printer = new PrintPlugin();

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.

  • 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 PrintPlugin

  1. Hubungkan ke printer dan cetak teks.

    printer.connectToPrint({
      onReady: async (print) => {
        await print.writeText("Hello, World!");
      },
      onFailed: (message) => {
        console.log(message);
      },
    });
  2. Contoh penggunaan lengkap (HTML):

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Bluetooth Print</title>
  </head>
  <body>
    <h1>Bluetooth Print</h1>
    <button id="connect">Connect and Print</button>
    <p id="status"></p>

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/index.min.js"></script>
    <script>
      document.getElementById("connect").addEventListener("click", () => {
        let printer = new PrintPlugin("80mm");
        printer.connectToPrint({
          onReady: async (print) => {
            // Print Header
            await print.writeText("SADIGIT", {
              align: "center",
              bold: true,
              size: "double",
            });
            await print.writeText(
              "Jl. Kutamaya No.Ruko A, Kotakulon, Kec. Sumedang Sel., Kabupaten Sumedang, Jawa Barat 45311",
              { align: "center" }
            );
            await print.writeText("0852-2299-9699", { align: "center" });
            await print.writeLineBreak();
            await print.writeText("No.Transaksi: SDGT-ONL-0001", {
              align: "center",
            });
            await print.writeText("Kasir: Otongsuke", { align: "center" });
            await print.writeText("2024-10-23 10:20:18", { align: "center" });

            // Print Items
            await print.writeDashLine();
            for (let i = 0; i < 5; i++) {
              await print.writeText("Item Sample-" + i, { align: "left" });
              await print.writeTextWith2Column("1 pcs x 10.000", "10.000");
            }
            await print.writeDashLine();

            // Print Total
            await print.writeTextWith2Column("Total :", "50.000");
            await print.writeTextWith2Column("Bayar :", "100.000");
            await print.writeTextWith2Column("Kembali :", "50.000");
            await print.writeTextWith2Column("Metode :", "Tunai");

            // Print Footer
            await print.writeLineBreak();
            await print.writeText(
              "Terimakasih sudah mencoba Follow IG @sadigit.id",
              { align: "center" }
            );
            await print.writeLineBreak(3);
          },
          onFailed: (message) => {
            console.log(message);
          },
        });
      });
    </script>
  </body>
</html>

Metode yang Tersedia

  • 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

  • bold: Menentukan apakah teks dicetak dengan huruf tebal. (default: false)
  • underline: Menentukan apakah teks dicetak dengan garis bawah. (default: false)
  • align: Menentukan perataan teks. Nilai yang didukung: "left", "center", "right". (default: "left")
  • size: Menentukan ukuran teks. Nilai yang didukung: "normal", "double". (default: "normal")