-
Notifications
You must be signed in to change notification settings - Fork 0
/
simplate.min.js
1 lines (1 loc) · 1.98 KB
/
simplate.min.js
1
!function(){"use strict";var e={};e.cache={},e.insertHTML="",e.TAGS={evaluate:/\{\{([\s\S]+?(\}?)+)\}\}/g,interpolate:/\{\{=([\s\S]+?)\}\}/g,nonescape:/\{\{!([\s\S]+?)\}\}/g,comment:/\{\{#([\s\S]+?)\}\}/g},e.SETTINGS={cache:!0,escape:!0,debug:!0},e.utils={$copy:function(e){return JSON.parse(JSON.stringify(e))},$isArray:Array.isArray()||function(e){return{}.toString().call(e)},$escapeHTML:function(n){return n.replace(/[&<>"'`=\/]/g,function(n){return e.escapeMap[n]})}},e.config=function(e,n){var t=this;if(n&&"string"==typeof e)t.SETTINGS[e]=n;else if(n||"object"!=typeof e)console.log("Error: Type error!");else for(var r in e)e.hasOwnProperty(r)&&(t.SETTINGS[r]=e[r])},e.escapeMap={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="},e.skip=/$^/,e.template=function(e,n,t){function r(e){return e.replace(/\\('|\\)/g,"$1").replace(/[\r\t\n]/g," ")}var o=this;t=t||{};for(var c in o.SETTINGS)"undefined"===t[c]&&(t[c]=o.SETTINGS[c]);e=("var $out = '"+e.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g," ").replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g,"").replace(/'|\\/g,"\\$&").replace(o.TAGS.comment||o.skip,function(e,n){return"' /* "+r(n)+" */ + '"}).replace(o.TAGS.interpolate||o.skip,function(e,n){return"' + ("+r(n)+") + '"}).replace(o.TAGS.nonescape||o.skip,function(e,n){return"' + simplate.utils.$escapeHTML("+r(n)+") + '"}).replace(o.TAGS.evaluate||o.skip,function(e,n){return"';"+r(n)+"$out += '"})+"';return $out;").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r").replace(/(\s|;|\}|^|\{)\$out\+='';/g,"$1").replace(/\+''/g,"");try{return new Function("data",e)}catch(n){throw"undefined"!=typeof console&&console.error("Cannot create a template function: \n"+e),n}},e.VERSION="0.1.0","undefined"!=typeof document&&document.body&&(e.insertHTML=document.body.innerHTML);var n=function(){return this||(0,eval)("this")}();"undefined"!=typeof module&&module.exports?module.exports=e:"function"==typeof define&&define.amd?define(function(){return e}):n.simplate=e}();