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

tspl-generator

v1.0.1

Published

A TypeScript library for generating TSPL/TSPL2 commands for thermal label printers

Readme

TSPL Generator

CI/CD

A TypeScript library for generating TSPL (Taiwan Semiconductor Printer Language) / TSPL2 commands for thermal label printers.

Installation

npm

npm install tspl-generator

Browser Direct Download

For direct browser usage, you can download the latest browser bundle from:

Features

  • Strongly typed API with TypeScript
  • Fluent interface for easy command chaining
  • Support for all common TSPL/TSPL2 commands
  • Measurement system support (inches and millimeters)
  • Browser support via UMD bundle

Usage

Basic Example (Node.js)

import { TSPLPrinter, MeasurementSystem, Font } from "tspl-generator";

// Create a new printer instance
const label = new TSPLPrinter(MeasurementSystem.METRIC);

// Initialize with label size and settings
label.initialize({
  width: 100,
  height: 60,
  speed: 4,
  density: 8,
  gap: 3,
});

// Add text
label.addText({
  x: 10,
  y: 10,
  font: Font.FONT_1,
  text: "Hello World!",
});

// Add a barcode
label.addBarcode(10, 30, "128", 30, "12345678", 1);

// Print 2 copies
label.print(2);

// Get the generated TSPL code
const tsplCode = label.getBuffer();
console.log(tsplCode);

Browser Usage

You can use the library directly in a browser by including the UMD bundle:

<!-- Using CDN (recommended) -->
<script src="https://cdn.jsdelivr.net/npm/tspl-generator/dist/browser/tspl-generator.min.js"></script>

<!-- Or using a local file -->
<script src="path/to/tspl-generator.min.js"></script>

<script>
  // Create a new printer instance
  const printer = new TSPLGenerator.TSPLPrinter(
    TSPLGenerator.MeasurementSystem.METRIC
  );

  // Initialize with label size and settings
  printer.initialize({
    width: 100,
    height: 60,
    speed: 4,
    density: 8,
    gap: 3,
  });

  // Add text
  printer.addText({
    x: 10,
    y: 10,
    font: TSPLGenerator.Font.FONT_1,
    text: "Hello World!",
  });

  // Get the generated TSPL code
  const tsplCode = printer.getBuffer();
  console.log(tsplCode);
</script>

See the examples/browser-example.html file for a complete browser example.

Available Commands

The library supports the following TSPL/TSPL2 commands:

Printer Setup

  • SIZE - Set label size
  • GAP - Set gap distance
  • SPEED - Set print speed
  • DENSITY - Set print density
  • CLS - Clear image buffer

Text

  • TEXT - Print text
  • BLOCK - Print text block with word wrap

Barcodes

  • BARCODE - Print various barcode types
  • QRCODE - Print QR codes

Graphics

  • BOX - Draw rectangle
  • LINE - Draw line
  • CIRCLE - Draw circle
  • ELLIPSE - Draw ellipse

Images

  • BITMAP - Print bitmap image
  • PUTBMP - Print BMP file
  • PUTPCX - Print PCX file
  • DOWNLOAD - Download graphic to printer

Printing

  • PRINT - Print labels

API Reference

TSPLPrinter Class

The main class for generating TSPL commands.

Constructor

constructor(measurementSystem: MeasurementSystem = MeasurementSystem.ENGLISH)

Methods

  • initialize(config: LabelConfig): this - Initialize printer with basic settings
  • setGap(gap: number, offset: number = 0): this - Set gap between labels
  • addText(options: TextOptions): this - Add text to the label
  • addTextBlock(x: number, y: number, width: number, height: number, font: Font | string, text: string, ...): this - Add a text block with word wrap
  • addBarcode(x: number, y: number, barcodeType: BarcodeType | string, height: number, content: string, ...): this - Add a barcode
  • addQRCode(x: number, y: number, content: string, ...): this - Add a QR code
  • addBox(x: number, y: number, xEnd: number, yEnd: number, thickness: number = 1): this - Add a box
  • addLine(x: number, y: number, xEnd: number, yEnd: number, thickness: number = 1): this - Add a line
  • addCircle(x: number, y: number, diameter: number, thickness: number = 1): this - Add a circle
  • addEllipse(x: number, y: number, width: number, height: number, thickness: number = 1): this - Add an ellipse
  • addBitmap(x: number, y: number, width: number, height: number, bitmap: string, mode: 0 | 1 = 0): this - Add a bitmap image
  • addBMP(x: number, y: number, filename: string): this - Add a BMP image
  • print(copies: number = 1): this - Print labels
  • clear(): this - Clear the image buffer
  • getBuffer(): string - Get the generated TSPL code
  • reset(): this - Reset the buffer

License

ISC

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.