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

@dailykit/xml-escpos-helper

v1.0.3

Published

ESC/POS with XML interface

Downloads

30

Readme

Originally forked from here

ESC/POS XML

Cross platform JavaScript library that implements the thermal printer ESC / POS protocol and provides an XML interface for preparing templates for printing.

Features

  • [x] Text
  • [x] Text line
  • [x] Feed line
  • [x] Bold text
  • [x] Underline text
  • [x] Font size
  • [x] Small mode
  • [x] White mode
  • [x] Align
  • [x] Barcode
  • [x] QRcode
  • [x] Paper cut node
  • [x] Image (base64) (png only)
  • [x] XML with mustache

Tested manually on following environments or platforms

  • [x] React Native (Android)
  • [x] React Native (iOS)
  • [x] React Native Web
  • [x] Server side (NodeJs)
  • [x] Desktop applications (nwjs & electron)
  • [x] Other node environment (terminal)

Installation

  yarn add @dailykit/xml-escpos-helper

Examples

With an XML template + plain object input (regular text).

import { EscPos } from '@dailykit/xml-escpos-helper';

// store this template somewhere `s3` or as `static asset` based on your preference
const template = `
  <?xml version="1.0" encoding="UTF-8"?>
  <document>
    <align mode="center">
      <bold>
        <text-line size="1:0">{{title}}</text-line>
      </bold>
    </align>

    {{#thankyouNote}}
    <align mode="center">
      <text-line encoding="cp864" codepage="22" size="0:0">  {{{thankyouNote}}}</text-line>
    </align>

    <line-feed />

    <paper-cut />
  </document>
`;

// if encoding & codepage in text-line is not mentioned (by default it is set to utf8 & 0 respectively)

const input = {
  title: 'Sample',
  thankyouNote: 'أهلا بك',
};

const options = {
  wrapWord: false, //true by default
  wrapWordMaxLength: 48, // 32 by default
};

const buffer = EscPos.getBufferFromTemplate(template, input, options);
// send this buffer to a stream (eg.: bluetooth or wifi)

With an XML template + png image (base64)

const template = `<?xml version="1.0" encoding="UTF-8"?>
  <document>
    <align mode="center">
      <bold>
        <text-line size="1:0">{{title}}</text-line>
      </bold>

      <image density="d24">
        {{base64PngImage}}
      </image>
    </align>
  </document>`;

const input = {
  title: 'PNG - base64',
  base64PngImage: `data:image/png;base64,iVBORw0KGgoAAA+P/AaNn2GPEMgEFAAAAAElFTkSuQmCC`,
};

const buffer = EscPos.getBufferFromTemplate(template, input);

TODO

  • [ ] Font styles (font family)
  • [ ] Image bitmap conversion improvements
  • [ ] jpeg support
  • [ ] Add example apps to repo
  • [ ] Removed uglify for some reason, need to bring it back
  • [ ] Improve image rendering

Common issues

  • If there is any delay you observe while printing with this library it is mostly due to image manipulations (try without image :mask: )

Useful links / resources

Limitations on the react-native framework

  • FileReader.readAsArrayBuffer was not implemented.
  • Most of popular image manupulation libraries does not have support for react-native. eg : jimp, jpeg-js and sharp. We can use these libraries with some native node lib implemented in react native (some sort of polyfill).
  • For png this library seems to be faster, but when tested this library with it, it is not retaining pixels at some places)
  • Use this node-libs-react-native if we need to use this library in react native (adds some mock or js implementation for fs, stream etc)

Contributions of any kind welcome! :heart: