Socket
Book a DemoInstallSign in
Socket

escpos-template

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

escpos-template

Library to process json template for thermal printers coupons.

2.0.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

TypeScript version Node.js version MIT Build Status

ESC/POS Template Processing Library

Library to process json template for thermal printers coupons.

Install

Run command bellow on your project folder

yarn add escpos-template

or

npm install escpos-template

Basic example

const { Printer, Model, InMemory, Image } = require('escpos-buffer')
const { ObjectProcessor } = require('escpos-template')
const { ImageManager } = require('escpos-buffer-image')
const path = require('path')

const connection = new InMemory()
const printer = await Printer.CONNECT(new Model('MP-4200 TH'), connection)

const template = [
  { items: 'coupon.title', align: 'center', style: 'bold+', width: '2x' },
  '',
  { items: 'Qrcode', align: 'right' },
  { type: 'qrcode', data: 'https://github.com/grandchef/escpos-template', align: 'right' },
  '',
  { items: 'picture.title', align: 'center', height: '2x' },
  { type: 'image', data: 'picture.image', align: 'center' },
  { whitespace: '=' }
]

const imageManager = new ImageManager()
const imageData = await imageManager.loadImage(
  path.join(__dirname, 'sample.png'),
)
const image = new Image(imageData)

const data = {
  coupon: {
    title: 'Coupon Title'
  },
  picture: {
    title: 'Picture Title',
    image
  }
}

const coupon = new ObjectProcessor(data, printer, template)
await coupon.print()

await printer.feed(2)
await printer.buzzer()
await printer.cutter()
process.stdout.write(connection.buffer())

// to print, run command bellow on terminal
//> node examples/basic.js | lp -d MyCupsPrinterName

Available scripts

  • clean - remove coverage data, Jest cache and transpiled files,
  • build - transpile TypeScript to ES6,
  • build:watch - interactive watch mode to automatically transpile source files,
  • lint - lint source files and tests,
  • test - run tests,
  • test:watch - interactive watch mode to automatically re-run tests
  • test:debug - run tests debugging

License

Licensed under the MIT. See the LICENSE file for details.

FAQs

Package last updated on 29 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.