UNPKG

mew-template

Version:

Precompile template to cmd module

15 lines (13 loc) 477 B
module.exports = { compile: function(str) { var strFunc = "var out=[];with(data){out.push('" + str.replace(/[\r\t\n]/g, " ") .replace(/'(?=[^%]*%>)/g, "\t") .split("'").join("\\'") .split("\t").join("'") .replace(/<%=(.+?)%>/g, "',$1,'") .split("<%").join("');") .split("%>").join("out.push('") + "');}return out.join('');"; return new Function("data", strFunc); } };