UNPKG

brazejs

Version:

Liquid template engine for the Braze variant by pure JavaScript: compatible to Braze, easy to extend.

3 lines (2 loc) 47.7 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("path"),require("crypto")):"function"==typeof define&&define.amd?define(["path","crypto"],t):(e=e||self).Liquid=t(e.path,e.crypto)}(this,function(h,n){"use strict";var i=function(e,t){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function u(e,t){function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var b=function(){return(b=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function d(s,o,u,a){return new(u||(u=Promise))(function(e,t){function r(e){try{i(a.next(e))}catch(e){t(e)}}function n(e){try{i(a.throw(e))}catch(e){t(e)}}function i(t){t.done?e(t.value):new u(function(e){e(t.value)}).then(r,n)}i((a=a.apply(s,o||[])).next())})}function q(r,n){var i,s,o,e,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return e={next:t(0),throw:t(1),return:t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,s&&(o=2&t[0]?s.return:t[0]?s.throw||((o=s.return)&&o.call(s),0):s.next)&&!(o=o.call(s,t[1])).done)return o;switch(s=0,o&&(t=[2&t[0],o.value]),t[0]){case 0:case 1:o=t;break;case 4:return u.label++,{value:t[1],done:!1};case 5:u.label++,s=t[1],t=[0];continue;case 7:t=u.ops.pop(),u.trys.pop();continue;default:if(!(o=0<(o=u.trys).length&&o[o.length-1])&&(6===t[0]||2===t[0])){u=0;continue}if(3===t[0]&&(!o||t[1]>o[0]&&t[1]<o[3])){u.label=t[1];break}if(6===t[0]&&u.label<o[1]){u.label=o[1],o=t;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(t);break}o[2]&&u.ops.pop(),u.trys.pop();continue}t=n.call(r,u)}catch(e){t=[6,e],s=0}finally{i=o=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}}var t=Object.prototype.toString,r=RegExp("["+["-","[","]","/","{","}","(",")","*","+","?",".","\\","^","$","|"].join("\\")+"]","g");function o(e){return e.replace(r,"\\$&")}function f(e){return"[object String]"===t.call(e)}function a(e){return"function"==typeof e}function c(t){return p(t)?"":g(t=l(t))?"["+t.map(function(e){return s(e)}).join(", ")+"]":w(t)?"{"+Object.keys(t).map(function(e){return'"'+e+'"=>'+s(t[e])}).join(", ")+"}":String(t)}function s(e){return f(e)?'"'+e+'"':c(e)}function l(e){return a(e.toLiquid)?l(e.toLiquid()):e}function p(e){return null==e}function g(e){return"[object Array]"===t.call(e)}function v(e,t){for(var r in e=e||{})if(e.hasOwnProperty(r)&&!1===t(e[r],r,e))break;return e}function m(e){return e[e.length-1]}function w(e){var t=typeof e;return null!==e&&("object"===t||"function"===t)}function y(e,t,r){void 0===r&&(r=1);for(var n=[],i=e;i<t;i+=r)n.push(i);return n}function T(e,t,r){void 0===r&&(r=" ");for(var n=t-(e=String(e)).length;0<n--;)e=r+e;return e}var E=function(){function e(){}return e.prototype.valueOf=function(){},e.prototype.liquidMethodMissing=function(e){},e}(),e=function(n){function e(e,t){var r=n.call(this,e.message)||this;return r.originalError=e,r.token=t,r}return u(e,n),e.prototype.update=function(){var i,s,e,o,t=this.originalError,r=(i=this.token,s=i.input.split("\n"),e=Math.max(i.line-2,1),o=Math.min(i.line+3,s.length),y(e,o+1).map(function(e){var t=e===i.line?">> ":" ",r=T(String(e),String(o).length),n=s[e-1];return""+t+r+"| "+n}).join("\n"));this.message=function(e,t){t.file&&(e+=", file:"+t.file);return e+=", line:"+t.line+", col:"+t.col}(t.message,this.token),this.stack=this.message+"\n"+r+"\n"+this.stack+"\nFrom "+t.stack},e}(Error),R=function(n){function e(e,t){var r=n.call(this,new Error(e),t)||this;return r.name="TokenizationError",n.prototype.update.call(r),r}return u(e,n),e}(e),k=function(n){function e(e,t){var r=n.call(this,e,t)||this;return r.name="ParseError",r.message=e.message,n.prototype.update.call(r),r}return u(e,n),e}(e),x=function(n){function e(e,t){var r=n.call(this,e,t.token)||this;return r.name="RenderError",r.message=e.message,n.prototype.update.call(r),r}return u(e,n),e}(e),O=function(r){function e(e){var t=r.call(this,e)||this;return t.resolvedHTML="",t.name="RenderBreakError",t.message=e+"",t}return u(e,r),e}(Error),_=function(r){function e(e){var t=r.call(this,e)||this;return t.name="AssertionError",t.message=e+"",t}return u(e,r),e}(Error);function S(e,t){if(!e)throw new _(t=t||"expect "+e+" to be true")}var M={root:["."],cache:!1,extname:"",dynamicPartials:!0,trimTagRight:!1,trimTagLeft:!1,trimOutputRight:!1,trimOutputLeft:!1,greedy:!0,tagDelimiterLeft:"{%",tagDelimiterRight:"%}",outputDelimiterLeft:"{{",outputDelimiterRight:"}}",strictFilters:!1,strictVariables:!1};function L(e){var t;return(e=e||{}).hasOwnProperty("root")&&(e.root=g(t=e.root)?t:f(t)?[t]:[]),e}function N(e){return b({},M,e)}var U=function(){function e(e,t){void 0===e&&(e={}),this.scopes=[{}],this.registers={},this.opts=N(t),this.environments=e}return e.prototype.getRegister=function(e,t){return void 0===t&&(t={}),this.registers[e]=this.registers[e]||t},e.prototype.setRegister=function(e,t){return this.registers[e]=t},e.prototype.getAll=function(){return[this.environments].concat(this.scopes).reduce(function(e,t){return b(e,t)},{})},e.prototype.get=function(o){return d(this,void 0,void 0,function(){var t,r,n,i,s;return q(this,function(e){switch(e.label){case 0:return[4,this.parseProp(o)];case 1:for(t=e.sent(),r=this.findScope(t[0])||this.environments,n=0,i=t;n<i.length;n++)if(s=i[n],p(r=A(r,s))&&this.opts.strictVariables)throw new TypeError("undefined variable: "+s);return[2,r]}})})},e.prototype.push=function(e){return this.scopes.push(e)},e.prototype.pop=function(){return this.scopes.pop()},e.prototype.front=function(){return this.scopes[0]},e.prototype.findScope=function(e){for(var t=this.scopes.length-1;0<=t;t--){var r=this.scopes[t];if(e in r)return r}return null},e.prototype.parseProp=function(a){return d(this,void 0,void 0,function(){function t(){n.length&&r.push(n),n=""}var r,n,i,s,o,u;return q(this,function(e){switch(e.label){case 0:a=String(a),r=[],n="",s=0,e.label=1;case 1:if(!(s<a.length))return[3,10];switch(a[s]){case"[":return[3,2];case".":return[3,7]}return[3,8];case 2:return t(),o=a[s+1],/['"]/.test(o)?(S(-1!==(i=a.indexOf(o,s+2)),"unbalanced "+o+": "+a),n=a.slice(s+2,i),t(),s=i+2,[3,6]):[3,3];case 3:return S(-1!==(i=function(e,t){for(var r=1,n=t;n<e.length;n++)if("["===e[n]&&r++,"]"===e[n]&&0===--r)return n;return-1}(a,s+1)),"unbalanced []: "+a),n=a.slice(s+1,i),/^[+-]?\d+$/.test(n)?[3,5]:(u=String,[4,this.get(n)]);case 4:n=u.apply(void 0,[e.sent()]),e.label=5;case 5:t(),s=i+1,e.label=6;case 6:return[3,9];case 7:return t(),s++,[3,9];case 8:n+=a[s++],e.label=9;case 9:return[3,1];case 10:if(t(),!r.length)throw new TypeError('invalid path:"'+a+'"');return[2,r]}})})},e}();function A(e,t){return p(e)?e:(e=l(e))instanceof E?a(e[t])?e[t]():e.hasOwnProperty(t)?e[t]:e.liquidMethodMissing(t):"first"===t&&g(e)?e[0]:"last"===t&&g(e)?e[e.length-1]:"size"===t?p((r=e).size)&&(g(r)||f(r))?r.length:r.size:e[t];var r}var C=Object.freeze({ParseError:k,TokenizationError:R,RenderBreakError:O,AssertionError:_,Drop:E});var D={readFile:function(n){return d(this,void 0,void 0,function(){return q(this,function(e){return[2,new Promise(function(e,t){var r=new XMLHttpRequest;r.onload=function(){200<=r.status&&r.status<300?e(r.responseText):t(new Error(r.statusText))},r.onerror=function(){t(new Error("An error occurred whilst receiving the response."))},r.open("GET",n),r.send()})]})})},resolve:function(e,t,i){return e.length&&"/"!==m(e)&&(e+="/"),function(e,t){var r=document.createElement("base");r.href=e;var n=document.getElementsByTagName("head")[0];n.insertBefore(r,n.firstChild);var i=document.createElement("a");i.href=t;var s=i.href;return n.removeChild(r),s}(e,t).replace(/^(\w+:\/\/[^/]+)(\/[^?]+)/,function(e,t,r){var n=r.split("/").pop();return/\.\w+$/.test(n)?e:t+r+i})},exists:function(){return d(this,void 0,void 0,function(){return q(this,function(e){return[2,!0]})})}},j=function(e,t,r,n,i){this.trimLeft=!1,this.trimRight=!1,this.type="notset",this.col=n,this.line=r,this.raw=e,this.value=e,this.input=t,this.file=i},P=function(h){function e(e,t,r,n,i,s,o,u){var a=h.call(this,e,r,n,i,u)||this,c="-"===t[0],l="-"===m(t);return a.value=t.slice(c?1:0,l?-1:t.length).trim(),a.trimLeft=c||s,a.trimRight=l||o,a}return u(e,h),e}(j),F=new RegExp(/'[^']*'/.source+"|"+/"[^"]*"/.source),H=new RegExp("(?:"+F.source+"|[^'\"])*"),$=/[+-]?(?:\d+\.?\d*|\.?\d+)/,z=/[\w-]+[?]?/,B=new RegExp("\\[(?:"+F.source+"|[\\w-\\.]+)\\]"),I=new RegExp("(?:"+F.source+"|"+/true|false/.source+"|"+$.source+")"),Y=new RegExp(z.source+"(?:\\."+z.source+"|"+B.source+")*"),J=new RegExp("(?:"+Y.source+"|"+$.source+")"),K=new RegExp("\\("+J.source+"\\.\\."+J.source+"\\)"),W=new RegExp("\\(("+J.source+")\\.\\.("+J.source+")\\)"),G=new RegExp("(?:"+Y.source+"|"+I.source+"|"+K.source+")"),V=new RegExp("(?:"+z.source+")\\s*:\\s*(?:"+G.source+")"),Z=new RegExp("("+z.source+")\\s*:\\s*("+G.source+")","g"),X=new RegExp("^\\s*("+z.source+")\\s*([\\s\\S]*?)\\s*$"),Q=new RegExp("^"+F.source+"$"),ee=new RegExp("^"+W.source+"$"),te=new RegExp("^\\s*(?:("+z.source+")\\.)?\\$\\{\\s*([\\s\\S]+?)\\s*\\}\\s*$"),re=[/\s+or\s+/,/\s+and\s+/,/==|!=|<=|>=|<|>|\s+contains\s+/],ne=function(c){function e(e,t,r,n,i,s,o){var u=c.call(this,e,t,r,n,i,s.trimTagLeft,s.trimTagRight,o)||this;u.type="tag";var a=u.value.match(X);if(!a)throw new R("illegal tag syntax",u);return u.name=a[1],u.args=a[2],u}return u(e,c),e.is=function(e){return"tag"===e.type},e}(P),ie=function(o){function e(e,t,r,n,i){var s=o.call(this,e,t,r,n,i)||this;return s.type="html",s.value=e,s}return u(e,o),e.is=function(e){return"html"===e.type},e}(j);function se(e,t){if(e&&ie.is(e)){var r=t?/\s+$/g:/[\t\r ]*$/g;e.value=e.value.replace(r,"")}}function oe(e,t){if(e&&ie.is(e)){var r=t?/^\s+/g:/^[\t\r ]*\n?/g;e.value=e.value.replace(r,"")}}var ue,ae,ce=function(a){function e(e,t,r,n,i,s,o){var u=a.call(this,e,t,r,n,i,s.trimOutputLeft,s.trimOutputRight,o)||this;return u.type="output",u}return u(e,a),e.is=function(e){return"output"===e.type},e}(P);(ae=ue||(ue={}))[ae.HTML=0]="HTML",ae[ae.OUTPUT=1]="OUTPUT",ae[ae.TAG=2]="TAG",ae[ae.ATTRIBUTE=3]="ATTRIBUTE",ae[ae.CONTENT_BLOCKS=4]="CONTENT_BLOCKS";var le=function(){function e(e){this.options=N(e)}return e.prototype.tokenize=function(e,t){for(var r=[],n=this.options,i=n.tagDelimiterLeft,s=n.tagDelimiterRight,o=n.outputDelimiterLeft,u=n.outputDelimiterRight,a="content_blocks",c=0,l=1,h=ue.HTML,p="",f=0,d=1,g=1,v=ue.HTML;c<e.length;){if("\n"===e[c]&&(l++,f=c+1),h===ue.HTML){if(e.substr(c,o.length)===o){for(p&&r.push(new ie(p,e,d,g,t)),d=l,g=c-f+1,c+=(p=o).length;" "===e.substr(c,1);)p+=" ",c+=1;h=e.substr(c,a.length)===a?(p+=a,c+=a.length,ue.CONTENT_BLOCKS):ue.OUTPUT;continue}if(e.substr(c,i.length)===i){p&&r.push(new ie(p,e,d,g,t)),d=l,g=c-f+1,c+=(p=i).length,h=ue.TAG;continue}}else{if((h===ue.OUTPUT||h===ue.CONTENT_BLOCKS)&&"${"===e.substr(c,"${".length)){v=h,p+="${",d=l,g=c-f+1,c+="${".length,h=ue.ATTRIBUTE;continue}if(h===ue.ATTRIBUTE&&"}"===e[c]){p+="}",d=l,g=c-f+1,c+="}".length,h=v,v=ue.HTML;continue}if((h===ue.OUTPUT||h===ue.CONTENT_BLOCKS)&&e.substr(c,u.length)===u){p+=u;var m=h===ue.OUTPUT?ce:ne;r.push(new m(p,p.slice(o.length,-u.length),e,d,g,this.options,t)),p="",d=l,g=(c+=u.length)-f+1,h=ue.HTML;continue}if(e.substr(c,s.length)===s){p+=s,r.push(new ne(p,p.slice(i.length,-s.length),e,d,g,this.options,t)),p="",d=l,g=(c+=s.length)-f+1,h=ue.HTML;continue}}p+=e[c++]}if(h===ue.HTML)return p&&r.push(new ie(p,e,d,g,t)),function(e,t){t=b({greedy:!0},t);for(var r=!1,n=0;n<e.length;n++){var i=e[n];!r&&i.trimLeft&&se(e[n-1],t.greedy),ne.is(i)&&("raw"===i.name?r=!0:"endraw"===i.name&&(r=!1)),!r&&i.trimRight&&oe(e[n+1],t.greedy)}}(r,this.options),r;var w=h===ue.OUTPUT?"output":"tag",y=16<p.length?p.slice(0,13)+"...":p;throw new R(w+' "'+y+'" not closed',new j(p,e,d,g,t))},e}(),he=function(){function e(){}return e.prototype.renderTemplates=function(u,a){return d(this,void 0,void 0,function(){var t,r,n,i,s,o;return q(this,function(e){switch(e.label){case 0:S(a,"unable to evalTemplates: context undefined"),t="",r=0,n=u,e.label=1;case 1:if(!(r<n.length))return[3,6];i=n[r],e.label=2;case 2:return e.trys.push([2,4,,5]),s=t,[4,i.render(a)];case 3:return t=s+e.sent(),[3,5];case 4:if("AbortError"===(o=e.sent()).name)throw o.resolvedHTML="",o;if("RenderBreakError"===o.name)throw o.resolvedHTML=t,o;throw"RenderError"===o.name?o:new x(o,i);case 5:return r++,[3,1];case 6:return[2,t]}})})},e}();function pe(e){return e&&a(e.equals)}var fe=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return u(t,e),t.prototype.equals=function(e){return f(e)||g(e)?0===e.length:!!w(e)&&0===Object.keys(e).length},t.prototype.gt=function(){return!1},t.prototype.geq=function(){return!1},t.prototype.lt=function(){return!1},t.prototype.leq=function(){return!1},t.prototype.valueOf=function(){return""},t}(E),de=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return u(e,t),e.prototype.equals=function(e){return!1===e||(!!p(e instanceof E?e.valueOf():e)||(f(e)?/^\s*$/.test(e):t.prototype.equals.call(this,e)))},e}(fe),ge=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return u(t,e),t.prototype.equals=function(e){return p(e instanceof E?e.valueOf():e)||e instanceof de},t.prototype.gt=function(){return!1},t.prototype.geq=function(){return!1},t.prototype.lt=function(){return!1},t.prototype.leq=function(){return!1},t.prototype.valueOf=function(){return null},t}(E),ve={"==":function(e,t){return pe(e)?e.equals(t):pe(t)?t.equals(e):e===t},"!=":function(e,t){return pe(e)?!e.equals(t):pe(t)?!t.equals(e):e!==t},">":function(e,t){return pe(e)?e.gt(t):pe(t)?t.lt(e):t<e},"<":function(e,t){return pe(e)?e.lt(t):pe(t)?t.gt(e):e<t},">=":function(e,t){return pe(e)?e.geq(t):pe(t)?t.leq(e):t<=e},"<=":function(e,t){return pe(e)?e.leq(t):pe(t)?t.geq(e):e<=t},contains:function(e,t){return!(!e||!a(e.indexOf))&&-1<e.indexOf(t)},and:function(e,t){return be(e)&&be(t)},or:function(e,t){return be(e)||be(t)}};function me(r,n){return d(this,void 0,void 0,function(){var t;return q(this,function(e){switch(e.label){case 0:return[4,function h(p,f){return d(this,void 0,void 0,function(){var t,r,n,i,s,o,u,a,c,l;return q(this,function(e){switch(e.label){case 0:S(f,"unable to parseExp: scope undefined"),t=re,n=0,e.label=1;case 1:return n<t.length?(i=t[n],s=new RegExp("^("+H.source+")("+i.source+")("+H.source+")$"),(r=p.match(s))?[4,h(r[1],f)]:[3,4]):[3,5];case 2:return o=e.sent(),u=ve[r[2].trim()],[4,h(r[3],f)];case 3:return a=e.sent(),[2,u(o,a)];case 4:return n++,[3,1];case 5:return(r=p.match(ee))?[4,ye(r[1],f)]:[3,8];case 6:return c=e.sent(),[4,ye(r[2],f)];case 7:return l=e.sent(),[2,y(+c,+l+1)];case 8:return[2,we(p,f)]}})})}(r,n)];case 1:return[2,(t=e.sent())instanceof E?t.valueOf():t]}})})}function we(n,i){return d(this,void 0,void 0,function(){var t,r;return q(this,function(e){return n?"true"===(n=n.trim())?[2,!0]:"false"===n?[2,!1]:"nil"===n||"null"===n?[2,new ge]:"empty"===n?[2,new fe]:"blank"===n?[2,new de]:isNaN(Number(n))?'"'!==n[0]&&"'"!==n[0]||n[0]!==m(n)?(t=new RegExp(o(i.opts.outputDelimiterLeft)+"\\s*(.*?)\\s*"+o(i.opts.outputDelimiterRight)),n=n.replace(t,"$1"),(r=n.match(te))?r[1]?[2,i.get(r[1]+"['"+r[2]+"']")]:[2,i.get(r[2])]:[2,i.get(n)]):[2,n.slice(1,-1)]:[2,Number(n)]:[2,null]})})}function ye(r,n){return d(this,void 0,void 0,function(){var t;return q(this,function(e){switch(e.label){case 0:return[4,we(r,n)];case 1:return[2,(t=e.sent())instanceof E?t.valueOf():t]}})})}function be(e){return!Te(e)}function Te(e){return!1===e||null==e}var Ee,Re,ke=function(){function c(){}return c.create=function(u,a){return d(this,void 0,void 0,function(){var t,r,n,i,s,o;return q(this,function(e){switch(e.label){case 0:t=new c,Z.lastIndex=0,e.label=1;case 1:return(r=Z.exec(u))?(n=r[1],i=r[2],s=t,o=n,[4,ye(i,a)]):[3,3];case 2:return s[o]=e.sent(),[3,1];case 3:return[2,t]}})})},c}(),xe=function(e){this.token=e},Oe=function(s){function o(e,t,r){var n=s.call(this,e)||this;n.name=e.name;var i=o.impls[e.name];return S(i,"tag "+e.name+" not found"),n.impl=Object.create(i),n.impl.liquid=r,n.impl.parse&&n.impl.parse(e,t),n}return u(o,s),o.prototype.render=function(s){return d(this,void 0,void 0,function(){var t,r,n,i;return q(this,function(e){switch(e.label){case 0:return[4,ke.create(this.token.args,s)];case 1:return t=e.sent(),a((r=this.impl).render)?(i=c,[4,r.render(s,t)]):[3,3];case 2:return n=i.apply(void 0,[e.sent()]),[3,4];case 3:n="",e.label=4;case 4:return[2,n]}})})},o.register=function(e,t){o.impls[e]=t},o.clear=function(){o.impls={}},o.impls={},o}(xe),qe=function(){function i(e,t,r){var n=i.impls[e];if(!n&&r)throw new TypeError("undefined filter: "+e);this.name=e,this.impl=n||function(e){return e},this.args=t}return i.prototype.render=function(l,h){return d(this,void 0,void 0,function(){var t,r,n,i,s,o,u,a,c;return q(this,function(e){switch(e.label){case 0:t=[],r=0,n=this.args,e.label=1;case 1:return r<n.length?g(i=n[r])?(o=(s=t).push,u=[i[0]],[4,ye(i[1],h)]):[3,3]:[3,6];case 2:return o.apply(s,[u.concat([e.sent()])]),[3,5];case 3:return c=(a=t).push,[4,ye(i,h)];case 4:c.apply(a,[e.sent()]),e.label=5;case 5:return r++,[3,1];case 6:return[2,this.impl.apply({context:h},[l].concat(t))]}})})},i.register=function(e,t){i.impls[e]=t},i.clear=function(){i.impls={}},i.impls={},i}(),_e=function(){function e(e,t){this.handlers={},this.stopRequested=!1,this.tokens=e,this.parseToken=t}return e.prototype.on=function(e,t){return this.handlers[e]=t,this},e.prototype.trigger=function(e,t){var r=this.handlers[e];return!!r&&(r(t),!0)},e.prototype.start=function(){var e;for(this.trigger("start");!this.stopRequested&&(e=this.tokens.shift());)if(!(this.trigger("token",e)||ne.is(e)&&this.trigger("tag:"+e.name,e))){var t=this.parseToken(e,this.tokens);this.trigger("template",t)}return this.stopRequested||this.trigger("end"),this},e.prototype.stop=function(){return this.stopRequested=!0,this},e}(),Se=function(){function n(e,t){this.filters=[];var r=n.tokenize(e);this.strictFilters=t,this.initial=r[0],this.parseFilters(r,1)}return n.prototype.parseFilters=function(e,t){for(var r=t;r<e.length;)if("|"===e[r]){for(var n=++r;r<e.length&&"|"!==e[r];)r++;this.parseFilter(e,n,r)}else r++},n.prototype.parseFilter=function(e,t,r){for(var n,i,s=e[t],o=[],u=t+1;u<r+1;u++)u===r||","===e[u]?((n||i)&&o.push(n?[n,i]:i),i=n=void 0):":"===e[u]?(n=i,i=void 0):void 0===i&&(i=e[u]);this.filters.push(new qe(s,o,this.strictFilters))},n.prototype.value=function(i){return d(this,void 0,void 0,function(){var t,r,n;return q(this,function(e){switch(e.label){case 0:return[4,me(this.initial,i)];case 1:t=e.sent(),r=0,n=this.filters,e.label=2;case 2:return r<n.length?[4,n[r].render(t,i)]:[3,5];case 3:t=e.sent(),e.label=4;case 4:return r++,[3,2];case 5:return[2,t]}})})},n.tokenize=function(e){for(var t=[],r=0;r<e.length;){var n=e[r];if('"'===n||"'"===n){var i=r;for(r+=2;r<e.length&&e[r-1]!==n;++r);t.push(e.slice(i,r))}else if(/\s/.test(n))r++;else if(/[|,:]/.test(n))t.push(e[r++]);else{for(i=r++;r<e.length&&!/[|,:\s]/.test(e[r]);++r);t.push(e.slice(i,r))}}return t},n}(),Me=function(n){function e(e,t){var r=n.call(this,e)||this;return r.value=new Se(e.value,t),r}return u(e,n),e.prototype.render=function(t){return d(this,void 0,void 0,function(){return q(this,function(e){switch(e.label){case 0:return[4,this.value.value(t)];case 1:return[2,c(e.sent())]}})})},e}(xe),Le=function(r){function e(e){var t=r.call(this,e)||this;return t.str=e.value,t}return u(e,r),e.prototype.render=function(){return d(this,void 0,void 0,function(){return q(this,function(e){return[2,this.str]})})},e}(xe),Ne=function(){function e(e){this.liquid=e}return e.prototype.parse=function(e){for(var t,r=[];t=e.shift();)r.push(this.parseToken(t,e));return r},e.prototype.parseToken=function(t,e){try{return ne.is(t)?new Oe(t,e,this.liquid):ce.is(t)?new Me(t,this.liquid.options.strictFilters):new Le(t)}catch(e){throw new k(e,t)}},e.prototype.parseStream=function(e){var r=this;return new _e(e,function(e,t){return r.parseToken(e,t)})},e}(),Ue=new RegExp("("+z.source+")\\s*=\\s*([^]*)"),Ae={parse:function(e){var t=e.args.match(Ue);S(t,"illegal token "+e.raw),this.key=t[1],this.value=t[2],this.token=e},render:function(i){return d(this,void 0,void 0,function(){var t,r,n;return q(this,function(e){switch(e.label){case 0:return t=this.value.replace(i.opts.outputDelimiterLeft,"").replace(i.opts.outputDelimiterRight,""),r=i.front(),n=this.key,[4,this.liquid.evalValue(t,i)];case 1:return r[n]=e.sent(),[2]}})})}},Ce=function(r){function e(e){var t=r.call(this)||this;return t.i=0,t.length=e,t}return u(e,r),e.prototype.next=function(){this.i++},e.prototype.index0=function(){return this.i},e.prototype.index=function(){return this.i+1},e.prototype.first=function(){return 0===this.i},e.prototype.last=function(){return this.i===this.length-1},e.prototype.rindex=function(){return this.length-this.i},e.prototype.rindex0=function(){return this.length-this.i-1},e.prototype.valueOf=function(){return JSON.stringify(this)},e}(E),De=new RegExp("^("+z.source+")\\s+in\\s+("+G.source+")(?:\\s+"+V.source+")*(?:\\s+(reversed))?(?:\\s+"+V.source+")*$"),je={type:"block",parse:function(e,t){var r,n=this,i=De.exec(e.args);S(i,"illegal tag: "+e.raw),this.variable=i[1],this.collection=i[2],this.reversed=!!i[3],this.templates=[],this.elseTemplates=[];var s=this.liquid.parser.parseStream(t).on("start",function(){return r=n.templates}).on("tag:else",function(){return r=n.elseTemplates}).on("tag:endfor",function(){return s.stop()}).on("template",function(e){return r.push(e)}).on("end",function(){throw new Error("tag "+e.raw+" not closed")});s.start()},render:function(h,p){return d(this,void 0,void 0,function(){var t,r,n,i,s,o,u,a,c,l;return q(this,function(e){switch(e.label){case 0:return[4,me(this.collection,h)];case 1:if(g(t=e.sent())||(f(t)&&0<t.length?t=[t]:w(t)&&(t=Object.keys(t).map(function(e){return[e,t[e]]}))),!g(t)||!t.length)return[2,this.liquid.renderer.renderTemplates(this.elseTemplates,h)];r=p.offset||0,n=void 0===p.limit?t.length:p.limit,t=t.slice(r,r+n),this.reversed&&t.reverse(),i={forloop:new Ce(t.length)},h.push(i),s="",o=0,u=t,e.label=2;case 2:if(!(o<u.length))return[3,8];a=u[o],i[this.variable]=a,e.label=3;case 3:return e.trys.push([3,5,,6]),c=s,[4,this.liquid.renderer.renderTemplates(this.templates,h)];case 4:return s=c+e.sent(),[3,6];case 5:if("RenderBreakError"!==(l=e.sent()).name)throw l;return s+=l.resolvedHTML,"break"===l.message?[3,8]:[3,6];case 6:i.forloop.next(),e.label=7;case 7:return o++,[3,2];case 8:return h.pop(),[2,s]}})})}},Pe=new RegExp("("+z.source+")"),Fe={parse:function(e,t){var r=this,n=e.args.match(Pe);S(n,e.args+" not valid identifier"),this.variable=n[1],this.templates=[];var i=this.liquid.parser.parseStream(t);i.on("tag:endcapture",function(){return i.stop()}).on("template",function(e){return r.templates.push(e)}).on("end",function(){throw new Error("tag "+e.raw+" not closed")}),i.start()},render:function(r){return d(this,void 0,void 0,function(){var t;return q(this,function(e){switch(e.label){case 0:return[4,this.liquid.renderer.renderTemplates(this.templates,r)];case 1:return t=e.sent(),r.front()[this.variable]=t,[2]}})})}},He={parse:function(e,t){var r=this;this.cond=e.args,this.cases=[],this.elseTemplates=[];var n=[],i=this.liquid.parser.parseStream(t).on("tag:when",function(e){r.cases.push({val:e.args,templates:n=[]})}).on("tag:else",function(){return n=r.elseTemplates}).on("tag:endcase",function(){return i.stop()}).on("template",function(e){return n.push(e)}).on("end",function(){throw new Error("tag "+e.raw+" not closed")});i.start()},render:function(s){return d(this,void 0,void 0,function(){var t,r,n,i;return q(this,function(e){switch(e.label){case 0:t=0,e.label=1;case 1:return t<this.cases.length?[4,me((r=this.cases[t]).val,s)]:[3,5];case 2:return n=e.sent(),[4,me(this.cond,s)];case 3:if(i=e.sent(),n===i)return[2,this.liquid.renderer.renderTemplates(r.templates,s)];e.label=4;case 4:return t++,[3,1];case 5:return[2,this.liquid.renderer.renderTemplates(this.elseTemplates,s)]}})})}},$e={parse:function(e,t){var r=this.liquid.parser.parseStream(t);r.on("token",function(e){"endcomment"===e.name&&r.stop()}).on("end",function(){throw new Error("tag "+e.raw+" not closed")}),r.start()}};(Re=Ee||(Ee={}))[Re.OUTPUT=0]="OUTPUT",Re[Re.STORE=1]="STORE";var ze=Ee,Be=/[^\s,]+/,Ie=new RegExp("with\\s+("+G.source+")"),Ye={parse:function(e){var t=Be.exec(e.args);t&&(this.staticValue=t[0]),(t=G.exec(e.args))&&(this.value=t[0]),(t=Ie.exec(e.args))&&(this.with=t[1])},render:function(c,l){return d(this,void 0,void 0,function(){var t,r,n,i,s,o,u,a;return q(this,function(e){switch(e.label){case 0:return c.opts.dynamicPartials?Q.exec(this.value)?(r=this.value.slice(1,-1),[4,this.liquid.parseAndRender(r,c.getAll(),c.opts)]):[3,2]:[3,5];case 1:return t=e.sent(),[3,4];case 2:return[4,ye(this.value,c)];case 3:t=e.sent(),e.label=4;case 4:return[3,6];case 5:t=this.staticValue,e.label=6;case 6:return S(t,"cannot include with empty filename"),n=c.getRegister("blocks"),i=c.getRegister("blockMode"),c.setRegister("blocks",{}),c.setRegister("blockMode",ze.OUTPUT),this.with?(s=l,o=t,[4,ye(this.with,c)]):[3,8];case 7:s[o]=e.sent(),e.label=8;case 8:return[4,this.liquid.getTemplate(t,c.opts)];case 9:return u=e.sent(),c.push(l),[4,this.liquid.renderer.renderTemplates(u,c)];case 10:return a=e.sent(),c.pop(),c.setRegister("blocks",n),c.setRegister("blockMode",i),[2,a]}})})}},Je={parse:function(e){var t=e.args.match(z);S(t,"illegal identifier "+e.args),this.variable=t[0]},render:function(e){var t=e.environments;return"number"!=typeof t[this.variable]&&(t[this.variable]=0),--t[this.variable]}},Ke=new RegExp("^(?:("+G.source+")\\s*:\\s*)?(.*)$"),We=new RegExp(G.source,"g"),Ge={parse:function(e){var t=Ke.exec(e.args);S(t,"illegal tag: "+e.raw),this.group=t[1]||"";var r=t[2];for(this.candidates=[];t=We.exec(r);)this.candidates.push(t[0]);S(this.candidates.length,"empty candidates: "+e.raw)},render:function(o){return d(this,void 0,void 0,function(){var t,r,n,i,s;return q(this,function(e){switch(e.label){case 0:return[4,ye(this.group,o)];case 1:return t=e.sent(),r="cycle:"+t+":"+this.candidates.join(","),n=o.getRegister("cycle"),void 0===(i=n[r])&&(i=n[r]=0),s=this.candidates[i],i=(i+1)%this.candidates.length,n[r]=i,[2,ye(s,o)]}})})}},Ve={parse:function(e,t){var r,n=this;this.branches=[],this.elseTemplates=[];var i=this.liquid.parser.parseStream(t).on("start",function(){return n.branches.push({cond:e.args,templates:r=[]})}).on("tag:elsif",function(e){n.branches.push({cond:e.args,templates:r=[]})}).on("tag:else",function(){return r=n.elseTemplates}).on("tag:endif",function(){return i.stop()}).on("template",function(e){return r.push(e)}).on("end",function(){throw new Error("tag "+e.raw+" not closed")});i.start()},render:function(s){return d(this,void 0,void 0,function(){var t,r,n,i;return q(this,function(e){switch(e.label){case 0:t=new RegExp(o(s.opts.outputDelimiterLeft)+"\\s*(.*?)\\s*"+o(s.opts.outputDelimiterRight)),r=0,n=this.branches,e.label=1;case 1:return r<n.length?(i=n[r],[4,me(i.cond.replace(t,"$1"),s)]):[3,4];case 2:if(be(e.sent()))return[2,this.liquid.renderer.renderTemplates(i.templates,s)];e.label=3;case 3:return r++,[3,1];case 4:return[2,this.liquid.renderer.renderTemplates(this.elseTemplates,s)]}})})}},Ze={parse:function(e){var t=e.args.match(z);S(t,"illegal identifier "+e.args),this.variable=t[0]},render:function(e){var t=e.environments;"number"!=typeof t[this.variable]&&(t[this.variable]=0);var r=t[this.variable];return t[this.variable]++,r}},Xe=/\S+/,Qe={parse:function(e,t){var r=Xe.exec(e.args);r&&(this.staticLayout=r[0]),(r=G.exec(e.args))&&(this.layout=r[0]),this.tpls=this.liquid.parser.parse(t)},render:function(u,a){return d(this,void 0,void 0,function(){var t,r,n,i,s,o;return q(this,function(e){switch(e.label){case 0:return u.opts.dynamicPartials?[4,ye(this.layout,u)]:[3,2];case 1:return r=e.sent(),[3,3];case 2:r=this.staticLayout,e.label=3;case 3:return S(t=r,"cannot apply layout with empty filename"),u.setRegister("blockMode",ze.STORE),n=u.getRegister("blocks"),[4,this.liquid.renderer.renderTemplates(this.tpls,u)];case 4:return i=e.sent(),void 0===n[""]&&(n[""]=i),[4,this.liquid.getTemplate(t,u.opts)];case 5:return s=e.sent(),u.push(a),u.setRegister("blockMode",ze.OUTPUT),[4,this.liquid.renderer.renderTemplates(s,u)];case 6:return o=e.sent(),u.pop(),[2,o]}})})}},et={parse:function(e,t){var r=this,n=/\w+/.exec(e.args);this.block=n?n[0]:"",this.tpls=[];var i=this.liquid.parser.parseStream(t).on("tag:endblock",function(){return i.stop()}).on("template",function(e){return r.tpls.push(e)}).on("end",function(){throw new Error("tag "+e.raw+" not closed")});i.start()},render:function(s){return d(this,void 0,void 0,function(){var t,r,n,i;return q(this,function(e){switch(e.label){case 0:return t=s.getRegister("blocks"),void 0===(r=t[this.block])?[3,1]:(i=r,[3,3]);case 1:return[4,this.liquid.renderer.renderTemplates(this.tpls,s)];case 2:i=e.sent(),e.label=3;case 3:return n=i,s.getRegister("blockMode",ze.OUTPUT)===ze.STORE?(t[this.block]=n,[2,""]):[2,n]}})})}},tt={parse:function(e,t){var r=this;this.tokens=[];var n=this.liquid.parser.parseStream(t);n.on("token",function(e){"endraw"===e.name?n.stop():r.tokens.push(e)}).on("end",function(){throw new Error("tag "+e.raw+" not closed")}),n.start()},render:function(){return this.tokens.map(function(e){return e.raw}).join("")}},rt=function(n){function e(e,t){var r=n.call(this,e)||this;return r.length=e,r.cols=t,r}return u(e,n),e.prototype.row=function(){return Math.floor(this.i/this.cols)+1},e.prototype.col0=function(){return this.i%this.cols},e.prototype.col=function(){return this.col0()+1},e.prototype.col_first=function(){return 0===this.col0()},e.prototype.col_last=function(){return this.col()===this.cols},e}(Ce),nt=new RegExp("^("+z.source+")\\s+in\\s+("+G.source+")(?:\\s+"+V.source+")*$"),it={assign:Ae,for:je,capture:Fe,case:He,comment:$e,include:Ye,decrement:Je,increment:Ze,cycle:Ge,if:Ve,layout:Qe,block:et,raw:tt,tablerow:{parse:function(e,t){var r,n=this,i=nt.exec(e.args);S(i,"illegal tag: "+e.raw),this.variable=i[1],this.collection=i[2],this.templates=[];var s=this.liquid.parser.parseStream(t).on("start",function(){return r=n.templates}).on("tag:endtablerow",function(){return s.stop()}).on("template",function(e){return r.push(e)}).on("end",function(){throw new Error("tag "+e.raw+" not closed")});s.start()},render:function(l,h){return d(this,void 0,void 0,function(){var t,r,n,i,s,o,u,a,c;return q(this,function(e){switch(e.label){case 0:return[4,me(this.collection,l)];case 1:t=e.sent()||[],r=h.offset||0,n=void 0===h.limit?t.length:h.limit,t=t.slice(r,r+n),i=h.cols||t.length,s=new rt(t.length,i),o={tablerowloop:s},l.push(o),u="",a=0,e.label=2;case 2:return a<t.length?(o[this.variable]=t[a],0===s.col0()&&(1!==s.row()&&(u+="</tr>"),u+='<tr class="row'+s.row()+'">'),u+='<td class="col'+s.col()+'">',c=u,[4,this.liquid.renderer.renderTemplates(this.templates,l)]):[3,5];case 3:u=c+e.sent(),u+="</td>",e.label=4;case 4:return a++,s.next(),[3,2];case 5:return t.length&&(u+="</tr>"),l.pop(),[2,u]}})})}},unless:{parse:function(e,t){var r,n=this;this.templates=[],this.elseTemplates=[];var i=this.liquid.parser.parseStream(t).on("start",function(){r=n.templates,n.cond=e.args}).on("tag:else",function(){return r=n.elseTemplates}).on("tag:endunless",function(){return i.stop()}).on("template",function(e){return r.push(e)}).on("end",function(){throw new Error("tag "+e.raw+" not closed")});i.start()},render:function(t){return d(this,void 0,void 0,function(){return q(this,function(e){switch(e.label){case 0:return[4,me(this.cond,t)];case 1:return[2,Te(e.sent())?this.liquid.renderer.renderTemplates(this.templates,t):this.liquid.renderer.renderTemplates(this.elseTemplates,t)]}})})}},break:{render:function(){return d(this,void 0,void 0,function(){return q(this,function(e){throw new O("break")})})}},continue:{render:function(){return d(this,void 0,void 0,function(){return q(this,function(e){throw new O("continue")})})}}},st={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&#34;","'":"&#39;"},ot={"&amp;":"&","&lt;":"<","&gt;":">","&#34;":'"',"&#39;":"'"};function ut(e){return String(e).replace(/&|<|>|"|'/g,function(e){return st[e]})}var at={escape:ut,escape_once:function(e){return ut(String(e).replace(/&(amp|lt|gt|#34|#39);/g,function(e){return ot[e]}))},newline_to_br:function(e){return e.replace(/\n/g,"<br />")},strip_html:function(e){return e.replace(/<script.*?<\/script>|<!--.*?-->|<style.*?<\/style>|<.*?>/g,"")}},ct={append:function(e,t){return e+t},prepend:function(e,t){return t+e},capitalize:function(e){return c(e).charAt(0).toUpperCase()+e.slice(1)},lstrip:function(e){return c(e).replace(/^\s+/,"")},downcase:function(e){return c(e).toLowerCase()},upcase:function(e){return c(e).toUpperCase()},remove:function(e,t){return e.split(t).join("")},remove_first:function(e,t){return e.replace(t,"")},replace:function(e,t,r){return c(e).split(t).join(r)},replace_first:function(e,t,r){return c(e).replace(t,r)},rstrip:function(e){return c(e).replace(/\s+$/,"")},split:function(e,t){return c(e).replace(new RegExp("("+o(t)+")+$"),"").split(t)},strip:function(e){return c(e).trim()},strip_newlines:function(e){return c(e).replace(/\n/g,"")},truncate:function(e,t,r){return void 0===t&&(t=50),void 0===r&&(r="..."),(e=c(e)).length<=t?e:e.substr(0,t-r.length)+r},truncatewords:function(e,t,r){void 0===t&&(t=15),void 0===r&&(r="...");var n=e.split(/\s+/),i=n.slice(0,t).join(" ");return n.length>=t&&(i+=r),i}},lt={ceil:function(e){return Math.ceil(e)},divided_by:function(e,t){return e/t},floor:function(e){return Math.floor(e)},minus:function(e,t){return Number(e||0)-Number(t)},modulo:function(e,t){return e%t},round:function(e,t){void 0===t&&(t=0);var r=Math.pow(10,t);return Math.round(e*r)/r},plus:function(e,t){return Number(e||0)+Number(t)},times:function(e,t){return e*t}},ht={url_decode:function(e){return e.split("+").map(decodeURIComponent).join(" ")},url_encode:function(e){return e.split(" ").map(encodeURIComponent).join("+")}},pt={join:function(e,t){return e.join(void 0===t?" ":t)},last:function(e){return m(e)},first:function(e){return e[0]},map:function(e,t){return e.map(function(e){return e[t]})},reverse:function(e){return e.reverse()},sort:function(e,t){return e.sort(t)},size:function(e){return e.length},concat:function(e,t){return Array.prototype.concat.call(e,t)},slice:function(e,t,r){return void 0===r&&(r=1),t=t<0?e.length+t:t,e.slice(t,t+r)},uniq:function(e){var t={};return(e||[]).filter(function(e){return!t.hasOwnProperty(String(e))&&(t[String(e)]=!0)})},where:function(e,t,r){return e.filter(function(e){return void 0===r?be(e[t]):e[t]===r})}},ft=["January","February","March","April","May","June","July","August","September","October","November","December"],dt=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],gt=ft.map(wt),vt=dt.map(wt),mt={1:"st",2:"nd",3:"rd",default:"th"};function wt(e){return e.slice(0,3)}var yt={daysInMonth:function(e){return[31,yt.isLeapYear(e)?29:28,31,30,31,30,31,31,30,31,30,31]},getDayOfYear:function(e){for(var t=0,r=0;r<e.getMonth();++r)t+=yt.daysInMonth(e)[r];return t+e.getDate()},getWeekOfYear:function(e,t){var r=this.getDayOfYear(e)+(t-e.getDay()),n=7-new Date(e.getFullYear(),0,1).getDay()+t;return T(String(Math.floor((r-n)/7)+1),2,"0")},isLeapYear:function(e){var t=e.getFullYear();return!(0!=(3&t)||!(t%100||t%400==0&&t))},getSuffix:function(e){var t=e.getDate().toString(),r=parseInt(t.slice(-1));return mt[r]||mt.default},century:function(e){return parseInt(e.getFullYear().toString().substring(0,2),10)}},bt={a:function(e){return vt[e.getDay()]},A:function(e){return dt[e.getDay()]},b:function(e){return gt[e.getMonth()]},B:function(e){return ft[e.getMonth()]},c:function(e){return Tt(e,"%a %b %e %T %Y")},C:function(e){return yt.century(e)},d:function(e){return T(e.getDate(),2,"0")},D:function(e){return Tt(e,"%m/%d/%y")},e:function(e){return T(e.getDate(),2)},H:function(e){return T(e.getHours(),2,"0")},I:function(e){return T(String(e.getHours()%12||12),2,"0")},j:function(e){return T(yt.getDayOfYear(e),3,"0")},k:function(e){return T(e.getHours(),2)},l:function(e){return T(String(e.getHours()%12||12),2)},L:function(e){return T(e.getMilliseconds(),3,"0")},m:function(e){return T(e.getMonth()+1,2,"0")},M:function(e){return T(e.getMinutes(),2,"0")},p:function(e){return e.getHours()<12?"AM":"PM"},P:function(e){return e.getHours()<12?"am":"pm"},q:function(e){return yt.getSuffix(e)},r:function(e){return Tt(e,"%I:%M:%S %p")},R:function(e){return Tt(e,"%H:%M")},s:function(e){return Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds())/1e3},S:function(e){return T(e.getSeconds(),2,"0")},T:function(e){return Tt(e,"%H:%M:%S")},u:function(e){return e.getDay()||7},U:function(e){return yt.getWeekOfYear(e,0)},w:function(e){return e.getDay()},W:function(e){return yt.getWeekOfYear(e,1)},x:function(e){return Tt(e,"%m/%d/%y")},X:function(e){return Tt(e,"%H:%M:%S")},y:function(e){return e.getFullYear().toString().substring(2,4)},Y:function(e){return e.getFullYear()},z:function(e){var t=e.getTimezoneOffset()/60*100;return(0<t?"-":"+")+T(String(Math.abs(t)),4,"0")},"%":function(){return"%"}};function Tt(e,t){for(var r="",n=t;;){var i=/%./g,s=i.exec(n);if(!s)return(r+n).replace(/\s+/g," ");r+=n.slice(0,i.lastIndex-2),n=n.slice(i.lastIndex);var o=s[0].charAt(1),u=bt[o];r+=u?u(e):"%"+o}}bt.h=bt.b,bt.N=bt.L;var Et=b({},at,ct,lt,ht,{date:function(e,t){var r,n,i=e;return"now"===e?i=new Date:isNaN(Number(e))?f(e)&&(i=new Date(e)):(r=new Date(1e3*Number(e)),i=new Date(r.getUTCFullYear(),r.getUTCMonth(),r.getUTCDate(),r.getUTCHours(),r.getUTCMinutes(),r.getUTCSeconds())),(n=i)instanceof Date&&!isNaN(n.getTime())?Tt(i,t):e}},{default:function(e,t){return be(e)?e:t}},pt),Rt=require("request"),kt=require("nano-cache"),xt=global.Promise;function Ot(p,e){(p=p||Rt.defaults(e||{}))._loading={},p._cache=new kt,p._cache.on("del",function(e){delete p._loading[e]}),p._cache.on("clear",function(){p._loading={}});var t=function(n){var h={};return h.promise=new xt(function(i,s){var e,t=n.fresh,o=n.cacheKey,u=n.cacheTTL,a=n.cacheLimit;!u&&!a||o||(e=JSON.stringify(n),o=e.split("").reduce(function(e,t){return(e<<5)-e+t.charCodeAt(0)},0)),delete n.fresh,delete n.cacheKey,delete n.cacheTTL,delete n.cacheLimit,(t||n.qs&&n.qs._)&&o&&p._cache.del(o);var c="get"===(n.method||"get").toLowerCase();if(c&&o){var r=p._cache.get(o);if(r)return r.__fromCache=!0,void i(r);if(p._loading[o])return void(p._loading[o].promise.done?p._loading[o].promise.done(i,s):p._loading[o].promise.then(i,s));p._loading[o]=h}var l=n.resolveWithFullResponse;delete n.resolveWithFullResponse,p(n,function(e,t,r){var n=l?t:r;e||t.statusCode<200||299<t.statusCode?s(e||t):(o&&c&&p._cache.set(o,n,{ttl:u,limit:a}),i(n)),delete p._loading[o]})})};return t.loading=p._loading,t.cache=p._cache,t}xt||console.warn('your nodejs version does not natively support global.Promise, you must pass your custom class, i.e. request.use(require("bluebird")); see https://github.com/akhoury/request-promise-cache#other-promise-libraries');var qt=Ot();qt.original=Rt,qt.defaults=function(e){return Ot(Rt.defaults(e||{}))},qt.use=function(e){return xt=e,qt},module.exports=qt;var _t=Object.freeze({}),St=new RegExp("(https?(?:[^\\s\\{\\}]+|\\{\\{.*?\\}\\})+)(\\s+(\\s|.)*)?$"),Mt=new RegExp(":headers\\s+(\\{(.|\\s)*?[^\\}]\\}([^\\}]|$))"),Lt={parse:function(e){var r=this,t=e.args.match(St);if(!t)throw new Error("illegal token "+e.raw);this.url=t[1];var n=t[2];if(this.options={},n){var i=n.match(Mt);null!=i&&(this.options.headers=JSON.parse(i[1])),n.replace(Mt,"").split(/\s+:/).forEach(function(e){if(""!==e){var t=e.split(/\s+/);"headers"===t[0]&&console.error("Headers JSON malformed. Check your headers value"),r.options[t[0]]=!(1<t.length)||t[1]}})}},render:function(O){return d(this,void 0,void 0,function(){var t,r,n,i,s,o,u,a,c,l,h,p,f,d,g,v,m,w,y,b,T,E,R,k,x;return q(this,function(e){switch(e.label){case 0:return[4,this.liquid.parseAndRender(this.url,O.getAll())];case 1:if(t=e.sent(),r=(this.options.method||"GET").toUpperCase(),n=3e5,"GET"!==r?n=0:0<(i=parseInt(this.options.cache,10))?n=1e3*i:0===i&&(n=1),s=this.options.content_type,"POST"===r&&(s=this.options.content_type||"application/x-www-form-urlencoded"),o={"User-Agent":"brazejs-client","Content-Type":s,Accept:this.options.content_type},!this.options.headers)return[3,5];u=0,a=Object.keys(this.options.headers),e.label=2;case 2:return u<a.length?(c=a[u],l=o,h=c,[4,this.liquid.parseAndRender(this.options.headers[c],O.getAll())]):[3,5];case 3:l[h]=e.sent(),e.label=4;case 4:return u++,[3,2];case 5:if(p=this.options.body,!this.options.body)return[3,12];if("POST"!==r.toUpperCase()||!s.toLowerCase().includes("application/json"))return[3,10];f={},d=0,g=this.options.body.split("&"),e.label=6;case 6:return d<g.length?(v=g[d],m=v.split("="),w=f,y=m[0],[4,this.liquid.parseAndRender(m[1],O.getAll())]):[3,9];case 7:w[y]=e.sent().replace(/(?:\r\n|\r|\n|)/g,""),e.label=8;case 8:return d++,[3,6];case 9:return p=JSON.stringify(f),[3,12];case 10:return[4,this.liquid.parseAndRender(this.options.body,O.getAll())];case 11:p=e.sent(),e.label=12;case 12:if(b={resolveWithFullResponse:!0,method:r,headers:o,body:p,uri:t,cacheKey:t,cacheTTL:n,timeout:2e3},this.options.basic_auth){if(!(T=O.environments.__secrets))throw new Error("No secrets defined in context!");if(!(E=T[this.options.basic_auth]))throw new Error("No secret found for "+this.options.basic_auth);if(!E.username||!E.password)throw new Error("No username or password set for "+this.options.basic_auth);b.auth={user:E.username,pass:E.password}}e.label=13;case 13:return e.trys.push([13,15,,16]),[4,_t(b)];case 14:return R=e.sent(),[3,16];case 15:return k=e.sent(),R=k,[3,16];case 16:if(200<=R.statusCode&&R.statusCode<=299)try{(x=JSON.parse(R.body)).__http_status_code__=R.statusCode,O.environments[this.options.save||"connected"]=x}catch(e){if(void 0===R.headers["content-type"]||!R.headers["content-type"].includes("json"))return[2,R.body];console.error('Failed to parse body as JSON: "'+R.body+'"')}else console.error(t+" responded with "+R.statusCode+":\n"+R.body);return[2]}})})}},Nt=function(r){function e(e){var t=r.call(this,e)||this;return t.name="AbortError",t.message=e+"",t}return u(e,r),e}(Error),Ut=new RegExp("\\(('([^']*)'|\"([^\"]*)\")?\\)"),At=function(e){return e.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g).map(function(e){return e.toLocaleLowerCase()}).join("-")},Ct={connected_content:Lt,abort_message:{parse:function(e){var t=e.args.match(Ut);if(!t)throw new Error("illegal token "+e.raw);this.msg=t[2]||t[3]||"message is aborted"},render:function(e){return d(this,void 0,void 0,function(){return q(this,function(e){throw new Nt(this.msg)})})}},content_blocks:{parse:function(e){var t=e.value.match(te);if(!t)throw new Error("illegal token "+e.raw);this.fileName=t[2],this.extension=".liquid"},render:function(i){return d(this,void 0,void 0,function(){var t,r,n;return q(this,function(e){return S(this.fileName,"content blocks name is undefined"),t=i.getRegister("blocks"),r=i.getRegister("blockMode"),i.setRegister("blocks",{}),i.setRegister("blockMode",ze.OUTPUT),n=function(a,c,l){return d(this,void 0,void 0,function(){var t,r,n,i,s,o,u;return q(this,function(e){switch(e.label){case 0:t=c.environments.__contentBlocks,r={},1===(n=c.opts.root.slice(0)).length&&(i=n[0],s=["./content_blocks","../content_blocks"],t&&t.root&&0<t.root.length&&(s=f(t.root)?[t.root]:t.root),r.root=s.map(function(e){return h.resolve(i,e)})),o=t&&t.ext||".liquid",e.label=1;case 1:return e.trys.push([1,3,,13]),[4,a.getTemplate(l,r)];case 2:return u=e.sent(),[3,13];case 3:e.sent(),e.label=4;case 4:return e.trys.push([4,6,,12]),[4,a.getTemplate(At(l),r)];case 5:return u=e.sent(),[3,12];case 6:e.sent(),e.label=7;case 7:return e.trys.push([7,9,,11]),[4,a.getTemplate(l+o,r)];case 8:return u=e.sent(),[3,11];case 9:return e.sent(),[4,a.getTemplate(At(l)+o,r)];case 10:return u=e.sent(),[3,11];case 11:return[3,12];case 12:return[3,13];case 13:return[2,a.renderer.renderTemplates(u,c)]}})})}(this.liquid,i,this.fileName),i.setRegister("blocks",t),i.setRegister("blockMode",r),[2,n]})})}}},Dt=b({},{property_accessor:function(e,t){return e[t]}},{json_escape:function(e){return JSON.stringify(e).slice(1,-1)}},{url_escape:function(e){return encodeURI(e)},url_param_escape:function(e){return encodeURIComponent(e)}},{md5:function(e){var t=n.createHash("md5");return t.update(e),t.digest("hex")},sha1:function(e){var t=n.createHash("sha1");return t.update(e),t.digest("hex")},sha2:function(e){var t=n.createHash("sha256");return t.update(e),t.digest("hex")},hmac_sha1:function(e,t){var r=n.createHmac("sha1",t);return r.update(e),r.digest("hex")},base64:function(e){return Buffer.from(e,"utf8").toString("base64")}},{number_with_delimiter:function(e){return e.toLocaleString()}});return function(){function t(e){void 0===e&&(e={});var r=this;this.cache={},this.options=N(L(e)),this.parser=new Ne(this),this.renderer=new he,this.tokenizer=new le(this.options),v(it,function(e,t){return r.registerTag(t,e)}),v(Et,function(e,t){return r.registerFilter(t,e)}),v(Ct,function(e,t){return r.registerTag(t,e)}),v(Dt,function(e,t){return r.registerFilter(t,e)})}return t.prototype.parse=function(e,t){var r=this.tokenizer.tokenize(e,t);return this.parser.parse(r)},t.prototype.render=function(e,t,r){var n=b({},this.options,L(r)),i=new U(t,n);return this.renderer.renderTemplates(e,i)},t.prototype.parseAndRender=function(n,i,s){return d(this,void 0,void 0,function(){var t,r;return q(this,function(e){switch(e.label){case 0:return[4,this.parse(n)];case 1:t=e.sent(),e.label=2;case 2:return e.trys.push([2,4,,5]),[4,this.render(t,i,s)];case 3:return[2,e.sent()];case 4:if("AbortError"===(r=e.sent()).name)return[2,r.message];throw r;case 5:return[2]}})})},t.prototype.getTemplate=function(h,p){return d(this,void 0,void 0,function(){var t,r,n,i,s,o,u,a,c,l=this;return q(this,function(e){switch(e.label){case 0:t=L(p),r=t.root?t.root.concat(this.options.root):this.options.root,n=r.map(function(e){return D.resolve(e,h,l.options.extname)}),i=0,s=n,e.label=1;case 1:return i<s.length?(o=s[i],[4,D.exists(o)]):[3,5];case 2:return e.sent()?this.options.cache&&this.cache[o]?[2,this.cache[o]]:(a=this.parse,[4,D.readFile(o)]):[3,4];case 3:return u=a.apply(this,[e.sent(),o]),this.options.cache&&(this.cache[o]=u),[2,u];case 4:return i++,[3,1];case 5:throw(c=new Error("ENOENT")).message='ENOENT: Failed to lookup "'+h+'" in "'+r+'"',c.code="ENOENT",c}})})},t.prototype.renderFile=function(n,i,s){return d(this,void 0,void 0,function(){var t,r;return q(this,function(e){switch(e.label){case 0:return t=L(s),[4,this.getTemplate(n,t)];case 1:return r=e.sent(),[2,this.render(r,i,s)]}})})},t.prototype.evalValue=function(e,t){return new Se(e,this.options.strictFilters).value(t)},t.prototype.registerFilter=function(e,t){return qe.register(e,t)},t.prototype.registerTag=function(e,t){return Oe.register(e,t)},t.prototype.plugin=function(e){return e.call(this,t)},t.prototype.express=function(){var i=this;return function(e,t,r){var n={root:this.root};i.renderFile(e,t,n).then(function(e){return r(null,e)},r)}},(t.default=t).isTruthy=be,t.isFalsy=Te,t.evalExp=me,t.evalValue=ye,t.Types=C,t}()}); //# sourceMappingURL=liquid.min.js.map