import * as Handlebars from 'handlebars' ; import { IAttachmentOptions } from '../template/template.interface' ; Handlebars . registerHelper ( 'equals' , function helper ( this , arg1 , arg2 , options ) { return arg1 == arg2 ? options . fn ( this ) : options . inverse ( this ) ; } ) ; type HandlebarsContext = { [ key ] : string | { key : string ; } [ ] | { key : string | number ; } | string [ ] | number [ ] | boolean | number | undefined | IAttachmentOptions | IAttachmentOptions [ ] ; } ; export function compileTemplate ( content , data ) { const template = Handlebars . compile < HandlebarsContext > ( content ) ; return template ( data ) ; } export function getHandlebarsVariables ( input ) { const ast = Handlebars . parseWithoutProcessing ( input ) ; return ast . body . filter ( ( { type } ) => type === 'MustacheStatement' ) . map ( ( statement ) => { const moustacheStatement = statement as hbs . AST . MustacheStatement ; const paramsExpressionList = moustacheStatement . params as hbs . AST . PathExpression [ ] ; const pathExpression = moustacheStatement . path as hbs . AST . PathExpression ; return paramsExpressionList [ 0 ] ?. original || pathExpression . original ; } ) ; }