zpl-handlebars
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

zpl-handlebars

NPM version build status Test coverage npm download

ZPL label templating using Handlebars.

Installation

$ npm i zpl-handlebars

Usage

import { compile } from 'zpl-handlebars';
import { Image } from 'image-js';
 
const template = `
^XA
^FO150,125^ADN,36,20^FD{{data.value1}}^FS
^FO100,100^XGR:{{images.myImage}},1,1^FS
^XZ
`;
 
const compiled = compile(template);
 
// prettier-ignore
const myImage = new Image(8, 4, [ // Or load any image with Image.load()
    0,   0,   0,   0,   0,   0,   0,   0,
  255,   0, 255, 255,   0, 255, 255, 255,
  255, 255,   0, 255, 255, 255, 255,   0,
  255, 255, 255, 255, 255, 255, 255, 255
  // @ts-ignore
], { kind: 'GREY' });
 
const zpl = compiled({ data: { value1: 'TEST' }, images: { myImage } });
/*
~DGR:00000000.GRF,4,1,
FF
48
21
00
^XA
^FO150,125^ADN,36,20^FDTEST^FS
^FO100,100^XGR:00000000.GRF,1,1^FS
^XZ
*/

Helpers

toFixed

Formats a value using Number(value).toFixed(decimals).
The decimals parameter is optional and defaults to 2.

{{toFixed data.value}}
{{toFixed data.value 3}}

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i zpl-handlebars

Weekly Downloads

12

Version

1.1.0

License

MIT

Unpacked Size

20.9 kB

Total Files

16

Last publish

Collaborators

  • zakodium-bot
  • lpatiny
  • targos
  • stropitek