vegeto
Version:
Simple micro templating with JavaScript expression support.
27 lines (21 loc) • 771 B
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.vegeto = factory());
}(this, (function () { '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
})
};
return index;
})));