expression-language
Version:
Javascript implementation of symfony/expression-language
1 lines • 56.5 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ExpressionLanguage={})}(this,function(e){"use strict";function t(e,t,s){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var s=e[Symbol.toPrimitive];if(void 0!==s){var r=s.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}const s=function(e,t){if(0===e.length)return t.length;if(0===t.length)return e.length;let s,r,i=[];for(s=0;s<=t.length;s++)i[s]=[s];for(r=0;r<=e.length;r++)void 0===i[0]&&(i[0]=[]),i[0][r]=r;for(s=1;s<=t.length;s++)for(r=1;r<=e.length;r++)t.charAt(s-1)===e.charAt(r-1)?i[s][r]=i[s-1][r-1]:i[s][r]=Math.min(i[s-1][r-1]+1,Math.min(i[s][r-1]+1,i[s-1][r]+1));return void 0===i[t.length]&&(i[t.length]=[]),i[t.length][e.length]};class r extends Error{constructor(e,t,s,r,i){super(e),this.name="SyntaxError",this.cursor=t,this.expression=s,this.subject=r,this.proposals=i}toString(){let e=`${this.name}: ${this.message} around position ${this.cursor}`;if(this.expression&&(e+=` for expression \`${this.expression}\``),e+=".",this.subject&&this.proposals){let t=Number.MAX_SAFE_INTEGER,r=null;for(let e of this.proposals){let i=s(this.subject,e);i<t&&(r=e,t=i)}null!==r&&t<3&&(e+=` Did you mean "${r}"?`)}return e}}class i{constructor(e,s){t(this,"next",()=>{if(this.position+=1,void 0===this.tokens[this.position])throw new r("Unexpected end of expression",this.last.cursor,this.expression)}),t(this,"expect",(e,t,s)=>{let i=this.current;if(!i.test(e,t)){let n="";s&&(n=s+". ");let a="";throw t&&(a=` with value "${t}"`),n+=`Unexpected token "${i.type}" of value "${i.value}" ("${e}" expected${a})`,new r(n,i.cursor,this.expression)}this.next()}),t(this,"isEOF",()=>n.EOF_TYPE===this.current.type),t(this,"isEqualTo",e=>{if(null==e||!e instanceof i)return!1;if(e.tokens.length!==this.tokens.length)return!1;let t=e.position;e.position=0;let s=!0;for(let t of this.tokens){if(!e.current.isEqualTo(t)){s=!1;break}e.position<e.tokens.length-1&&e.next()}return e.position=t,s}),t(this,"diff",e=>{let t=[];if(!this.isEqualTo(e)){let s=0,r=e.position;e.position=0;for(let r of this.tokens){let i=r.diff(e.current);i.length>0&&t.push({index:s,diff:i}),e.position<e.tokens.length-1&&e.next()}e.position=r}return t}),this.expression=e,this.position=0,this.tokens=s}get current(){return this.tokens[this.position]}get last(){return this.tokens[this.position-1]}toString(){return this.tokens.join("\n")}}class n{constructor(e,s,r){t(this,"test",(e,t=null)=>this.type===e&&(null===t||this.value===t)),t(this,"isEqualTo",e=>!(null==e||!e instanceof n)&&(e.value==this.value&&e.type===this.type&&e.cursor===this.cursor)),t(this,"diff",e=>{let t=[];return this.isEqualTo(e)||(e.value!==this.value&&t.push(`Value: ${e.value} != ${this.value}`),e.cursor!==this.cursor&&t.push(`Cursor: ${e.cursor} != ${this.cursor}`),e.type!==this.type&&t.push(`Type: ${e.type} != ${this.type}`)),t}),this.value=s,this.type=e,this.cursor=r}toString(){return`${this.cursor} [${this.type}] ${this.value}`}}function a(e){let t=0,s=[],a=[],h=(e=e.replace(/\r|\n|\t|\v|\f/g," ")).length;for(;t<h;){if(" "===e[t]){++t;continue}let i=o(e.substr(t));if(null!==i){const e=i.length;i=-1===i.indexOf(".")?parseInt(i):parseFloat(i),s.push(new n(n.NUMBER_TYPE,i,t+1)),t+=e}else if("([{".indexOf(e[t])>=0)a.push([e[t],t]),s.push(new n(n.PUNCTUATION_TYPE,e[t],t+1)),++t;else if(")]}".indexOf(e[t])>=0){if(0===a.length)throw new r(`Unexpected "${e[t]}"`,t,e);let[i,o]=a.pop(),h=i.replace("(",")").replace("{","}").replace("[","]");if(e[t]!==h)throw new r(`Unclosed "${i}"`,o,e);s.push(new n(n.PUNCTUATION_TYPE,e[t],t+1)),++t}else{let i=u(e.substr(t));if(null!==i)s.push(new n(n.STRING_TYPE,i.captured,t+1)),t+=i.length;else{let i=d(e.substr(t));if(i)s.push(new n(n.OPERATOR_TYPE,i,t+1)),t+=i.length;else if(".,?:".indexOf(e[t])>=0)s.push(new n(n.PUNCTUATION_TYPE,e[t],t+1)),++t;else{let i=f(e.substr(t));if(!i)throw new r(`Unexpected character "${e[t]}"`,t,e);s.push(new n(n.NAME_TYPE,i,t+1)),t+=i.length}}}}if(s.push(new n(n.EOF_TYPE,null,t+1)),a.length>0){let[t,s]=a.pop();throw new r(`Unclosed "${t}"`,s,e)}return new i(e,s)}function o(e){let t=null,s=e.match(/^[0-9]+(?:.[0-9]+)?/);return s&&s.length>0&&(t=s[0]),t}t(n,"EOF_TYPE","end of expression"),t(n,"NAME_TYPE","name"),t(n,"NUMBER_TYPE","number"),t(n,"STRING_TYPE","string"),t(n,"OPERATOR_TYPE","operator"),t(n,"PUNCTUATION_TYPE","punctuation");const h=/^"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'/s;function u(e){let t=null;if(-1===["'",'"'].indexOf(e.substr(0,1)))return t;let s=h.exec(e);return null!==s&&s.length>0&&(t=s[1]?{captured:s[1]}:{captured:s[2]},t.length=s[0].length),t}const c=["&&","and","||","or","+","-","**","*","/","%","&","|","^","===","!==","!=","==","<=",">=","<",">","contains","matches","starts with","ends with","not in","in","not","!","~",".."],l=["and","or","matches","contains","starts with","ends with","not in","in","not"];function d(e){let t=null;for(let s of c)if(e.substr(0,s.length)===s){l.indexOf(s)>=0?e.substr(0,s.length+1)===s+" "&&(t=s):t=s;break}return t}function f(e){let t=null,s=e.match(/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/);return s&&s.length>0&&(t=s[0]),t}function p(e){return/boolean|number|string/.test(typeof e)}function m(e,t){var s="",r=[],i=0,n=0,a="",o="",h="",u="",c="",l=0,d=0,f=0,p=0,m=0,g=[],y="",w=/%([\dA-Fa-f]+)/g,x=function(e,t){return(e+="").length<t?new Array(++t-e.length).join("0")+e:e};for(i=0;i<t.length;i++)if(a=t.charAt(i),o=t.charAt(i+1),"\\"===a&&o&&/\d/.test(o)){if(p=i+(f=(h=t.slice(i+1).match(/^\d+/)[0]).length)+1,t.charAt(p)+t.charAt(p+1)===".."){if(l=h.charCodeAt(0),/\\\d/.test(t.charAt(p+2)+t.charAt(p+3)))u=t.slice(p+3).match(/^\d+/)[0],i+=1;else{if(!t.charAt(p+2))throw new Error("Range with no end point");u=t.charAt(p+2)}if((d=u.charCodeAt(0))>l)for(n=l;n<=d;n++)r.push(String.fromCharCode(n));else r.push(".",h,u);i+=u.length+2}else c=String.fromCharCode(parseInt(h,8)),r.push(c);i+=f}else if(o+t.charAt(i+2)===".."){if(l=(h=a).charCodeAt(0),/\\\d/.test(t.charAt(i+3)+t.charAt(i+4)))u=t.slice(i+4).match(/^\d+/)[0],i+=1;else{if(!t.charAt(i+3))throw new Error("Range with no end point");u=t.charAt(i+3)}if((d=u.charCodeAt(0))>l)for(n=l;n<=d;n++)r.push(String.fromCharCode(n));else r.push(".",h,u);i+=u.length+2}else r.push(a);for(i=0;i<e.length;i++)if(a=e.charAt(i),-1!==r.indexOf(a))if(s+="\\",(m=a.charCodeAt(0))<32||m>126)switch(a){case"\n":s+="n";break;case"\t":s+="t";break;case"\r":s+="r";break;case"":s+="a";break;case"\v":s+="v";break;case"\b":s+="b";break;case"\f":s+="f";break;default:for(y=encodeURIComponent(a),null!==(g=w.exec(y))&&(s+=x(parseInt(g[1],16).toString(8),3));null!==(g=w.exec(y));)s+="\\"+x(parseInt(g[1],16).toString(8),3)}else s+=a;else s+=a;return s}class g{constructor(e={},s={}){t(this,"compile",e=>{for(let t of Object.values(this.nodes))t.compile(e)}),t(this,"evaluate",(e,t)=>{let s=[];for(let r of Object.values(this.nodes))s.push(r.evaluate(e,t));return s}),t(this,"dump",()=>{let e="";for(let t of this.toArray())e+=p(t)?t:t.dump();return e}),t(this,"dumpString",e=>`"${m(e,'\0\t"\\')}"`),t(this,"isHash",e=>{let t=0;for(let s of Object.keys(e))if(s=parseInt(s),s!==t++)return!0;return!1}),this.name="Node",this.nodes=e,this.attributes=s}toString(){let e=[];for(let t of Object.keys(this.attributes)){let s="null";this.attributes[t]&&(s=this.attributes[t].toString()),e.push(`${t}: '${s}'`)}let t=[this.name+"("+e.join(", ")];if(this.nodes.length>0){for(let e of Object.values(this.nodes)){let s=e.toString().split("\n");for(let e of s)t.push(" "+e)}t.push(")")}else t[0]+=")";return t.join("\n")}toArray(){throw new Error(`Dumping a "${this.name}" instance is not supported yet.`)}}class y extends g{constructor(e,s,r){super({left:s,right:r},{operator:e}),t(this,"compile",e=>{let t=this.attributes.operator;"matches"!==t?"contains"!==t?"starts with"!==t?"ends with"!==t?void 0===y.functions[t]?(void 0!==y.operators[t]&&(t=y.operators[t]),e.raw("(").compile(this.nodes.left).raw(" ").raw(t).raw(" ").compile(this.nodes.right).raw(")")):e.raw(`${y.functions[t]}(`).compile(this.nodes.left).raw(", ").compile(this.nodes.right).raw(")"):e.raw("(").compile(this.nodes.left).raw(".toString().toLowerCase().endsWith(").compile(this.nodes.right).raw(".toString().toLowerCase())"):e.raw("(").compile(this.nodes.left).raw(".toString().toLowerCase().startsWith(").compile(this.nodes.right).raw(".toString().toLowerCase())"):e.raw("(").compile(this.nodes.left).raw(".toString().toLowerCase().includes(").compile(this.nodes.right).raw(".toString().toLowerCase())"):e.compile(this.nodes.right).raw(".test(").compile(this.nodes.left).raw(")")}),t(this,"evaluate",(e,t)=>{let s=this.attributes.operator,r=this.nodes.left.evaluate(e,t);if(void 0!==y.functions[s]){let i=this.nodes.right.evaluate(e,t);switch(s){case"not in":return-1===i.indexOf(r);case"in":return i.indexOf(r)>=0;case"..":return function(e,t){let s=[];for(let r=e;r<=t;r++)s.push(r);return s}(r,i);case"**":return Math.pow(r,i)}}let i=null;switch(s){case"or":case"||":return r||(i=this.nodes.right.evaluate(e,t)),r||i;case"and":case"&&":return r&&(i=this.nodes.right.evaluate(e,t)),r&&i}switch(i=this.nodes.right.evaluate(e,t),s){case"|":return r|i;case"^":return r^i;case"&":return r&i;case"==":return r==i;case"===":return r===i;case"!=":return r!=i;case"!==":return r!==i;case"<":return r<i;case">":return r>i;case">=":return r>=i;case"<=":return r<=i;case"not in":return-1===i.indexOf(r);case"in":return i.indexOf(r)>=0;case"+":return r+i;case"-":return r-i;case"~":return r.toString()+i.toString();case"*":return r*i;case"/":return r/i;case"%":return r%i;case"matches":let e=i.match(y.regex_expression);return new RegExp(e[1],e[2]).test(r);case"contains":return r.toString().toLowerCase().includes(i.toString().toLowerCase());case"starts with":return r.toString().toLowerCase().startsWith(i.toString().toLowerCase());case"ends with":return r.toString().toLowerCase().endsWith(i.toString().toLowerCase())}}),this.name="BinaryNode"}toArray(){return["(",this.nodes.left," "+this.attributes.operator+" ",this.nodes.right,")"]}}t(y,"regex_expression",/\/(.+)\/(.*)/),t(y,"operators",{"~":".",and:"&&",or:"||"}),t(y,"functions",{"**":"Math.pow","..":"range",in:"includes","not in":"!includes"});class w extends g{constructor(e,s){super({node:s},{operator:e}),t(this,"compile",e=>{e.raw("(").raw(w.operators[this.attributes.operator]).compile(this.nodes.node).raw(")")}),t(this,"evaluate",(e,t)=>{let s=this.nodes.node.evaluate(e,t);switch(this.attributes.operator){case"not":case"!":return!s;case"-":return-s}return s}),this.name="UnaryNode"}toArray(){return["(",this.attributes.operator+" ",this.nodes.node,")"]}}t(w,"operators",{"!":"!",not:"!","+":"+","-":"-"});class x extends g{constructor(e,s=!1){super({},{value:e}),t(this,"compile",e=>{e.repr(this.attributes.value,this.isIdentifier)}),t(this,"evaluate",(e,t)=>this.attributes.value),t(this,"toArray",()=>{let e=[],t=this.attributes.value;if(this.isIdentifier)e.push(t);else if(!0===t)e.push("true");else if(!1===t)e.push("false");else if(null===t)e.push("null");else if("number"==typeof t)e.push(t);else if("string"==typeof t)e.push(this.dumpString(t));else if(Array.isArray(t)){for(let s of t)e.push(","),e.push(new x(s));e[0]="[",e.push("]")}else if(this.isHash(t)){for(let s of Object.keys(t))e.push(", "),e.push(new x(s)),e.push(": "),e.push(new x(t[s]));e[0]="{",e.push("}")}return e}),this.isIdentifier=s,this.name="ConstantNode"}}class b extends g{constructor(e,s,r){super({expr1:e,expr2:s,expr3:r}),t(this,"compile",e=>{e.raw("((").compile(this.nodes.expr1).raw(") ? (").compile(this.nodes.expr2).raw(") : (").compile(this.nodes.expr3).raw("))")}),t(this,"evaluate",(e,t)=>this.nodes.expr1.evaluate(e,t)?this.nodes.expr2.evaluate(e,t):this.nodes.expr3.evaluate(e,t)),this.name="ConditionalNode"}toArray(){return["(",this.nodes.expr1," ? ",this.nodes.expr2," : ",this.nodes.expr3,")"]}}class v extends g{constructor(e,s){super({arguments:s},{name:e}),t(this,"compile",e=>{let t=[];for(let s of Object.values(this.nodes.arguments.nodes))t.push(e.subcompile(s));let s=e.getFunction(this.attributes.name);e.raw(s.compiler.apply(null,t))}),t(this,"evaluate",(e,t)=>{let s=[t];for(let r of Object.values(this.nodes.arguments.nodes))s.push(r.evaluate(e,t));return e[this.attributes.name].evaluator.apply(null,s)}),this.name="FunctionNode"}toArray(){let e=[];e.push(this.attributes.name);for(let t of Object.values(this.nodes.arguments.nodes))e.push(", "),e.push(t);return e[1]="(",e.push(")"),e}}class k extends g{constructor(e){super({},{name:e}),t(this,"compile",e=>{e.raw(this.attributes.name)}),t(this,"evaluate",(e,t)=>t[this.attributes.name]),this.name="NameNode"}toArray(){return[this.attributes.name]}}class E extends g{constructor(){super(),t(this,"addElement",(e,t=null)=>{null===t?t=new x(++this.index):"Array"===this.type&&(this.type="Object"),this.nodes[(++this.keyIndex).toString()]=t,this.nodes[(++this.keyIndex).toString()]=e}),t(this,"compile",e=>{"Object"===this.type?e.raw("{"):e.raw("["),this.compileArguments(e,"Array"!==this.type),"Object"===this.type?e.raw("}"):e.raw("]")}),t(this,"evaluate",(e,t)=>{let s;if("Array"===this.type){s=[];for(let r of this.getKeyValuePairs())s.push(r.value.evaluate(e,t))}else{s={};for(let r of this.getKeyValuePairs())s[r.key.evaluate(e,t)]=r.value.evaluate(e,t)}return s}),t(this,"getKeyValuePairs",()=>{let e,t,s,r=[],i=Object.values(this.nodes);for(e=0,t=i.length;e<t;e+=2)s=i.slice(e,e+2),r.push({key:s[0],value:s[1]});return r}),t(this,"compileArguments",(e,t=!0)=>{let s=!0;for(let r of this.getKeyValuePairs())s||e.raw(", "),s=!1,t&&e.compile(r.key).raw(": "),e.compile(r.value)}),this.name="ArrayNode",this.type="Array",this.index=-1,this.keyIndex=-1}toArray(){let e={};for(let t of this.getKeyValuePairs())e[t.key.attributes.value]=t.value;let t=[];if(this.isHash(e)){for(let s of Object.keys(e))t.push(", "),t.push(new x(s)),t.push(": "),t.push(e[s]);t[0]="{",t.push("}")}else{for(let s of Object.values(e))t.push(", "),t.push(s);t[0]="[",t.push("]")}return t}}class T extends E{constructor(){super(),t(this,"compile",e=>{this.compileArguments(e,!1)}),this.name="ArgumentsNode"}toArray(){let e=[];for(let t of this.getKeyValuePairs())e.push(t.value),e.push(", ");return e.pop(),e}}class A extends g{constructor(e,s,r,i){super({node:e,attribute:s,arguments:r},{type:i}),t(this,"compile",e=>{switch(this.attributes.type){case A.PROPERTY_CALL:e.compile(this.nodes.node).raw(".").raw(this.nodes.attribute.attributes.value);break;case A.METHOD_CALL:e.compile(this.nodes.node).raw(".").raw(this.nodes.attribute.attributes.value).raw("(").compile(this.nodes.arguments).raw(")");break;case A.ARRAY_CALL:e.compile(this.nodes.node).raw("[").compile(this.nodes.attribute).raw("]")}}),t(this,"evaluate",(e,t)=>{switch(this.attributes.type){case A.PROPERTY_CALL:let s=this.nodes.node.evaluate(e,t),r=this.nodes.attribute.attributes.value;if("object"!=typeof s)throw new Error(`Unable to get property "${r}" on a non-object: `+typeof s);return s[r];case A.METHOD_CALL:let i=this.nodes.node.evaluate(e,t),n=this.nodes.attribute.attributes.value;if("object"!=typeof i)throw new Error(`Unable to call method "${n}" on a non-object: `+typeof i);if(void 0===i[n])throw new Error(`Method "${n}" is undefined on object.`);if("function"!=typeof i[n])throw new Error(`Method "${n}" is not a function on object.`);let a=this.nodes.arguments.evaluate(e,t);return i[n].apply(null,a);case A.ARRAY_CALL:let o=this.nodes.node.evaluate(e,t);if(!Array.isArray(o)&&"object"!=typeof o)throw new Error("Unable to get an item on a non-array: "+typeof o);return o[this.nodes.attribute.evaluate(e,t)]}}),this.name="GetAttrNode"}toArray(){switch(this.attributes.type){case A.PROPERTY_CALL:return[this.nodes.node,".",this.nodes.attribute];case A.METHOD_CALL:return[this.nodes.node,".",this.nodes.attribute,"(",this.nodes.arguments,")"];case A.ARRAY_CALL:return[this.nodes.node,"[",this.nodes.attribute,"]"]}}}t(A,"PROPERTY_CALL",1),t(A,"METHOD_CALL",2),t(A,"ARRAY_CALL",3);class N{constructor(e={}){t(this,"functions",{}),t(this,"unaryOperators",{not:{precedence:50},"!":{precedence:50},"-":{precedence:500},"+":{precedence:500}}),t(this,"binaryOperators",{or:{precedence:10,associativity:1},"||":{precedence:10,associativity:1},and:{precedence:15,associativity:1},"&&":{precedence:15,associativity:1},"|":{precedence:16,associativity:1},"^":{precedence:17,associativity:1},"&":{precedence:18,associativity:1},"==":{precedence:20,associativity:1},"===":{precedence:20,associativity:1},"!=":{precedence:20,associativity:1},"!==":{precedence:20,associativity:1},"<":{precedence:20,associativity:1},">":{precedence:20,associativity:1},">=":{precedence:20,associativity:1},"<=":{precedence:20,associativity:1},"not in":{precedence:20,associativity:1},in:{precedence:20,associativity:1},matches:{precedence:20,associativity:1},contains:{precedence:20,associativity:1},"starts with":{precedence:20,associativity:1},"ends with":{precedence:20,associativity:1},"..":{precedence:25,associativity:1},"+":{precedence:30,associativity:1},"-":{precedence:30,associativity:1},"~":{precedence:40,associativity:1},"*":{precedence:60,associativity:1},"/":{precedence:60,associativity:1},"%":{precedence:60,associativity:1},"**":{precedence:200,associativity:2}}),t(this,"parse",(e,t=[])=>{this.tokenStream=e,this.names=t,this.objectMatches={},this.cachedNames=null,this.nestedExecutions=0;let s=this.parseExpression();if(!this.tokenStream.isEOF())throw new r(`Unexpected token "${this.tokenStream.current.type}" of value "${this.tokenStream.current.value}".`,this.tokenStream.current.cursor,this.tokenStream.expression);return s}),t(this,"parseExpression",(e=0)=>{let t=this.getPrimary(),s=this.tokenStream.current;if(this.nestedExecutions++,this.nestedExecutions>100)throw new Error("Way to many executions on '"+s.toString()+"' of '"+this.tokenStream.toString()+"'");for(;s.test(n.OPERATOR_TYPE)&&void 0!==this.binaryOperators[s.value]&&null!==this.binaryOperators[s.value]&&this.binaryOperators[s.value].precedence>=e;){let e=this.binaryOperators[s.value];this.tokenStream.next();let r=this.parseExpression(1===e.associativity?e.precedence+1:e.precedence);t=new y(s.value,t,r),s=this.tokenStream.current}return 0===e?this.parseConditionalExpression(t):t}),t(this,"getPrimary",()=>{let e=this.tokenStream.current;if(e.test(n.OPERATOR_TYPE)&&void 0!==this.unaryOperators[e.value]&&null!==this.unaryOperators[e.value]){let t=this.unaryOperators[e.value];this.tokenStream.next();let s=this.parseExpression(t.precedence);return this.parsePostfixExpression(new w(e.value,s))}if(e.test(n.PUNCTUATION_TYPE,"(")){this.tokenStream.next();let e=this.parseExpression();return this.tokenStream.expect(n.PUNCTUATION_TYPE,")","An opened parenthesis is not properly closed"),this.parsePostfixExpression(e)}return this.parsePrimaryExpression()}),t(this,"hasVariable",e=>this.getNames().indexOf(e)>=0),t(this,"getNames",()=>{if(null!==this.cachedNames)return this.cachedNames;if(this.names&&this.names.length>0){let e=[],t=0;this.objectMatches={};for(let s of this.names)"object"==typeof s?(this.objectMatches[Object.values(s)[0]]=t,e.push(Object.keys(s)[0]),e.push(Object.values(s)[0])):e.push(s),t++;return this.cachedNames=e,e}return[]}),t(this,"parseArrayExpression",()=>{this.tokenStream.expect(n.PUNCTUATION_TYPE,"[","An array element was expected");let e=new E,t=!0;for(;!this.tokenStream.current.test(n.PUNCTUATION_TYPE,"]")&&(t||(this.tokenStream.expect(n.PUNCTUATION_TYPE,",","An array element must be followed by a comma"),!this.tokenStream.current.test(n.PUNCTUATION_TYPE,"]")));)t=!1,e.addElement(this.parseExpression());return this.tokenStream.expect(n.PUNCTUATION_TYPE,"]","An opened array is not properly closed"),e}),t(this,"parseHashExpression",()=>{this.tokenStream.expect(n.PUNCTUATION_TYPE,"{","A hash element was expected");let e=new E,t=!0;for(;!this.tokenStream.current.test(n.PUNCTUATION_TYPE,"}")&&(t||(this.tokenStream.expect(n.PUNCTUATION_TYPE,",","An array element must be followed by a comma"),!this.tokenStream.current.test(n.PUNCTUATION_TYPE,"}")));){t=!1;let s=null;if(this.tokenStream.current.test(n.STRING_TYPE)||this.tokenStream.current.test(n.NAME_TYPE)||this.tokenStream.current.test(n.NUMBER_TYPE))s=new x(this.tokenStream.current.value),this.tokenStream.next();else{if(!this.tokenStream.current.test(n.PUNCTUATION_TYPE,"(")){let e=this.tokenStream.current;throw new r(`A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "${e.type}" of value "${e.value}"`,e.cursor,this.tokenStream.expression)}s=this.parseExpression()}this.tokenStream.expect(n.PUNCTUATION_TYPE,":","A hash key must be followed by a colon (:)");let i=this.parseExpression();e.addElement(i,s)}return this.tokenStream.expect(n.PUNCTUATION_TYPE,"}","An opened hash is not properly closed"),e}),t(this,"parsePostfixExpression",e=>{let t=this.tokenStream.current;for(;n.PUNCTUATION_TYPE===t.type;){if("."===t.value){if(this.tokenStream.next(),t=this.tokenStream.current,this.tokenStream.next(),n.NAME_TYPE!==t.type&&(n.OPERATOR_TYPE!==t.type||!/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/.test(t.value)))throw new r("Expected name",t.cursor,this.tokenStream.expression);let s=new x(t.value,!0),i=new T,a=null;if(this.tokenStream.current.test(n.PUNCTUATION_TYPE,"(")){a=A.METHOD_CALL;for(let e of Object.values(this.parseArguments().nodes))i.addElement(e)}else a=A.PROPERTY_CALL;e=new A(e,s,i,a)}else{if("["!==t.value)break;{this.tokenStream.next();let t=this.parseExpression();this.tokenStream.expect(n.PUNCTUATION_TYPE,"]"),e=new A(e,t,new T,A.ARRAY_CALL)}}t=this.tokenStream.current}return e}),t(this,"parseArguments",()=>{let e=[];for(this.tokenStream.expect(n.PUNCTUATION_TYPE,"(","A list of arguments must begin with an opening parenthesis");!this.tokenStream.current.test(n.PUNCTUATION_TYPE,")");)0!==e.length&&this.tokenStream.expect(n.PUNCTUATION_TYPE,",","Arguments must be separated by a comma"),e.push(this.parseExpression());return this.tokenStream.expect(n.PUNCTUATION_TYPE,")","A list of arguments must be closed by a parenthesis"),new g(e)}),this.functions=e,this.tokenStream=null,this.names=null,this.objectMatches={},this.cachedNames=null,this.nestedExecutions=0}parseConditionalExpression(e){for(;this.tokenStream.current.test(n.PUNCTUATION_TYPE,"?");){let t,s;this.tokenStream.next(),this.tokenStream.current.test(n.PUNCTUATION_TYPE,":")?(this.tokenStream.next(),t=e,s=this.parseExpression()):(t=this.parseExpression(),this.tokenStream.current.test(n.PUNCTUATION_TYPE,":")?(this.tokenStream.next(),s=this.parseExpression()):s=new x(null)),e=new b(e,t,s)}return e}parsePrimaryExpression(){let e=this.tokenStream.current,t=null;switch(e.type){case n.NAME_TYPE:switch(this.tokenStream.next(),e.value){case"true":case"TRUE":return new x(!0);case"false":case"FALSE":return new x(!1);case"null":case"NULL":return new x(null);default:if("("===this.tokenStream.current.value){if(void 0===this.functions[e.value])throw new r(`The function "${e.value}" does not exist`,e.cursor,this.tokenStream.expression,e.values,Object.keys(this.functions));t=new v(e.value,this.parseArguments())}else{if(!this.hasVariable(e.value))throw new r(`Variable "${e.value}" is not valid`,e.cursor,this.tokenStream.expression,e.value,this.getNames());let s=e.value;void 0!==this.objectMatches[s]&&(s=this.getNames()[this.objectMatches[s]]),t=new k(s)}}break;case n.NUMBER_TYPE:case n.STRING_TYPE:return this.tokenStream.next(),new x(e.value);default:if(e.test(n.PUNCTUATION_TYPE,"["))t=this.parseArrayExpression();else{if(!e.test(n.PUNCTUATION_TYPE,"{"))throw new r(`Unexpected token "${e.type}" of value "${e.value}"`,e.cursor,this.tokenStream.expression);t=this.parseHashExpression()}}return this.parsePostfixExpression(t)}}class S{constructor(e){t(this,"getFunction",e=>this.functions[e]),t(this,"getSource",()=>this.source),t(this,"reset",()=>(this.source="",this)),t(this,"compile",e=>(e.compile(this),this)),t(this,"subcompile",e=>{let t=this.source;this.source="",e.compile(this);let s=this.source;return this.source=t,s}),t(this,"raw",e=>(this.source+=e,this)),t(this,"string",e=>(this.source+='"'+m(e,'\0\t"$\\')+'"',this)),t(this,"repr",(e,t=!1)=>{if(t)this.raw(e);else if(Number.isInteger(e)||+e===e&&(!isFinite(e)||e%1))this.raw(e);else if(null===e)this.raw("null");else if("boolean"==typeof e)this.raw(e?"true":"false");else if("object"==typeof e){this.raw("{");let t=!0;for(let s of Object.keys(e))t||this.raw(", "),t=!1,this.repr(s),this.raw(":"),this.repr(e[s]);this.raw("}")}else if(Array.isArray(e)){this.raw("[");let t=!0;for(let s of e)t||this.raw(", "),t=!1,this.repr(s);this.raw("]")}else this.string(e);return this}),this.source="",this.functions=e}}class O{constructor(e){this.expression=e}toString(){return this.expression}}class C extends O{constructor(e,s){super(e),t(this,"getNodes",()=>this.nodes),this.nodes=s}}var P;class R{constructor(e=0){t(this,"createCacheItem",(e,t,s)=>{let r=new U;return r.key=e,r.value=t,r.isHit=s,r.defaultLifetime=this.defaultLifetime,r}),t(this,"get",(e,t,s=null,r=null)=>{let i=this.getItem(e);if(!i.isHit){let e=!0;this.save(i.set(t(i,e)))}return i.get()}),t(this,"getItem",e=>{let t=this.hasItem(e),s=null;return t?s=this.values[e]:this.values[e]=null,(0,this.createCacheItem)(e,s,t)}),t(this,"getItems",e=>{for(let t of e)"string"==typeof t||this.expiries[t]||U.validateKey(t);return this.generateItems(e,(new Date).getTime()/1e3,this.createCacheItem)}),t(this,"deleteItems",e=>{for(let t of e)this.deleteItem(t);return!0}),t(this,"save",e=>!(!e instanceof U)&&(null!==e.expiry&&e.expiry<=(new Date).getTime()/1e3?(this.deleteItem(e.key),!0):(null===e.expiry&&0<e.defaultLifetime&&(e.expiry=(new Date).getTime()/1e3+e.defaultLifetime),this.values[e.key]=e.value,this.expiries[e.key]=e.expiry||Number.MAX_SAFE_INTEGER,!0))),t(this,"saveDeferred",e=>this.save(e)),t(this,"commit",()=>!0),t(this,"delete",e=>this.deleteItem(e)),t(this,"getValues",()=>this.values),t(this,"hasItem",e=>!!("string"==typeof e&&this.expiries[e]&&this.expiries[e]>(new Date).getTime()/1e3)||(U.validateKey(e),!!this.expiries[e]&&!this.deleteItem(e))),t(this,"clear",()=>(this.values={},this.expiries={},!0)),t(this,"deleteItem",e=>("string"==typeof e&&this.expiries[e]||U.validateKey(e),delete this.values[e],delete this.expiries[e],!0)),t(this,"reset",()=>{this.clear()}),t(this,"generateItems",(e,t,s)=>{let r=[];for(let i of e){let e=null,n=!!this.expiries[i];n||!(this.expiries[i]>t)&&this.deleteItem(i)?e=this.values[i]:this.values[i]=null,r[i]=s(i,e,n)}return r}),this.defaultLifetime=e,this.values={},this.expiries={}}}class U{constructor(){t(this,"getKey",()=>this.key),t(this,"get",()=>this.value),t(this,"set",e=>(this.value=e,this)),t(this,"expiresAt",e=>{if(null===e)this.expiry=this.defaultLifetime>0?Date.now()/1e3+this.defaultLifetime:null;else{if(!(e instanceof Date))throw new Error(`Expiration date must be instance of Date or be null, "${e.name}" given`);this.expiry=e.getTime()/1e3}return this}),t(this,"expiresAfter",e=>{if(null===e)this.expiry=this.defaultLifetime>0?Date.now()/1e3+this.defaultLifetime:null;else{if(!Number.isInteger(e))throw new Error(`Expiration date must be an integer or be null, "${e.name}" given`);this.expiry=(new Date).getTime()/1e3+e}return this}),t(this,"tag",e=>{if(!this.isTaggable)throw new Error(`Cache item "${this.key}" comes from a non tag-aware pool: you cannot tag it.`);Array.isArray(e)||(e=[e]);for(let t of e){if("string"!=typeof t)throw new Error(`Cache tag must by a string, "${typeof t}" given.`);if(this.newMetadata.tags[t]&&""===t)throw new Error("Cache tag length must be greater than zero");this.newMetadata.tags[t]=t}return this}),t(this,"getMetadata",()=>this.metadata),this.key=null,this.value=null,this.isHit=!1,this.expiry=null,this.defaultLifetime=null,this.metadata={},this.newMetadata={},this.innerItem=null,this.poolHash=null,this.isTaggable=!1}}P=U,t(U,"METADATA_EXPIRY_OFFSET",1527506807),t(U,"RESERVED_CHARACTERS",["{","}","(",")","/","\\","@",":"]),t(U,"validateKey",e=>{if("string"!=typeof e)throw new Error(`Cache key must be string, "${typeof e}" given.`);if(""===e)throw new Error("Cache key length must be greater than zero");for(let t of P.RESERVED_CHARACTERS)if(e.indexOf(t)>=0)throw new Error(`Cache key "${e}" contains reserved character "${t}".`);return e});class j extends Error{constructor(e){super(e),this.name="LogicException"}toString(){return`${this.name}: ${this.message}`}}class L{constructor(e=null,s=[]){t(this,"compile",(e,t=[])=>this.getCompiler().compile(this.parse(e,t).getNodes()).getSource()),t(this,"evaluate",(e,t={})=>this.parse(e,Object.keys(t)).getNodes().evaluate(this.functions,t)),t(this,"parse",(e,t)=>{if(e instanceof C)return e;t.sort((e,t)=>{let s=e,r=t;return"object"==typeof e&&(s=Object.values(e)[0]),"object"==typeof t&&(r=Object.values(t)[0]),s.localeCompare(r)});let s=[];for(let e of t){let t=e;if("object"==typeof e){t=Object.keys(e)[0]+":"+Object.values(e)[0]}s.push(t)}let r=this.cache.getItem(this.fixedEncodeURIComponent(e+"//"+s.join("|"))),i=r.get();if(null===i){let s=this.getParser().parse(a(e),t);i=new C(e,s),r.set(i),this.cache.save(r)}return i}),t(this,"fixedEncodeURIComponent",e=>encodeURIComponent(e).replace(/[!'()*]/g,function(e){return"%"+e.charCodeAt(0).toString(16)})),t(this,"register",(e,t,s)=>{if(null!==this.parser)throw new j("Registering functions after calling evaluate(), compile(), or parse() is not supported.");this.functions[e]={compiler:t,evaluator:s}}),t(this,"addFunction",e=>{this.register(e.getName(),e.getCompiler(),e.getEvaluator())}),t(this,"registerProvider",e=>{for(let t of e.getFunctions())this.addFunction(t)}),t(this,"getParser",()=>(null===this.parser&&(this.parser=new N(this.functions)),this.parser)),t(this,"getCompiler",()=>(null===this.compiler&&(this.compiler=new S(this.functions)),this.compiler.reset())),this.functions=[],this.parser=null,this.compiler=null,this.cache=e||new R;for(let e of s)this.registerProvider(e)}_registerFunctions(){}}class _{constructor(e,s,r){t(this,"getName",()=>this.name),t(this,"getCompiler",()=>this.compiler),t(this,"getEvaluator",()=>this.evaluator),this.name=e,this.compiler=s,this.evaluator=r}}class Y{getFunctions(){throw new Error("getFunctions must be implemented by "+this.name)}}const $=new _("isset",function(e){return`isset(${e})`},function(e,t){let s="",r=[],i="",n="";for(let e=0;e<t.length;e++){let a=t[e];if("]"!==a)if("["!==a){if("object"===i&&(!/[A-z0-9_]/.test(a)||e===t.length-1)){let s=!1;if(e===t.length-1&&(n+=a,s=!0),i="",r.push({type:"object",attribute:n}),n="",s)continue}"."!==a?i?n+=a:s+=a:(i="object",n="")}else i="array",n="";else i="",r.push({type:"array",index:n.replace(/"/g,"").replace(/'/g,"")}),n=""}if(r.length>0){if(void 0!==e[s]){let t=e[s];for(let e of r){if("array"===e.type){if(void 0===t[e.index])return!1;t=t[e.index]}if("object"===e.type){if(void 0===t[e.attribute])return!1;t=t[e.attribute]}}return!0}return!1}return void 0!==e[s]});var I,D,M="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},F="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function z(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}function H(){return D?I:(D=1,I=function(e){var t="undefined"!=typeof window?window:M;t.$locutus=t.$locutus||{};var s=t.$locutus;return s.php=s.php||{},s.php.ini=s.php.ini||{},s.php.ini[e]&&void 0!==s.php.ini[e].local_value?null===s.php.ini[e].local_value?"":s.php.ini[e].local_value:""})}var W,B,q=function(e){var t=e+"";if("off"===((void 0!==z?H()("unicode.semantics"):void 0)||"off"))return t.length;var s=0,r=0,i=function(e,t){var s=e.charCodeAt(t),r="",i="";if(s>=55296&&s<=56319){if(e.length<=t+1)throw new Error("High surrogate without following low surrogate");if((r=e.charCodeAt(t+1))<56320||r>57343)throw new Error("High surrogate without following low surrogate");return e.charAt(t)+e.charAt(t+1)}if(s>=56320&&s<=57343){if(0===t)throw new Error("Low surrogate without preceding high surrogate");if((i=e.charCodeAt(t-1))<55296||i>56319)throw new Error("Low surrogate without preceding high surrogate");return!1}return e.charAt(t)};for(s=0,r=0;s<t.length;s++)!1!==i(t,s)&&r++;return r};var V=function(e,t,s){var r=function(){if(B)return W;B=1;var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};return W=function(t){switch(void 0===t?"undefined":e(t)){case"boolean":return t?"1":"";case"string":return t;case"number":return isNaN(t)?"NAN":isFinite(t)?t+"":(t<0?"-":"")+"INF";case"undefined":return"";case"object":return Array.isArray(t)?"Array":null!==t?"Object":"";default:throw new Error("Unsupported value type")}}}();e=r(e);var i="on"===H()("unicode.semantics");i&&(e=e.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\s\S]/g)||[]);var n=e.length,a=n;return t<0&&(t+=a),void 0!==s&&(a=s<0?s+a:s+t),!(t>n||t<0||t>a)&&(i?e.slice(t,a).join(""):e.slice(t,a))};var G=function(e){var t={},s=arguments.length,r=s-1,i="",n={},a=0,o="";e:for(i in e)t:for(a=1;a<s;a++){for(o in n=arguments[a])if(n[o]===e[i]){a===r&&(t[i]=e[i]);continue t}continue e}return t},K=function e(t,s){var r=void 0,i=0;if(null==t)return 0;if(t.constructor!==Array&&t.constructor!==Object)return 1;for(r in"COUNT_RECURSIVE"===s&&(s=1),1!==s&&(s=0),t)t.hasOwnProperty(r)&&(i++,1!==s||!t[r]||t[r].constructor!==Array&&t[r].constructor!==Object||(i+=e(t[r],1)));return i},Z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};const J=new _("implode",function(e,t){return`implode(${e}, ${t})`},function(e,t,s){return function(e,t){var s="",r="",i="";if(1===arguments.length&&(t=e,e=""),"object"===(void 0===t?"undefined":Z(t))){if("[object Array]"===Object.prototype.toString.call(t))return t.join(e);for(s in t)r+=i+t[s],i=e;return r}return t}(t,s)}),X=new _("count",function(e,t){let s="";return t&&(s=`, ${t}`),`count(${e}${s})`},function(e,t,s){return K(t,s)}),Q=new _("array_intersect",function(e,...t){let s="";return t.length>0&&(s=", "+t.join(", ")),`array_intersect(${e}${s})`},function(e){let t=[],s=!0;for(let e=1;e<arguments.length;e++)t.push(arguments[e]),Array.isArray(arguments[e])||(s=!1);let r=G.apply(null,t);return s?Object.values(r):r});var ee="[ \\t]+",te="[ \\t]*",se="(?:([ap])\\.?m\\.?([\\t ]|$))",re="(2[0-4]|[01]?[0-9])",ie="([01][0-9]|2[0-4])",ne="(0?[1-9]|1[0-2])",ae="([0-5]?[0-9])",oe="([0-5][0-9])",he="(60|[0-5]?[0-9])",ue="(60|[0-5][0-9])",ce="(?:\\.([0-9]+))",le="sunday|monday|tuesday|wednesday|thursday|friday|saturday",de="sun|mon|tue|wed|thu|fri|sat",fe=le+"|"+de+"|weekdays?",pe="first|second|third|fourth|fifth|sixth|seventh|eighth?|ninth|tenth|eleventh|twelfth",me="next|last|previous|this",ge="(?:second|sec|minute|min|hour|day|fortnight|forthnight|month|year)s?|weeks|"+fe,ye="([0-9]{1,4})",we="([0-9]{4})",xe="(1[0-2]|0?[0-9])",be="(0[0-9]|1[0-2])",ve="(?:(3[01]|[0-2]?[0-9])(?:st|nd|rd|th)?)",ke="(0[0-9]|[1-2][0-9]|3[01])",Ee="january|february|march|april|may|june|july|august|september|october|november|december",Te="jan|feb|mar|apr|may|jun|jul|aug|sept?|oct|nov|dec",Ae="("+Ee+"|"+Te+"|i[vx]|vi{0,3}|xi{0,2}|i{1,3})",Ne="((?:GMT)?([+-])"+re+":?"+ae+"?)",Se=Ae+"[ .\\t-]*"+ve+"[,.stndrh\\t ]*";function Oe(e,t){switch(t=t&&t.toLowerCase()){case"a":e+=12===e?-12:0;break;case"p":e+=12!==e?12:0}return e}function Ce(e){var t=+e;return e.length<4&&t<100&&(t+=t<70?2e3:1900),t}function Pe(e){return{jan:0,january:0,i:0,feb:1,february:1,ii:1,mar:2,march:2,iii:2,apr:3,april:3,iv:3,may:4,v:4,jun:5,june:5,vi:5,jul:6,july:6,vii:6,aug:7,august:7,viii:7,sep:8,sept:8,september:8,ix:8,oct:9,october:9,x:9,nov:10,november:10,xi:10,dec:11,december:11,xii:11}[e.toLowerCase()]}function Re(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return{mon:1,monday:1,tue:2,tuesday:2,wed:3,wednesday:3,thu:4,thursday:4,fri:5,friday:5,sat:6,saturday:6,sun:0,sunday:0}[e.toLowerCase()]||t}function Ue(e,t){if(!(e=e&&e.match(/(?:GMT)?([+-])(\d+)(:?)(\d{0,2})/i)))return t;var s="-"===e[1]?-1:1,r=+e[2],i=+e[4];return e[4]||e[3]||(i=Math.floor(r%100),r=Math.floor(r/100)),s*(60*r+i)*60}var je={acdt:37800,acst:34200,addt:-7200,adt:-10800,aedt:39600,aest:36e3,ahdt:-32400,ahst:-36e3,akdt:-28800,akst:-32400,amt:-13840,apt:-10800,ast:-14400,awdt:32400,awst:28800,awt:-10800,bdst:7200,bdt:-36e3,bmt:-14309,bst:3600,cast:34200,cat:7200,cddt:-14400,cdt:-18e3,cemt:10800,cest:7200,cet:3600,cmt:-15408,cpt:-18e3,cst:-21600,cwt:-18e3,chst:36e3,dmt:-1521,eat:10800,eddt:-10800,edt:-14400,eest:10800,eet:7200,emt:-26248,ept:-14400,est:-18e3,ewt:-14400,ffmt:-14660,fmt:-4056,gdt:39600,gmt:0,gst:36e3,hdt:-34200,hkst:32400,hkt:28800,hmt:-19776,hpt:-34200,hst:-36e3,hwt:-34200,iddt:14400,idt:10800,imt:25025,ist:7200,jdt:36e3,jmt:8440,jst:32400,kdt:36e3,kmt:5736,kst:30600,lst:9394,mddt:-18e3,mdst:16279,mdt:-21600,mest:7200,met:3600,mmt:9017,mpt:-21600,msd:14400,msk:10800,mst:-25200,mwt:-21600,nddt:-5400,ndt:-9052,npt:-9e3,nst:-12600,nwt:-9e3,nzdt:46800,nzmt:41400,nzst:43200,pddt:-21600,pdt:-25200,pkst:21600,pkt:18e3,plmt:25590,pmt:-13236,ppmt:-17340,ppt:-25200,pst:-28800,pwt:-25200,qmt:-18840,rmt:5794,sast:7200,sdmt:-16800,sjmt:-20173,smt:-13884,sst:-39600,tbmt:10751,tmt:12344,uct:0,utc:0,wast:7200,wat:3600,wemt:7200,west:3600,wet:0,wib:25200,wita:28800,wit:32400,wmt:5040,yddt:-25200,ydt:-28800,ypt:-28800,yst:-32400,ywt:-28800,a:3600,b:7200,c:10800,d:14400,e:18e3,f:21600,g:25200,h:28800,i:32400,k:36e3,l:39600,m:43200,n:-3600,o:-7200,p:-10800,q:-14400,r:-18e3,s:-21600,t:-25200,u:-28800,v:-32400,w:-36e3,x:-39600,y:-43200,z:0},Le={yesterday:{regex:/^yesterday/i,name:"yesterday",callback:function(){return this.rd-=1,this.resetTime()}},now:{regex:/^now/i,name:"now"},noon:{regex:/^noon/i,name:"noon",callback:function(){return this.resetTime()&&this.time(12,0,0,0)}},midnightOrToday:{regex:/^(midnight|today)/i,name:"midnight | today",callback:function(){return this.resetTime()}},tomorrow:{regex:/^tomorrow/i,name:"tomorrow",callback:function(){return this.rd+=1,this.resetTime()}},timestamp:{regex:/^@(-?\d+)/i,name:"timestamp",callback:function(e,t){return this.rs+=+t,this.y=1970,this.m=0,this.d=1,this.dates=0,this.resetTime()&&this.zone(0)}},firstOrLastDay:{regex:/^(first|last) day of/i,name:"firstdayof | lastdayof",callback:function(e,t){"first"===t.toLowerCase()?this.firstOrLastDayOfMonth=1:this.firstOrLastDayOfMonth=-1}},backOrFrontOf:{regex:RegExp("^(back|front) of "+re+te+se+"?","i"),name:"backof | frontof",callback:function(e,t,s,r){var i=+s,n=15;return"back"===t.toLowerCase()||(i-=1,n=45),i=Oe(i,r),this.resetTime()&&this.time(i,n,0,0)}},weekdayOf:{regex:RegExp("^("+pe+"|"+me+")"+ee+"("+le+"|"+de+")"+ee+"of","i"),name:"weekdayof"},mssqltime:{regex:RegExp("^"+ne+":"+oe+":"+ue+"[:.]([0-9]+)"+se,"i"),name:"mssqltime",callback:function(e,t,s,r,i,n){return this.time(Oe(+t,n),+s,+r,+i.substr(0,3))}},oracledate:{regex:/^(\d{2})-([A-Z]{3})-(\d{2})$/i,name:"d-M-y",callback:function(e,t,s,r){var i={JAN:0,FEB:1,MAR:2,APR:3,MAY:4,JUN:5,JUL:6,AUG:7,SEP:8,OCT:9,NOV:10,DEC:11}[s.toUpperCase()];return this.ymd(2e3+parseInt(r,10),i,parseInt(t,10))}},timeLong12:{regex:RegExp("^"+ne+"[:.]"+ae+"[:.]"+ue+te+se,"i"),name:"timelong12",callback:function(e,t,s,r,i){return this.time(Oe(+t,i),+s,+r,0)}},timeShort12:{regex:RegExp("^"+ne+"[:.]"+oe+te+se,"i"),name:"timeshort12",callback:function(e,t,s,r){return this.time(Oe(+t,r),+s,0,0)}},timeTiny12:{regex:RegExp("^"+ne+te+se,"i"),name:"timetiny12",callback:function(e,t,s){return this.time(Oe(+t,s),0,0,0)}},soap:{regex:RegExp("^"+we+"-"+be+"-"+ke+"T"+ie+":"+oe+":"+ue+ce+Ne+"?","i"),name:"soap",callback:function(e,t,s,r,i,n,a,o,h){return this.ymd(+t,s-1,+r)&&this.time(+i,+n,+a,+o.substr(0,3))&&this.zone(Ue(h))}},wddx:{regex:RegExp("^"+we+"-"+xe+"-"+ve+"T"+re+":"+ae+":"+he),name:"wddx",callback:function(e,t,s,r,i,n,a){return this.ymd(+t,s-1,+r)&&this.time(+i,+n,+a,0)}},exif:{regex:RegExp("^"+we+":"+be+":"+ke+" "+ie+":"+oe+":"+ue,"i"),name:"exif",callback:function(e,t,s,r,i,n,a){return this.ymd(+t,s-1,+r)&&this.time(+i,+n,+a,0)}},xmlRpc:{regex:RegExp("^"+we+be+ke+"T"+re+":"+oe+":"+ue),name:"xmlrpc",callback:function(e,t,s,r,i,n,a){return this.ymd(+t,s-1,+r)&&this.time(+i,+n,+a,0)}},xmlRpcNoColon:{regex:RegExp("^"+we+be+ke+"[Tt]"+re+oe+ue),name:"xmlrpcnocolon",callback:function(e,t,s,r,i,n,a){return this.ymd(+t,s-1,+r)&&this.time(+i,+n,+a,0)}},clf:{regex:RegExp("^"+ve+"/("+Te+")/"+we+":"+ie+":"+oe+":"+ue+ee+Ne,"i"),name:"clf",callback:function(e,t,s,r,i,n,a,o){return this.ymd(+r,Pe(s),+t)&&this.time(+i,+n,+a,0)&&this.zone(Ue(o))}},iso8601long:{regex:RegExp("^t?"+re+"[:.]"+ae+"[:.]"+he+ce,"i"),name:"iso8601long",callback:function(e,t,s,r,i){return this.time(+t,+s,+r,+i.substr(0,3))}},dateTextual:{regex:RegExp("^"+Ae+"[ .\\t-]*"+ve+"[,.stndrh\\t ]+"+ye,"i"),name:"datetextual",callback:function(e,t,s,r){return this.ymd(Ce(r),Pe(t),+s)}},pointedDate4:{regex:RegExp("^"+ve+"[.\\t-]"+xe+"[.-]"+we),name:"pointeddate4",callback:function(e,t,s,r){return this.ymd(+r,s-1,+t)}},pointedDate2:{regex:RegExp("^"+ve+"[.\\t]"+xe+"\\.([0-9]{2})"),name:"pointeddate2",callback:function(e,t,s,r){return this.ymd(Ce(r),s-1,+t)}},timeLong24:{regex:RegExp("^t?"+re+"[:.]"+ae+"[:.]"+he),name:"timelong24",callback:function(e,t,s,r){return this.time(+t,+s,+r,0)}},dateNoColon:{regex:RegExp("^"+we+be+ke),name:"datenocolon",callback:function(e,t,s,r){return this.ymd(+t,s-1,+r)}},pgydotd:{regex:RegExp("^"+we+"\\.?(00[1-9]|0[1-9][0-9]|[12][0-9][0-9]|3[0-5][0-9]|36[0-6])"),name:"pgydotd",callback:function(e,t,s){return this.ymd(+t,0,+s)}},timeShort24:{regex:RegExp("^t?"+re+"[:.]"+ae,"i"),name:"timeshort24",callback:function(e,t,s){return this.time(+t,+s,0,0)}},iso8601noColon:{regex:RegExp("^t?"+ie+oe+ue,"i"),name:"iso8601nocolon",callback:function(e,t,s,r){return this.time(+t,+s,+r,0)}},iso8601dateSlash:{regex:RegExp("^"+we+"/"+be+"/"+ke+"/"),name:"iso8601dateslash",callback:function(e,t,s,r){return this.ymd(+t,s-1,+r)}},dateSlash:{regex:RegExp("^"+we+"/"+xe+"/"+ve),name:"dateslash",callback:function(e,t,s,r){return this.ymd(+t,s-1,+r)}},american:{regex:RegExp("^"+xe+"/"+ve+"/"+ye),name:"american",callback:function(e,t,s,r){return this.ymd(Ce(r),t-1,+s)}},americanShort:{regex:RegExp("^"+xe+"/"+ve),name:"americanshort",callback:function(e,t,s){return this.ymd(this.y,t-1,+s)}},gnuDateShortOrIso8601date2:{regex:RegExp("^"+ye+"-"+xe+"-"+ve),name:"gnudateshort | iso8601date2",callback:function(e,t,s,r){return this.ymd(Ce(t),s-1,+r)}},iso8601date4:{regex:RegExp("^([+-]?[0-9]{4})-"+be+"-"+ke),name:"iso8601date4",callback:function(e,t,s,r){return this.ymd(+t,s-1,+r)}},gnuNoColon:{regex:RegExp("^t?"+ie+oe,"i"),name:"gnunocolon",callback:function(e,t,s){switch(this.times){case 0:return this.time(+t,+s,0,this.f);case 1:return this.y=100*t+ +s,this.times++,!0;default:return!1}}},gnuDateShorter:{regex:RegExp("^"+we+"-"+xe),name:"gnudateshorter",callback:function(e,t,s){return this.ymd(+t,s-1,1)}},pgTextReverse:{regex:RegExp("^(\\d{3,4}|[4-9]\\d|3[2-9])-("+Te+")-"+ke,"i"),name:"pgtextreverse",callback:function(e,t,s,r){return this.ymd(Ce(t),Pe(s),+r)}},dateFull:{regex:RegExp("^"+ve+"[ \\t.-]*"+Ae+"[ \\t.-]*"+ye,"i"),name:"datefull",callback:function(e,t,s,r){return this.ymd(Ce(r),Pe(s),+t)}},dateNoDay:{regex:RegExp("^"+Ae+"[ .\\t-]*"+we,"i"),name:"datenoday",callback:function(e,t,s){return this.ymd(+s,Pe(t),1)}},dateNoDayRev:{regex:RegExp("^"+we+"[ .\\t-]*"+Ae,"i"),name:"datenodayrev",callback:function(e,t,s){return this.ymd(+t,Pe(s),1)}},pgTextShort:{regex:RegExp("^("+Te+")-"+ke+"-"+ye,"i"),name:"pgtextshort",callback:function(e,t,s,r){return this.ymd(Ce(r),Pe(t),+s)}},dateNoYear:{regex:RegExp("^"+Se,"i"),name:"datenoyear",callback:function(e,t,s){return this.ymd(this.y,Pe(t),+s)}},dateNoYearRev:{regex:RegExp("^"+ve+"[ .\\t-]*"+Ae,"i"),name:"datenoyearrev",callback:function(e,t,s){return this.ymd(this.y,Pe(s),+t)}},isoWeekDay:{regex:RegExp("^"+we+"-?W(0[1-9]|[1-4][0-9]|5[0-3])(?:-?([0-7]))?"),name:"isoweekday | isoweek",callback:function(e,t,s,r){if(r=r?+r:1,!this.ymd(+t,0,1))return!1;var i=new Date(this.y,this.m,this.d).getDay();i=0-(i>4?i-7:i),this.rd+=i+7*(s-1)+r}},relativeText:{regex:RegExp("^("+pe+"|"+me+")"+ee+"("+ge+")","i"),name:"relativetext",callback:function(e,t,s){var r,i={amount:{last:-1,previous:-1,this:0,first:1,next:1,second:2,third:3,fourth:4,fifth:5,sixth:6,seventh:7,eight:8,eighth:8,ninth:9,tenth:10,eleventh:11,twelfth:12}[r=t.toLowerCase()],behavior:{this:1}[r]||0}.amount;switch(s.toLowerCase()){case"sec":case"secs":case"second":case"seconds":this.rs+=i;break;case"min":case"mins":case"minute":case"minutes":this.ri+=i;break;case"hour":case"hours":this.rh+=i;break;case"day":case"days":this.rd+=i;break;case"fortnight":case"fortnights":case"forthnight":case"forthnights":this.rd+=14*i;break;case"week":case"weeks":this.rd+=7*i;break;case"month":case"months":this.rm+=i;break;case"year":case"years":this.ry+=i;break;case"mon":case"monday":case"tue":case"tuesday":case"wed":case"wednesday":case"thu":case"thursday":case"fri":case"friday":case"sat":case"saturday":case"sun":case"sunday":this.resetTime(),this.weekday=Re(s,7),this.weekdayBehavior=1,this.rd+=7*(i>0?i-1:i)}}},relative:{regex:RegExp("^([+-]*)[ \\t]*(\\d+)"+te+"("+ge+"|week)","i"),name:"relative",callback:function(e,t,s,r){var i=t.replace(/[^-]/g,"").length,n=+s*Math.pow(-1,i);switch(r.toLowerCase()){case"sec":case"secs":case"second":case"seconds":this.rs+=n;break;case"min":case"mins":case"minute":case"minutes":this.ri+=n;break;case"hour":case"hours":this.rh+=n;break;case"day":case"days":this.rd+=n;break;case"fortnight":case"fortnights":case"forthnight":case"forthnights":this.rd+=14*n;break;case"week":case"weeks":this.rd+=7*n;break;case"month":case"months":this.rm+=n;break;case"year":case"years":this.ry+=n;break;case"mon":case"monday":case"tue":case"tuesday":case"wed":case"wednesday":case"thu":case"thursday":case"fri":case"friday":case"sat":case"saturday":case"sun":case"sunday":this.resetTime(),this.weekday=Re(r,7),this.weekdayBehavior=1,this.rd+=7*(n>0?n-1:n)}}},dayText:{regex:RegExp("^("+fe+")","i"),name:"daytext",callback:function(e,t){this.resetTime(),this.weekday=Re(t,0),2!==this.weekdayBehavior&&(this.weekdayBehavior=1)}},relativeTextWeek:{regex:RegExp("^("+me+")"+ee+"week","i"),name:"relativetextweek",callback:function(e,t){switch(this.weekdayBehavior=2,t.toLowerCase()){case"this":this.rd+=0;break;case"next":this.rd+=7;break;case"last":case"previous":this.rd-=7}isNaN(this.weekday)&&(this.weekday=1)}},monthFullOrMonthAbbr:{regex:RegExp("^("+Ee+"|"+Te+")","i"),name:"monthfull | monthabbr",callback:function(e,t){return this.ymd(this.y,Pe(t),this.d)}},tzCorrection:{regex:RegExp("^"+Ne,"i"),name:"tzcorrection",callback:function(e){return this.zone(Ue(e))}},tzAbbr:{regex:RegExp("^\\(?([a-zA-Z]{1,6})\\)?"),name:"tzabbr",callback:function(e,t){var s=je[t.toLowerCase()];return!isNaN(s)&&this.zone(s)}},ago:{regex:/^ago/i,name:"ago",callback:function(){this.ry=-this.ry,this.rm=-this.rm,this.rd=-this.rd,this.rh=-this.rh,this.ri=-this.ri,this.rs=-this.rs,this.rf=-this.rf}},year4:{regex:RegExp("^"+we),name:"year4",callback:function(e,t){return this.y=+t,!0}},whitespace:{regex:/^[ .,\t]+/,name:"whitespace"},dateShortWithTimeLong:{regex:RegExp("^"+Se+"t?"+re+"[:.]"+ae+"[:.]"+he,"i"),name:"dateshortwithtimelong",callback:function(e,t,s,r,i,n){return this.ymd(this.y,Pe(t),+s)&&this.time(+r,+i,+n,0)}},dateShortWithTimeLong12:{regex:RegExp("^"+Se+ne+"[:.]"+ae+"[:.]"+ue+te+se,"i"),name:"dateshortwithtimelong12",callback:function(e,t,s,r,i,n,a){return this.ymd(this.y,Pe(t),+s)&&this.time(Oe(+r,a),+i,+n,0)}},dateShortWithTimeShort:{regex:RegExp("^"+Se+"t?"+re+"[:.]"+ae,"i"),name:"dateshortwithtimeshort",callback:function(e,t,s,r,i){return this.ymd(this.y,Pe(t),+s)&&this.time(+r,+i,0,0)}},dateShortWithTimeShort12:{regex:RegExp("^"+Se+ne+"[:.]"+oe+te+se,"i"),name:"dateshortwithtimeshort12",callback:function(e,t,s,r,i,n){return this.ymd(this.y,Pe(t),+s)&&this.time(Oe(+r,n),+i,0,0)}}},_e={y:NaN,m:NaN,d:NaN,h:NaN,i:NaN,s:NaN,f:NaN,ry:0,rm:0,rd:0,rh:0,ri:0,rs:0,rf:0,weekday:NaN,weekdayBehavior:0,firstOrLastDayOfMonth:0,z:NaN,dates:0,times:0,zones:0,ymd:function(e,t,s){return!(this.dates>0)&&(this.dates++,this.y=e,this.m=t,this.d=s,!0)},time:function(e,t,s,r){return!(this.times>0)&&(this.times++,this.h=e,this.i=t,this.s=s,this.f=r,!0)},resetTime:function(){return this.h=0,this.i=0,this.s=0,this.f=0,this.times=0,!0},zone:function(e){return this.zones<=1&&(this.zones++,this.z=e,!0)},toDate:function(e){switch(this.dates&&!this.times&&(this.h=this.i=this.s=this.f=0),isNaN(this.y)&&(this.y=e.getFullYear()),isNaN(this.m)&&(this.m=e.getMonth()),isNaN(this.d)&&(this.d=e.getDate()),isNaN(this.h)&&(this.h=e.getHours()),isNaN(this.i)&&(this.i=e.getMinutes()),isNaN(this.s)&&(this.s=e.getSeconds()),isNaN(this.f)&&(this.f=e.getMilliseconds()),this.firstOrLastDayOfMonth){case 1:this.d=1;break;case-1:this.d=0,this.m+=1}if(!isNaN(this.weekday)){var t=new Date(e.getTime());t.setFullYear(this.y,this.m,this.d),t.setHours(this.h,this.i,this.s,this.f);var s=t.getDay();if(2===this.weekdayBehavior)0===s&&0!==this.weekday&&(this.weekday=-6),0===this.weekday&&0!==s&&(this.we