zpl-handlebars
v1.1.0
Published
ZPL label templating using Handlebars
Downloads
1
Readme
zpl-handlebars
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}}