UNPKG

vegeto

Version:

Simple micro templating with JavaScript expression support.

21 lines (16 loc) 531 B
'use strict'; var index = function ( tpl, data, ref ) { if ( tpl === void 0 ) tpl = ''; if ( data === void 0 ) data = {}; if ( ref === void 0 ) ref = {}; var delimiters = ref.delimiters; if ( delimiters === void 0 ) delimiters = ['{{', '}}']; var re = new RegExp(((delimiters[0]) + "([\\s\\S]+?)" + (delimiters[1])), 'g'); return tpl.replace(re, function (_, exp) { return new Function('data', ("with (data) {return " + exp + "}"))(data) // eslint-disable-line no-new-func }) }; module.exports = index;