UNPKG

stp

Version:

基于 es6 模板字符串的超简模板引擎

8 lines 281 B
module.exports = function stp(strTmpl, data) { if (data !== null && data !== undefined) { return stp(strTmpl)(data); } strTmpl = strTmpl.replace(/\\/g, '\\\\'); strTmpl = strTmpl.replace(/`/g, '\\`'); return new Function("$", "with($){return `" + strTmpl + '`;}'); };