New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

Templ8

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Templ8 - npm Package Compare versions

Comparing version 0.10.4 to 0.10.5

2

package.json

@@ -36,3 +36,3 @@ {

},
"version" : "0.10.4"
"version" : "0.10.5"
}

@@ -67,3 +67,3 @@ ( function() {

},
re_for_split = /^(\[[^,]+,\s*[^\]]+\]|[^\s]+)(?:\s+in\s+([^\s\[]+)){0,1}\s*(?:\[?(\d+)\.+(\d*)]*\]?){0,1}/i,
re_for_split = /^(\[[^,]+,\s*[^\]]+\]|[^\s]+)(?:\s+in\s+([^\s\[]+)){0,1}\s*(?:\[?(\d*)\.+(\d*)]*\]?){0,1}/i,
re_keys = /(\w+)/g;

@@ -70,0 +70,0 @@

@@ -674,3 +674,3 @@ ;!function( util, Name, PACKAGE ) {

},
re_for_split = /^(\[[^,]+,\s*[^\]]+\]|[^\s]+)(?:\s+in\s+([^\s\[]+)){0,1}\s*(?:\[?(\d+)\.+(\d*)]*\]?){0,1}/i,
re_for_split = /^(\[[^,]+,\s*[^\]]+\]|[^\s]+)(?:\s+in\s+([^\s\[]+)){0,1}\s*(?:\[?(\d*)\.+(\d*)]*\]?){0,1}/i,
re_keys = /(\w+)/g;

@@ -677,0 +677,0 @@

@@ -1,1 +0,1 @@

!function(t,e,n){"use strict";function r(e,n){return e&&"function"==typeof e.indexOf&&!!~e.indexOf(n)||t.got(e,n)}function i(t){return(t+"").replace(G,H)}function s(e,n){if(!n)return ue[e]||null;var r;do if(r=t.format(pe,n.id,e),r in ue)return ue[r];while(n=n.parentTemplate);return ue[e]||null}function a(t){return"object"==typeof t&&(t.constructor===Object||t.constructor===N)}function u(e,n,r){n||(n=t),r||(r=e);for(var i,s=-1,a=e.length,u=[];a>++s;)switch(i=n.call(r,e[s],s,e)){case null:case N:break;default:switch(typeof i){case"string":""===i.trim()||u.push(i);break;case"number":isNaN(i)||u.push(i);break;default:!t.iter(i)||t.len(i)||u.push(i)}}return u}function o(e){return!t.empty(e)}function c(e,n){switch(this[P]=[],this.tpl=n,this.push(t.global),n.fallback!==N&&(this.hasFallback=!0,this.fallback=n.fallback),t.ntype(e)){case"object":this.push(e);break;case"array":e[M.dict]?e.map(this.push,this):this.push(e);break;default:!t.exists(e)||this.push(e)}}function f(e,n,r,i){var s=Object.keys(e=this._=Object(e)),a=s.length;return a?("[object Object]"==t.tostr(e)||(s=s.map(Number)),this.empty=!1,this.count=isNaN(i)?a:0>i?a+i:i>a?a:i,0==r||isNaN(r)?(this.firstIndex=0,this.index=-1):(this.firstIndex=r,this.index=r-2),this.index1=this.index+1,this.lastIndex=this.count===a?this.count-1:this.count,this.keys=s,!(n instanceof f)||(this.parent=n),void 0):this.stop()}function h(e,n){return t.empty(n)||e.push(n),e}function l(e,n){return n.reduce(function(n,r,i){if(0==i)return k(e,r);var s,a="",u=r.indexOf(":");return~u?(s=r.substring(0,u),a=r.substring(u+1)):s=r,!a||(a=", "+a.split(",").map(function(t){return k(this,t)},e).join(", ")),t.format(le,b(s),s,k(e,n),a,M.ctx)},"")}function p(t,e){for(var n,r=[X];n=e.shift();)r.push(y(t,n,e));return r.push(V),r.join("\r\n")}function d(t){return t.replace(Y,"").replace(Z,"\n").replace(te," ").trim()}function m(e,n){n=t.format(oe,"*",e.__tpl__.replace(Q,"$1 \\$2"),n,e.sourceURL?e.sourceURL:t.format(he,e.id));var r=Function("root","ContextStack","Iter",M.filter,M.assert,M.util,M.ctx,n);return r.bind(e,t.global,c,f,t.copy(e.filters,E.Filter.all(),!0),K,F)}function g(t){t.currentIterKeys=[];var e=m(t,p(t,x(t.__tpl__)));return delete t.currentIterKeys,e}function y(e,n,r){var i;return(i=E.Tag.get(n))?(n=r.shift(),i.emit(R,e,n,r)):I(t.format('"{0}"',n.replace(J,"\\$1")))}function _(t,e){switch(e=d(e)){case"AND":return" && ";case"OR":return" || "}return r(e,"|")||r(e,D)?(" "+e+D).replace(ie,function(e){return K.blank(e)||e==D?"":l(t,d(e).split("|"))}):k(t,e)}function b(t){return K[t]?M.assert:F[t]?M.util:M.filter}function x(t){return t.replace(L,ae).split(se).reduce(h,[])}function w(e,n){switch(typeof e){case"boolean":case"number":case"string":return e+"";default:switch(t.ntype(e)){case"date":return e.toDateString();case"array":return u(e,w).join(", ");case"object":return W in e?w(e.dict):"[object Object]"!=(n=""+e)?n:u(Object.values(e),w).join(", ");default:switch(t.type(e)){case"htmlelement":return e.outerHTML;case"htmlcollection":return u(Array.coerce(e),function(t){return w(t)}).join("\n")}}}return""}function v(t){return this==t||K.startsWith(this,t+".")}function j(t,e){return t.length?t.some(function(t){return t.some(v,e)}):0}function k(e,n){var i=e.currentIterKeys||[];return n=d(n),r(n,".call(")||ee.test(n)||K.startsWith(n,'"')&&K.endsWith(n,'"')||K.startsWith(n,"'")&&K.endsWith(n,"'")||!isNaN(n)?n:K.startsWith(n,"$_.")||K.startsWith(n,"iter.")||i.length&&j(i,n)||n in C?n.replace(ne,re):t.format('$C.get( "{0}" )',n)}function I(e){return t.format("{0} += {1};",M.output,e.replace(B,"\\n"))}function E(){var t,e=Array.coerce(arguments),n=a(e[e.length-1])?e.pop():a(e[0])?e.shift():null;return this instanceof E?(!n||q.forEach(function(t){t in n&&(this[t]=n[t],delete n[t])},this),t=this.fallback,(!t&&this.debug||"string"==typeof t&&t.toUpperCase()===U)&&(this.fallback=U),this.filters=n||{},this.__tpl__=e.join("\n"),ue[T(this)]=this,this.compiled&&(this.compiled=!1,S(this)),void 0):a(n)?new E(e.join(""),n):new E(e.join(""))}function T(e){return e.id||(e.id=t.format(fe,++z)),e.id}function O(t){this.compiled||S(this),this[M.dict]=t;var e=this._parse(t);return delete this[M.dict],e}function S(t){return t.compiled||(t.compiled=!0,t._parse=g(t)),t}function $(e){function n(t,e,n){!n&&t in i||(i[t]=e)}function r(t,e){switch(typeof e){case"string":n(e,arguments[2],t);break;case"object":for(var r in e)n(r,e[r],t)}return this}var i={};!a(e)||t.copy(i,e),this.all=function(){return t.copy(i)},this.add=function(){return r.call(this,!1,arguments[0],arguments[1])},this.get=function(t){return i[t]},this.replace=function(){return r.call(this,!0,arguments[0],arguments[1])}}var N,R,L,U="DEBUG",C="__ASSERT__ __CONTEXT__ __FILTER_ __OUTPUT__ __UTIL__ $_ document false global instanceof null true typeof undefined window".split(" ").reduce(function(t,e){return t[e]=!0,t},t.obj()),K={blank:function(e){return t.empty(e)||"string"==typeof e&&!e.trim()},contains:r,endsWith:function(t,e){t+="";var n=t.length-e.length;return n>=0&&t.lastIndexOf(e)==n},empty:t.empty,equals:function(t,e){return t==e},exists:t.exists,is:function(t,e){return t===e},isEven:function(t){return!(1&parseInt(t,10))},isOdd:function(t){return!!(1&parseInt(t,10))},isTPL:function(t){return!!s(t,this)},iterable:function(e){return t.iter(e)},notEmpty:o,startsWith:function(t,e){return 0===(t+"").indexOf(e)}},A={},F={inspect:function(e){switch(t.ntype(e)){case"object":case"array":console.dir(e);break;default:console.log(e)}return""},objectify:function(t,e){var n={};return n[e]=t,n},parse:function(t,e){var n,r,i,a;if(t=Object(t),e instanceof E?a=e:(e=(e+"").trim(),a=s(e,this)),!a)return this.fallback;r=this[M.dict],n=M.parent in r;for(;r&&r===r[M.parent];)r=r[M.parent];return t!==r&&(t[M.parent]=r),i=a.parse(t),n?t[M.parent]=r[M.parent]:delete t[M.parent],i},stop:function(t){t.stop()},stringify:w,type:function(e,n){var r=t.type(e);return"string"==typeof n?r==n:r},value:function(t,e){return Object.value(t,e)}},W="__tpl_cs_cached_keys",P="__tpl_cs_stack",q="compiled debug dict fallback id sourceURL".split(" "),D="<~>",G=/([-\*\+\?\.\|\^\$\/\\\(\)[\]\{\}])/g,H="\\$1",M={assert:"__ASSERT__",ctx:"__CONTEXT__",dict:"__dict__",filter:"__FILTER__",output:"__OUTPUT__",parent:"__PARENT__",util:"__UTIL__"},V=t.format("return {0};\n ",M.output),X='\n"use strict";\n'+t.format('var $C = new ContextStack( {0}, this ), $_ = $C.current(), iter = new Iter( null ), {1} = "", U;',M.ctx,M.output),z=999,B=/[\n\r]/gm,J=/(['"])/g,Q=/(\*)(\/)/gm,Y=RegExp(D,"gm"),Z=/[\r\n]+/g,te=/\s+/g,ee=/[\(\)\[\]\{\}\?\*\+\/<>%&=!-]/,ne=/\.(\d+)(\.?)/g,re="['$1']$2",ie=RegExp("\\s*([^\\|]+(?:\\|[^\\|]+?)){0,}"+D,"g"),se="<__SPLIT__TEMPLATE__HERE__>",ae=["","$1","$2",""].join(se),ue={},oe="/{0}{0} original template string:\n\n{1}\n\n{0}/\n\n// compiled template code: \n\n{2}\n\n//@ sourceURL={3}\n",ce="WARNING: NO VALUE FOUND FOR => {0}",fe="t8-anon-{0}",he="/Templ8/{0}.tpl",le='{0}["{1}"].call( this, {2}{3}, {4} )',pe="{0}.{1}";c.prototype={current:function(){return(this.top||this[P][0]).dict},get:function(e){for(var n,r,i=this.fallback,s=this[P],a=s.length;a--;){if(n=s[a],e in n.cache)return n.cache[e];if((r=n.dict[e])!==N||(r=Object.value(n.dict,e))!==N)return n.cache[e]=r}if(this.hasFallback)switch(t.ntype(i)){case"string":return i===U?t.format(ce,e):i;case"function":return i(e,n.dict)}return N},pop:function(){var t=this[P].pop().dict;return this.top=this[P][this[P].length-1],t},push:function(e){return this[P].push(this.top={cache:t.obj(),dict:e}),this}},f.prototype={empty:!0,hasNext:function(){return this.stopped||this.empty?!1:(++this.index<this.lastIndex||(this.stop().isLast=!0),this.key=this.keys[this.index1++],this.current=this.val=this._[this.key],this)},stop:function(){return this.stopped=!0,this}},t.defs(f.prototype,{first:{get:function(){return this._[this.keys[this.firstKey]]}},last:{get:function(){return this._[this.keys[this.lastKey]]}},next:{get:function(){return this._[this.keys[this.nextKey]]}},prev:{get:function(){return this._[this.keys[this.prevKey]]}},nextIndex:{get:function(){var t=this.index+1;return this.lastIndex>=t?t:N}},prevIndex:{get:function(){var t=this.index-1;return t>=this.firstIndex?t:N}},firstKey:{get:function(){return this.keys[this.firstIndex]}},lastKey:{get:function(){return this.keys[this.lastIndex]}},nextKey:{get:function(){return this.keys[this.nextIndex]}},prevKey:{get:function(){return this.keys[this.prevIndex]}}},"r"),R={assembleparts:p,clean:d,compiletpl:m,createtpl:g,emittag:y,fnvar:M,formatstatement:_,get:k,util:F,wrap:I},E.prototype={compiled:!1,debug:!1,dict:null,fallback:"",parse:O},t.defs(E,{m8:{value:t},escapeRE:i,format:t.format,get:s,gsub:t.gsub,stringify:w},"r"),E.Assert=new $(K),E.Filter=new $(A),E.Statement=new $,E.Tag=new function(){function n(e){s.forEach(r,e),t.copy(this,e),u[this.start]=this}function r(n){if(!(n in this))throw new TypeError(t.format("A "+e+" Tag requires an {0}",a[n]))}var s="emit end start".split(" "),a={emit:"emit function",end:"end tag definition",start:"start tag definition"},u={};this.all=function(){return t.copy(u)},this.compileRegExp=function(){var t,e=[],n=[];for(t in u)e.push(i(u[t].end.substring(0,1))),n.push(i(u[t].start.substring(1)));return L=RegExp("(\\{["+n.join("")+"])\\s*(.+?)\\s*(["+e.join("")+"]\\})","gm")},this.create=function(t,e){return new n(t),e===!0||this.compileRegExp(),this},this.get=function(t){return u[t]}};var de=[{start:"{{",end:"}}",emit:function(t,n,i,s){var a,u,c,f;if(""==i)throw new SyntaxError(e+" missing key in value declaration.");if(!we.test(i)||(a=r(i,"|")?(i.match(xe)||me).filter(o):i.match(xe)),!a||2>=a.length)return t.wrap(t.formatstatement(n,i));if(a.shift(),f=t.formatstatement(n,a.shift()),c=ge(a.shift().toLowerCase()),u=a.join(" "),!c||!u)throw new SyntaxError(e+" missing tag or statement in one liner value declaration.");return c(t,n,u,s)+t.wrap(f)+ge("endif")}},{start:"{%",end:"%}",emit:function(n,r,i,s){if(""==i)throw new SyntaxError(e+" missing key in statement declaration.");var a,u,o;if(!(o=ge(i.toLowerCase()))){if(a=i.split(" "),o=ge(a.shift().toLowerCase()),0==a.length&&"string"==typeof o)return o;if(u=a.join(" "),!o||!u)throw a=[],o||a.push("tag"),u||a.push("statement"),new SyntaxError(e+" missing "+a.join(" and ")+" in statement declaration.")}if(!o)throw new SyntaxError(t.format(e+" tag: {0} does not exist.",o));return"function"==typeof o?o(n,r,u,s):o}},{start:"{[",end:"]}",emit:function(t,e,n,r){n=n.replace(ye,"$1").split("for each");var i,s,a,u,c=t.clean(n.shift()),f=t.clean(n.pop()).match(_e);return n=[],f.shift(),u=f.shift(),a=f.shift(),f.length>=2&&(s=f.shift(),i=f.shift()),n.push(ge("for")(t,e,(o(u)?u.match(be,"$1").join(",")+" in ":"")+a,r)),!i||n.push(ge(s||"if")(t,e,i,r)),n.push(t.wrap(c.split(" ").map(function(n){return t.formatstatement(e,n)}).join(" "))),!i||n.push(ge("endif")),n.push(ge("endfor")(t,e)),n.join("")}},{start:"{:",end:":}",emit:function(t,e,n){return t.formatstatement(e,n)+";"}},{start:"{#",end:"#}",emit:function(t,e,n){return["\n/*",n,"*/\n"].join(" ")}}],me=[],ge=E.Statement.get,ye=/\s*(,)\s*/g,_e=/^\(\s*(.*?)(?:\bin\b){0,1}(.*?)\s*\)\s*(if|unless){0,1}\s*(.*)$/i,be=/(\w+)/g,xe=/^(.*?)\s+(if|unless)\s+(.*)|$/i,we=/\s+(if|unless)\s+/i;de.forEach(function(t){E.Tag.create(t,!0)}),E.Tag.compileRegExp(),function(){function e(t,e,n){return n.split(" ").map(function(n){return e(t,n)}).join(" ")}var n={"for":function(e,n,s){var a,u,o="U",c=o,f=e.clean(s).match(r),h=o,l=[];return null===f?a=s:(f.shift(),c=f.pop()||o,h=f.pop()||o,a=f.pop()||f.pop(),u=(f.pop()||"").match(i)),a=e.formatstatement(n,a),l.push(t.format(["","iter = new Iter( {0}, iter, {1}, {2} );","while ( iter.hasNext() ) {","$_ = iter.current;"].join("\n\r"),a,h,c)),u&&u.length>0&&(n.currentIterKeys.unshift(u),2>u.length?l.push(t.format("var {0} = iter.current;\n\r",u[0])):u.length>=2&&l.push(t.format("var {0} = iter.key, {1} = iter.current;\n\r",u[0],u[1]))),l.join("")},forempty:"\n\r}\n\rif ( iter.empty ) {\n\r",endfor:function(e,n){return n.currentIterKeys.shift(),t.format(["\n\r}","iter = iter.parent || new Iter( null );","$_ = iter.current || $C.current(); \n\r"].join("\n\r"),e.fnvar.util)},"if":function(n,r,i){return t.format("if ( {0} ) { ",e(r,n.formatstatement,i))},elseif:function(n,r,i){return t.format(" } else if ( {0} ) { ",e(r,n.formatstatement,i))},"else":" } else { ",endif:" }",sub:function(e,n,r,i){var s,a,u,o="endsub",c=r.trim();return s=i.indexOf([o,c].join(" ")),s>-1||(s=i.indexOf(o)),a=i.splice(0,s+1),a.splice(a.length-2,a.length),c=t.format("{0}.{1}",n.id,c),u=new E("",t.copy({debug:n.debug,fallback:n.fallback,id:c},n.filters)),u.currentIterKeys=[],u.__tpl__=a.join(""),u._parse=e.compiletpl(u,e.assembleparts(u,a)),delete u.currentIterKeys,u.compiled=!0,u.parentTemplate=n,""},unless:function(n,r,i){return t.format("if ( !( {0} ) ) { ",e(r,n.formatstatement,i))}},r=/^(\[[^,]+,\s*[^\]]+\]|[^\s]+)(?:\s+in\s+([^\s\[]+)){0,1}\s*(?:\[?(\d+)\.+(\d*)]*\]?){0,1}/i,i=/(\w+)/g;E.Statement.add(n),E.Statement.add("elsif",n.elseif),E.Statement.add("endunless",n.endif),E.Statement.add("/if",n.endif),E.Statement.add("/unless",n.endif),E.Statement.add("/for",n.endfor),E.Statement.add("/sub",n.endsub)}(),E.Filter.add({capitalize:function(t){return t=E.stringify(t),t.charAt(0).toUpperCase()+t.substring(1).toLowerCase()},count:function(e){return t.len(e)||0},crop:function(t,e){return t=E.stringify(t),e=parseInt(e,10)||50,t.length>e?t.substring(0,e/2)+"..."+t.substring(t.length-e/2):t},def:function(t,e){return K.blank(t)?e:t},first:function(e){switch(t.ntype(e)){case"array":return e[0];case"string":return e.charAt(0)}},join:function(e,n){return t.got(e,"join")&&"function"==typeof e.join?e.join(n):e},last:function(e){switch(t.ntype(e)){case"array":return e[e.length-1];case"string":return e.charAt(e.length-1)}},lowercase:function(t){return E.stringify(t).toLowerCase()},prefix:function(t,e){return e+t},suffix:function(t,e){return t+e},truncate:function(t,e){return t=E.stringify(t),e=parseInt(e,10)||50,t.length>e?t.substring(0,e)+"...":t},uppercase:function(t){return E.stringify(t).toUpperCase()},wrap:function(t,e,n){return e+t+(n||e)}}),t.iter(n)||(n="commonjs"==t.ENV?module:t.global),E=t.expose(E,e,n),t.expose(t,E)}("undefined"!=typeof m8?m8:"undefined"!=typeof require?require("m8"):null,"Templ8");
!function(t,e,n){"use strict";function r(e,n){return e&&typeof e.indexOf=="function"&&!!~e.indexOf(n)||t.got(e,n)}function i(t){return String(t).replace(G,H)}function s(e,n){if(!n)return ue[e]||null;var r;do if(r=t.format(pe,n.id,e),r in ue)return ue[r];while(n=n.parentTemplate);return ue[e]||null}function a(t){return"object"==typeof t&&(t.constructor===Object||t.constructor===N)}function u(e,n,r){n||(n=t),r||(r=e);for(var i,s=-1,a=e.length,u=[];++s<a;)switch(i=n.call(r,e[s],s,e)){case null:case N:break;default:switch(typeof i){case"string":i.trim()===""||u.push(i);break;case"number":isNaN(i)||u.push(i);break;default:!t.iter(i)||t.len(i)||u.push(i)}}return u}function o(e){return!t.empty(e)}function c(e,n){switch(this[P]=[],this.tpl=n,this.push(t.global),n.fallback!==N&&(this.hasFallback=!0,this.fallback=n.fallback),t.ntype(e)){case"object":this.push(e);break;case"array":e[M.dict]?e.map(this.push,this):this.push(e);break;default:!t.exists(e)||this.push(e)}}function f(e,n,r,i){var s=Object.keys(e=this._=Object(e)),a=s.length;return a?(t.tostr(e)=="[object Object]"||(s=s.map(Number)),this.empty=!1,this.count=isNaN(i)?a:0>i?a+i:i>a?a:i,0==r||isNaN(r)?(this.firstIndex=0,this.index=-1):(this.firstIndex=r,this.index=r-2),this.index1=this.index+1,this.lastIndex=this.count===a?this.count-1:this.count,this.keys=s,!(n instanceof f)||(this.parent=n),void 0):this.stop()}function h(e,n){return t.empty(n)||e.push(n),e}function l(e,n){return n.reduce(function(n,r,i){if(0==i)return k(e,r);var s,a="",u=r.indexOf(":");return~u?(s=r.substring(0,u),a=r.substring(u+1)):s=r,!a||(a=", "+a.split(",").map(function(t){return k(this,t)},e).join(", ")),t.format(le,b(s),s,k(e,n),a,M.ctx)},"")}function p(t,e){for(var n,r=[X];n=e.shift();)r.push(y(t,n,e));return r.push(V),r.join("\r\n")}function d(t){return t.replace(Y,"").replace(Z,"\n").replace(te," ").trim()}function m(e,n){n=t.format(oe,"*",e.__tpl__.replace(Q,"$1 \\$2"),n,e.sourceURL?e.sourceURL:t.format(he,e.id));var r=new Function("root","ContextStack","Iter",M.filter,M.assert,M.util,M.ctx,n);return r.bind(e,t.global,c,f,t.copy(e.filters,E.Filter.all(),!0),K,F)}function g(t){t.currentIterKeys=[];var e=m(t,p(t,x(t.__tpl__)));return delete t.currentIterKeys,e}function y(e,n,r){var i;return(i=E.Tag.get(n))?(n=r.shift(),i.emit(R,e,n,r)):I(t.format('"{0}"',n.replace(J,"\\$1")))}function _(t,e){switch(e=d(e)){case"AND":return" && ";case"OR":return" || "}return r(e,"|")||r(e,D)?(" "+e+D).replace(ie,function(e){return K.blank(e)||e==D?"":l(t,d(e).split("|"))}):k(t,e)}function b(t){return K[t]?M.assert:F[t]?M.util:M.filter}function x(t){return t.replace(L,ae).split(se).reduce(h,[])}function w(e,n){switch(typeof e){case"boolean":case"number":case"string":return String(e);default:switch(t.ntype(e)){case"date":return e.toDateString();case"array":return u(e,w).join(", ");case"object":return W in e?w(e.dict):(n=e.toString())!="[object Object]"?n:u(Object.values(e),w).join(", ");default:switch(t.type(e)){case"htmlelement":return e.outerHTML;case"htmlcollection":return u(Array.coerce(e),function(t){return w(t)}).join("\n")}}}return""}function v(t){return this==t||K.startsWith(this,t+".")}function j(t,e){return t.length?t.some(function(t){return t.some(v,e)}):0}function k(e,n){var i=e.currentIterKeys||[];return n=d(n),r(n,".call(")||ee.test(n)||K.startsWith(n,'"')&&K.endsWith(n,'"')||K.startsWith(n,"'")&&K.endsWith(n,"'")||!isNaN(n)?n:K.startsWith(n,"$_.")||K.startsWith(n,"iter.")||i.length&&j(i,n)||n in C?n.replace(ne,re):t.format('$C.get( "{0}" )',n)}function I(e){return t.format("{0} += {1};",M.output,e.replace(B,"\\n"))}function E(){var t,e=Array.coerce(arguments),n=a(e[e.length-1])?e.pop():a(e[0])?e.shift():null;return this instanceof E?(!n||q.forEach(function(t){t in n&&(this[t]=n[t],delete n[t])},this),t=this.fallback,(!t&&this.debug||"string"==typeof t&&t.toUpperCase()===U)&&(this.fallback=U),this.filters=n||{},this.__tpl__=e.join("\n"),ue[T(this)]=this,this.compiled&&(this.compiled=!1,O(this)),void 0):a(n)?new E(e.join(""),n):new E(e.join(""))}function T(e){return e.id||(e.id=t.format(fe,++z)),e.id}function S(t){this.compiled||O(this),this[M.dict]=t;var e=this._parse(t);return delete this[M.dict],e}function O(t){return t.compiled||(t.compiled=!0,t._parse=g(t)),t}function $(e){function n(t,e,n){!n&&t in i||(i[t]=e)}function r(t,e){switch(typeof e){case"string":n(e,arguments[2],t);break;case"object":for(var r in e)n(r,e[r],t)}return this}var i={};!a(e)||t.copy(i,e),this.all=function(){return t.copy(i)},this.add=function(){return r.call(this,!1,arguments[0],arguments[1])},this.get=function(t){return i[t]},this.replace=function(){return r.call(this,!0,arguments[0],arguments[1])}}var N,R,L,U="DEBUG",C="__ASSERT__ __CONTEXT__ __FILTER_ __OUTPUT__ __UTIL__ $_ document false global instanceof null true typeof undefined window".split(" ").reduce(function(t,e){return t[e]=!0,t},t.obj()),K={blank:function(e){return t.empty(e)||"string"==typeof e&&!e.trim()},contains:r,endsWith:function(t,e){t=String(t);var n=t.length-e.length;return n>=0&&t.lastIndexOf(e)==n},empty:t.empty,equals:function(t,e){return t==e},exists:t.exists,is:function(t,e){return t===e},isEven:function(t){return!(parseInt(t,10)&1)},isOdd:function(t){return!!(parseInt(t,10)&1)},isTPL:function(t){return!!s(t,this)},iterable:function(e){return t.iter(e)},notEmpty:o,startsWith:function(t,e){return String(t).indexOf(e)===0}},A={},F={inspect:function(e){switch(t.ntype(e)){case"object":case"array":console.dir(e);break;default:console.log(e)}return""},objectify:function(t,e){var n={};return n[e]=t,n},parse:function(t,e){var n,r,i,a;if(t=Object(t),e instanceof E?a=e:(e=String(e).trim(),a=s(e,this)),!a)return this.fallback;r=this[M.dict],n=M.parent in r;for(;r&&r===r[M.parent];)r=r[M.parent];return t!==r&&(t[M.parent]=r),i=a.parse(t),n?t[M.parent]=r[M.parent]:delete t[M.parent],i},stop:function(t){t.stop()},stringify:w,type:function(e,n){var r=t.type(e);return"string"==typeof n?r==n:r},value:function(t,e){return Object.value(t,e)}},W="__tpl_cs_cached_keys",P="__tpl_cs_stack",q="compiled debug dict fallback id sourceURL".split(" "),D="<~>",G=/([-\*\+\?\.\|\^\$\/\\\(\)[\]\{\}])/g,H="\\$1",M={assert:"__ASSERT__",ctx:"__CONTEXT__",dict:"__dict__",filter:"__FILTER__",output:"__OUTPUT__",parent:"__PARENT__",util:"__UTIL__"},V=t.format("return {0};\n ",M.output),X='\n"use strict";\n'+t.format('var $C = new ContextStack( {0}, this ), $_ = $C.current(), iter = new Iter( null ), {1} = "", U;',M.ctx,M.output),z=999,B=/[\n\r]/gm,J=/(['"])/g,Q=/(\*)(\/)/gm,Y=new RegExp(D,"gm"),Z=/[\r\n]+/g,te=/\s+/g,ee=/[\(\)\[\]\{\}\?\*\+\/<>%&=!-]/,ne=/\.(\d+)(\.?)/g,re="['$1']$2",ie=new RegExp("\\s*([^\\|]+(?:\\|[^\\|]+?)){0,}"+D,"g"),se="<__SPLIT__TEMPLATE__HERE__>",ae=["","$1","$2",""].join(se),ue={},oe="/{0}{0} original template string:\n\n{1}\n\n{0}/\n\n// compiled template code: \n\n{2}\n\n//@ sourceURL={3}\n",ce="WARNING: NO VALUE FOUND FOR => {0}",fe="t8-anon-{0}",he="/Templ8/{0}.tpl",le='{0}["{1}"].call( this, {2}{3}, {4} )',pe="{0}.{1}";c.prototype={current:function(){return(this.top||this[P][0]).dict},get:function(e){for(var n,r,i=this.fallback,s=this[P],a=s.length;a--;){if(n=s[a],e in n.cache)return n.cache[e];if((r=n.dict[e])!==N||(r=Object.value(n.dict,e))!==N)return n.cache[e]=r}if(this.hasFallback)switch(t.ntype(i)){case"string":return i===U?t.format(ce,e):i;case"function":return i(e,n.dict)}return N},pop:function(){var t=this[P].pop().dict;return this.top=this[P][this[P].length-1],t},push:function(e){return this[P].push(this.top={cache:t.obj(),dict:e}),this}},f.prototype={empty:!0,hasNext:function(){return this.stopped||this.empty?!1:(++this.index<this.lastIndex||(this.stop().isLast=!0),this.key=this.keys[this.index1++],this.current=this.val=this._[this.key],this)},stop:function(){return this.stopped=!0,this}},t.defs(f.prototype,{first:{get:function(){return this._[this.keys[this.firstKey]]}},last:{get:function(){return this._[this.keys[this.lastKey]]}},next:{get:function(){return this._[this.keys[this.nextKey]]}},prev:{get:function(){return this._[this.keys[this.prevKey]]}},nextIndex:{get:function(){var t=this.index+1;return t<=this.lastIndex?t:N}},prevIndex:{get:function(){var t=this.index-1;return t>=this.firstIndex?t:N}},firstKey:{get:function(){return this.keys[this.firstIndex]}},lastKey:{get:function(){return this.keys[this.lastIndex]}},nextKey:{get:function(){return this.keys[this.nextIndex]}},prevKey:{get:function(){return this.keys[this.prevIndex]}}},"r"),R={assembleparts:p,clean:d,compiletpl:m,createtpl:g,emittag:y,fnvar:M,formatstatement:_,get:k,util:F,wrap:I},E.prototype={compiled:!1,debug:!1,dict:null,fallback:"",parse:S},t.defs(E,{m8:{value:t},escapeRE:i,format:t.format,get:s,gsub:t.gsub,stringify:w},"r"),E.Assert=new $(K),E.Filter=new $(A),E.Statement=new $,E.Tag=new function(){function n(e){s.forEach(r,e),t.copy(this,e),u[this.start]=this}function r(n){if(!(n in this))throw new TypeError(t.format("A "+e+" Tag requires an {0}",a[n]))}var s="emit end start".split(" "),a={emit:"emit function",end:"end tag definition",start:"start tag definition"},u={};this.all=function(){return t.copy(u)},this.compileRegExp=function(){var t,e=[],n=[];for(t in u)e.push(i(u[t].end.substring(0,1))),n.push(i(u[t].start.substring(1)));return L=new RegExp("(\\{["+n.join("")+"])\\s*(.+?)\\s*(["+e.join("")+"]\\})","gm")},this.create=function(t,e){return new n(t),e===!0||this.compileRegExp(),this},this.get=function(t){return u[t]}};var de=[{start:"{{",end:"}}",emit:function(t,n,i,s){var a,u,c,f;if(""==i)throw new SyntaxError(e+" missing key in value declaration.");if(!we.test(i)||(a=r(i,"|")?(i.match(xe)||me).filter(o):i.match(xe)),!a||a.length<=2)return t.wrap(t.formatstatement(n,i));if(a.shift(),f=t.formatstatement(n,a.shift()),c=ge(a.shift().toLowerCase()),u=a.join(" "),!c||!u)throw new SyntaxError(e+" missing tag or statement in one liner value declaration.");return c(t,n,u,s)+t.wrap(f)+ge("endif")}},{start:"{%",end:"%}",emit:function(n,r,i,s){if(""==i)throw new SyntaxError(e+" missing key in statement declaration.");var a,u,o;if(!(o=ge(i.toLowerCase()))){if(a=i.split(" "),o=ge(a.shift().toLowerCase()),a.length==0&&"string"==typeof o)return o;if(u=a.join(" "),!o||!u)throw a=[],o||a.push("tag"),u||a.push("statement"),new SyntaxError(e+" missing "+a.join(" and ")+" in statement declaration.")}if(!o)throw new SyntaxError(t.format(e+" tag: {0} does not exist.",o));return"function"==typeof o?o(n,r,u,s):o}},{start:"{[",end:"]}",emit:function(t,e,n,r){n=n.replace(ye,"$1").split("for each");var i,s,a,u,c=t.clean(n.shift()),f=t.clean(n.pop()).match(_e);return n=[],f.shift(),u=f.shift(),a=f.shift(),f.length>=2&&(s=f.shift(),i=f.shift()),n.push(ge("for")(t,e,(o(u)?u.match(be,"$1").join(",")+" in ":"")+a,r)),!i||n.push(ge(s||"if")(t,e,i,r)),n.push(t.wrap(c.split(" ").map(function(n){return t.formatstatement(e,n)}).join(" "))),!i||n.push(ge("endif")),n.push(ge("endfor")(t,e)),n.join("")}},{start:"{:",end:":}",emit:function(t,e,n){return t.formatstatement(e,n)+";"}},{start:"{#",end:"#}",emit:function(t,e,n){return["\n/*",n,"*/\n"].join(" ")}}],me=[],ge=E.Statement.get,ye=/\s*(,)\s*/g,_e=/^\(\s*(.*?)(?:\bin\b){0,1}(.*?)\s*\)\s*(if|unless){0,1}\s*(.*)$/i,be=/(\w+)/g,xe=/^(.*?)\s+(if|unless)\s+(.*)|$/i,we=/\s+(if|unless)\s+/i;de.forEach(function(t){E.Tag.create(t,!0)}),E.Tag.compileRegExp(),function(){function e(t,e,n){return n.split(" ").map(function(n){return e(t,n)}).join(" ")}var n={"for":function(e,n,s){var a,u,o="U",c=o,f=e.clean(s).match(r),h=o,l=[];return null===f?a=s:(f.shift(),c=f.pop()||o,h=f.pop()||o,a=f.pop()||f.pop(),u=(f.pop()||"").match(i)),a=e.formatstatement(n,a),l.push(t.format(["","iter = new Iter( {0}, iter, {1}, {2} );","while ( iter.hasNext() ) {","$_ = iter.current;"].join("\n\r"),a,h,c)),u&&u.length>0&&(n.currentIterKeys.unshift(u),u.length<2?l.push(t.format("var {0} = iter.current;\n\r",u[0])):u.length>=2&&l.push(t.format("var {0} = iter.key, {1} = iter.current;\n\r",u[0],u[1]))),l.join("")},forempty:"\n\r}\n\rif ( iter.empty ) {\n\r",endfor:function(e,n){return n.currentIterKeys.shift(),t.format(["\n\r}","iter = iter.parent || new Iter( null );","$_ = iter.current || $C.current(); \n\r"].join("\n\r"),e.fnvar.util)},"if":function(n,r,i){return t.format("if ( {0} ) { ",e(r,n.formatstatement,i))},elseif:function(n,r,i){return t.format(" } else if ( {0} ) { ",e(r,n.formatstatement,i))},"else":" } else { ",endif:" }",sub:function(e,n,r,i){var s,a,u,o="endsub",c=r.trim();return s=i.indexOf([o,c].join(" ")),s>-1||(s=i.indexOf(o)),a=i.splice(0,s+1),a.splice(a.length-2,a.length),c=t.format("{0}.{1}",n.id,c),u=new E("",t.copy({debug:n.debug,fallback:n.fallback,id:c},n.filters)),u.currentIterKeys=[],u.__tpl__=a.join(""),u._parse=e.compiletpl(u,e.assembleparts(u,a)),delete u.currentIterKeys,u.compiled=!0,u.parentTemplate=n,""},unless:function(n,r,i){return t.format("if ( !( {0} ) ) { ",e(r,n.formatstatement,i))}},r=/^(\[[^,]+,\s*[^\]]+\]|[^\s]+)(?:\s+in\s+([^\s\[]+)){0,1}\s*(?:\[?(\d*)\.+(\d*)]*\]?){0,1}/i,i=/(\w+)/g;E.Statement.add(n),E.Statement.add("elsif",n.elseif),E.Statement.add("endunless",n.endif),E.Statement.add("/if",n.endif),E.Statement.add("/unless",n.endif),E.Statement.add("/for",n.endfor),E.Statement.add("/sub",n.endsub)}(),E.Filter.add({capitalize:function(t){return t=E.stringify(t),t.charAt(0).toUpperCase()+t.substring(1).toLowerCase()},count:function(e){return t.len(e)||0},crop:function(t,e){return t=E.stringify(t),e=parseInt(e,10)||50,t.length>e?t.substring(0,e/2)+"..."+t.substring(t.length-e/2):t},def:function(t,e){return K.blank(t)?e:t},first:function(e){switch(t.ntype(e)){case"array":return e[0];case"string":return e.charAt(0)}},join:function(e,n){return t.got(e,"join")&&typeof e.join=="function"?e.join(n):e},last:function(e){switch(t.ntype(e)){case"array":return e[e.length-1];case"string":return e.charAt(e.length-1)}},lowercase:function(t){return E.stringify(t).toLowerCase()},prefix:function(t,e){return e+t},suffix:function(t,e){return t+e},truncate:function(t,e){return t=E.stringify(t),e=parseInt(e,10)||50,t.length>e?t.substring(0,e)+"...":t},uppercase:function(t){return E.stringify(t).toUpperCase()},wrap:function(t,e,n){return e+t+(n||e)}}),t.iter(n)||(n=t.ENV=="commonjs"?module:t.global),E=t.expose(E,e,n),t.expose(t,E)}("undefined"!=typeof m8?m8:"undefined"!=typeof require?require("m8"):null,"Templ8");

@@ -410,5 +410,9 @@ typeof m8 !== 'undefined' || ( m8 = require( 'm8' ) );

'<index>{{iter.index}}</index><prevIndex>{{iter.prevIndex}}</prevIndex><nextIndex>{{iter.nextIndex}}</nextIndex><first>{{iter.first.name}}</first><last>{{iter.last.name}}</last><next>{{iter.next.name if iter.next|exists }}</next><prev>{{iter.prev.name if iter.prev|exists }}</prev>',
'{% endfor %}', { compiled : true, id : 'test.tpl.0' } ),
tpl1 = new Templ8( '{% for items_small [..2] %}',
'<index>{{iter.index}}</index><prevIndex>{{iter.prevIndex}}</prevIndex><nextIndex>{{iter.nextIndex}}</nextIndex><first>{{iter.first.name}}</first><last>{{iter.last.name}}</last><next>{{iter.next.name if iter.next|exists }}</next><prev>{{iter.prev.name if iter.prev|exists }}</prev>',
'{% endfor %}', { compiled : true, id : 'test.tpl.0' } );
expect( tpl0.parse( data ).replace( new_lines, '' ) ).to.equal( '<index>0</index><prevIndex>undefined</prevIndex><nextIndex>1</nextIndex><first>Baxter</first><last>Fleur</last><next>Alyssa</next><prev></prev><index>1</index><prevIndex>0</prevIndex><nextIndex>2</nextIndex><first>Baxter</first><last>Fleur</last><next>Fleur</next><prev>Baxter</prev><index>2</index><prevIndex>1</prevIndex><nextIndex>undefined</nextIndex><first>Baxter</first><last>Fleur</last><next></next><prev>Alyssa</prev>' );
expect( tpl1.parse( data ).replace( new_lines, '' ) ).to.equal( '<index>0</index><prevIndex>undefined</prevIndex><nextIndex>1</nextIndex><first>Baxter</first><last>Fleur</last><next>Alyssa</next><prev></prev><index>1</index><prevIndex>0</prevIndex><nextIndex>2</nextIndex><first>Baxter</first><last>Fleur</last><next>Fleur</next><prev>Baxter</prev><index>2</index><prevIndex>1</prevIndex><nextIndex>undefined</nextIndex><first>Baxter</first><last>Fleur</last><next></next><prev>Alyssa</prev>' );

@@ -422,2 +426,3 @@ done();

e3 = '<p>3. city: 22</p><p>4. country: 23</p><p>5. date: 24</p>',
e4 = '<p>1. name: 6</p><p>2. email: 21</p><p>3. city: 22</p><p>4. country: 23</p>',
tpl0 = new Templ8( '{% for columns %}',

@@ -453,4 +458,8 @@ '<p>{{iter.index1}}. {{iter.key}}: {{iter.current.width}}</p>',

'<p>{{iter.index1}}. {{k}}: {{v.width}}</p>',
'{% /for %}', { compiled : true, id : 'test.tpl.7' } );
'{% /for %}', { compiled : true, id : 'test.tpl.7' } ),
tpl8 = new Templ8( '{% for [k,v] in columns [..3] %}',
'<p>{{iter.index1}}. {{k}}: {{v.width}}</p>',
'{% /for %}', { compiled : true, id : 'test.tpl.8' } );
expect( tpl0.parse( data ).replace( new_lines, '' ) ).to.equal( e1 );

@@ -464,2 +473,3 @@ expect( tpl1.parse( data ).replace( new_lines, '' ) ).to.equal( e1 );

expect( tpl7.parse( data ).replace( new_lines, '' ) ).to.equal( e3 );
expect( tpl8.parse( data ).replace( new_lines, '' ) ).to.equal( e4 );

@@ -466,0 +476,0 @@ done();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc