raystanza / escpos-template

Library to process json template for thermal printers coupons

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 path = require('path')

const connection = new InMemory()
const printer = new Printer(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 image = new Image(path.join(__dirname, 'sample.png'))

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

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

printer.feed(2)
printer.buzzer()
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.

About

Library to process json template for thermal printers coupons

License:MIT License


Languages

Language:TypeScript 98.9%Language:JavaScript 1.1%