import AsyncHelpers from "async-helpers"; import bwipjs from "bwip-js"; export const asyncHelpers = new AsyncHelpers(); async function generateBarcode(str, options, emtpy, cb) { let res = await generateBase64Barcode(options.toString(), str.toString()); cb(null, res); } generateBarcode.async = true; asyncHelpers.set('--bc', generateBarcode); export const helpers = asyncHelpers.get({ wrap: true }); export async function generateBase64Barcode(type: string, content: string): Promise { let barcode: Buffer = await bwipjs.toBuffer({ bcid: type, text: content, scale: 3, height: 10, includetext: true, textxalign: 'center', }); return `data:image/png;base64,${barcode.toString('base64')}`; } export async function awaitAsyncHandlebarHelpers(input: string): Promise { return await new Promise((resolve, reject) => { asyncHelpers.resolveIds(input, (err, data) => { if (err) { reject(err) } resolve(data) }); }); }