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

zplify

v1.0.0

Published

Generate a table in ZPL format based on a simple set of inputs

Downloads

12

Readme

ZPLify

Background

The ZPL language is used to pass data to Zebra thermal printers, which are commonly used to print receipts. In the case of this module, the principle focus is printing a food label based on a set of input data.

Install

In terminal, in the same directory as your node_modules directory: npm install zplify --save

In your module:

(function() {
  const zplify = require('zplify');

  // your code here
})();

Usage

The main method to be used is generateTable, which takes an object with 2 properties:

  1. rows - a matrix (array of arrays), in which each entry corresponds to a table row
  2. config - an object containing properties for modifying the default formatting

It is assumed that the first item in the rows array will an array of column titles, which receive slightly different styling than the rest of the rows.

Example:

zplify.generateTable({
  rows: [
    ['col1', 'col2'],
    ['row1col1', 'row1col2']
  ],
  config: {
    columnRatios: [.3, .7]
  }
});

// returns a table with 2 rows and 2 columns, where row contains the column names

Config parameters

  • columnRatios

    • type: Array

    • default: [] (evaluates to evenly spaced columns)

    • description: specifiy custom widths for the table columns

    • notes:

      • must contain an equal number of items as the columns array
      • entries must add up to 1
      • each entry must be greater than 0 and less than 1

    example:

      zplify.generateTable({
        rows: [
          ['id', 'name', 'qty', 'price'],
          ['1', 'Delicious Dog Food', '2', '42']
        ],
        config: {
          columnRatios: [.1, .7, .1, .1] // same number of values as the first row
        }
      });
  • labelWidth

    • type: Number

    • unit: inches

    • default: 4

    • descripton: specify the total width of the label

    • notes:

      • width must be greater than 0
  • labelHeight

    • type: Number

    • unit: inches

    • default: 6

    • description: specify the total height of the label

    • notes:

      • height must be greater than 0
  • printDensity

    • type: Number
    • unit: DPI (dots per inch)
    • default: 203 (8 dpmm)
    • description: specify the dot resolution of the print
  • labelPadding

    • type: Number
    • unit: dots
    • default: 50
    • description: specify the amount of space you'd like around the table
  • borderWidth

    • type: Number
    • unit: dots
    • default: 3
    • description: specify how thick youd like the lines on the table to be
  • fontSize

    • type: Number
    • unit: dots
    • default: 30
    • description: specify how big you'd like the font to be
  • maxRowHeight

    • type: Number
    • unit: dots
    • default: twice the fontSize (so, 60 dots; see above)
    • description: specify the maximum height you'd like a row to be
  • rowHeight

    • type: Number
    • unit: dots
    • default: equal to the maxRowHeight (so, 60 dots; see above)
    • description: specify the height that you'd like each row to be
  • cellPadding

    • type: Number
    • unit: dots
    • default: 20
    • description: specify the amount of space you'd like to the left of each cell value
    • notes:
      • this does not apply to cells that have been horizontally centered

Testing

To see how the table you generated looks, you can use Labelary.

A bit about the logic

ZPL II is not backwards compatable with ZPL I [1], which is to say that an interpreter expecting ZPL II code will not necessarily return the correct results given an input in the ZPL I format. As such, I've elected to use the more recent version, ZPL II.

I may choose to add more features in following versions. If you'd like to request a feature, please reach out to [email protected]. Here are some I'm thinking might be useful:

  1. configuration option to produce output in the ZPL I format.
  2. overflow detection for a cell & handling protocol (wrap, throw error, or custom handler)

Resources

Learn more about the Zebra programming language here:

  1. Wikipedia article