See More

!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).ExpressionEngine={})}(this,function(e){"use strict";class r{constructor(e,r){this.source=e,this.index=0,this.previousToken={type:"EOFToken",range:[0,0]},this.locale=r||p}toTokens(){var e=[];let r=this.nextToken();for(;"EOFToken"!==r.type;)e.push(r),r=this.nextToken();return e}nextToken(){var e;return this.index>=this.source.length?this.previousToken={type:"EOFToken",range:[this.source.length,this.source.length]}:" "===(e=this.source[this.index])?(this.index++,this.previousToken=this.nextToken()):'"'===e||"'"===e?this.previousToken=this.nextStringToken(e):"."===e?("."!==this.source[this.index+1]||"."!==this.source[this.index+2])&&("EOFToken"===this.previousToken.type||"PunctuatorToken"===this.previousToken.type&&t.includes(this.previousToken.value))?this.previousToken=this.nextNumericToken(!0):this.previousToken=this.nextPunctuator(e):"0"<=e&&e<="9"?this.previousToken=this.nextNumericToken(!1):n.includes(e)?this.previousToken=this.nextPunctuator(e):this.previousToken=this.nextIdentifierToken(),this.previousToken}nextPunctuator(e){var r=this.index;return">"===e||"<"===e||"="===e||"!"===e?"="===this.source[this.index+1]?"="!==e&&"!"!==e||"="!==this.source[this.index+2]?(e+="=",this.index++):(e+="==",this.index+=2):">"===e&&">"===this.source[this.index+1]?">"===this.source[this.index+2]?(e+=">>",this.index+=2):(e+=">",this.index++):"<"===e&&"<"===this.source[this.index+1]?(e+="<",this.index++):"="===e&&">"===this.source[this.index+1]&&(e+=">",this.index++):"&"!==e&&"|"!==e||this.source[this.index+1]!==e?"*"===e&&"*"===this.source[this.index+1]?(e+="*",this.index++):"?"!==e||"."!==this.source[this.index+1]&&"?"!==this.source[this.index+1]?"."===e&&"."===this.source[this.index+1]&&"."===this.source[this.index+1]?(e+="..",this.index+=2):"|"===e&&">"===this.source[this.index+1]&&(e+=">",this.index++):(e+=this.source[this.index+1],this.index++):(e+=e,this.index++),this.index++,{type:"PunctuatorToken",value:e,range:[r,this.index]}}nextIdentifierToken(){var e=this.findEndOfIdentifier();if(void 0===e){const r=[this.index,this.source.length],t=this.getExplicitIdentifierToken(this.source.substring(this.index),r);return this.index=this.source.length,t}const r=[this.index,e],t=this.getExplicitIdentifierToken(this.source.substring(this.index,e),r);return this.index=e,t}getExplicitIdentifierToken(e,r){return"true"===e||"false"===e?{type:"BooleanLiteral",value:"true"===e,range:r}:"this"===e?{type:"KeywordToken",name:e,range:r}:"null"===e?{type:"NullLiteral",range:r}:"and"===e?{type:"PunctuatorToken",value:"&&",range:r}:"or"===e?{type:"PunctuatorToken",value:"||",range:r}:"not"===e?{type:"PunctuatorToken",value:"!",range:r}:"await"===e?{type:"PunctuatorToken",value:e,range:r}:{type:"Identifier",name:e,range:r}}findEndOfIdentifier(){for(let e=this.index;e"0"<=e&&e<="9",i,a=this.index;for(let e=this.index+1;e"0"<=e&&e<="9"||"a"<=e&&e<="f":"b"===s||"B"===s?e=>"0"<=e&&e<="1":e=>"0"<=e&&e<="7"}const o=void 0===i?this.getNumber(this.index):i*10**this.getNumber(a);return this.index=this.source.length,{type:"NumericLiteral",value:o,range:[t,this.index]}}getNumber(e,r){return+Array.from(this.source.substring(e,r)).filter(e=>"_"!==e).join("")}nextStringToken(e){var r=this.index,t=(this.index++,this.findEndOfString(e));if(void 0===t)throw new k(x(this.locale.expect,e,r),[r,this.source.length]);e=this.source.substring(this.index,t);return this.index=t+1,{type:"StringLiteral",value:e,range:[r,this.index]}}findEndOfString(r){for(let e=this.index;e","<","=","!","&","^","|"],n=["(",")","[","]","{","}",...t,"?",":",",","~"];class i{constructor(e){this.locale=e||p}parseExpression(e,r,t){if(0===e.length)throw new k(this.locale.emptyExpression,[0,0]);if(1===e.length)return this.parseLiteral(e[0]);if(2===e.length)return this.parseUnaryExpression(e,null!=t?t:r);var n=e[0],i=e[e.length-1];if("PunctuatorToken"===n.type&&"{"===n.value&&"PunctuatorToken"===i.type&&"}"===i.value)return this.parseObjectLiteral(e,r);if(3===e.length){const[s,o,p]=e;if("PunctuatorToken"===o.type){if(g.includes(o.value))return this.parseMemberExpression(s,o,p,r);if("=>"===o.value)return{type:"ArrowFunctionExpression",params:"FunctionParamsExpression"===s.type?s.params:[s],body:p,range:r};if(f.some(e=>e.some(e=>e===o.value)))return this.parseBinaryExpression(s,o,p,r,t)}else if("PunctuatorToken"===p.type&&c.includes(p.value))return n=this.parseExpression([o,p],[o.range[0],r[1]]),this.parseExpression([s,n],r)}if(e.some(e=>"PunctuatorToken"===e.type&&"("===e.value)){i=this.parseGroup(e);if(i.length!==e.length)return this.parseExpression(i,l(e))}if(e.some(e=>"PunctuatorToken"===e.type&&"["===e.value)){t=this.parseArrayLiteral(e);if(t.length!==e.length)return this.parseExpression(t,l(e))}if(e.some(e=>"PunctuatorToken"===e.type&&(g.includes(e.value)||"("===e.value||"["===e.value)))return this.parseMemberOrCallExpression(e);n=this.getPostfixUnaryOperatorIndex(e);if(0<=n)return i=e[n-1],t=e[n],a=[i.range[0],t.range[1]],i=this.parseExpression([i,t],a),e.splice(n-1,2,i),this.parseExpression(e,r);var a,t=this.getPrefixUnaryOperatorIndex(e);if(0<=t)return a=e[t],n=e[t+1],i=[a.range[0],n.range[1]],a=this.parseExpression([a,n],i),e.splice(t,2,a),this.parseExpression(e,r);for(const u of f)if(e.some(e=>"PunctuatorToken"===e.type&&u.includes(e.value)))return this.parsePreviousExpression(e,u,r);if(5===e.length)return this.parseConditionalExpression(e,r);n=h(0,e);if(0<=n)return i=this.parseFunctionParameters(e.slice(0,n),[e[0].range[0],e[n-1].range[1]]),t=this.parseExpression(e.slice(n+1),[e[n+1].range[0],e[e.length-1].range[1]]),{type:"ArrowFunctionExpression",params:i.params,body:t,range:r};throw new k(x(this.locale.unexpectToken,r[0],r[1]),r)}parseObjectLiteral(r,e){var t=[];let n=[],i=[],a=!0;var s=(...e)=>{(a?n:i).push(...e)};for(let e=1;e"===r.value)return e+1}return-1}const f=[["**"],["*","/","%"],["+","-"],["<<",">>",">>>"],[">","<",">=","<="],["==","!=","===","!=="],["&&"],["&"],["^"],["|"],["||","??"],["|>"]],a=["+","-","!","~","await"],c=["%"],g=[".","?."],o={"{":"}","[":"]","(":")"},u=Object.keys(o);function s(e){return"EOFToken"===e.type||"PunctuatorToken"===e.type||"KeywordToken"===e.type}const p={multipleDecimalPoint:"Multiple decimal point: {0}",expect:"Expect {0}: {1}",unexpectToken:"Unexpected token: {0} {1}",expectUnaryOperator:"Expect unary operator: {0}",expectConditionalOperator:"Expect conditional operator: {0} {1}",invalidPropertyName:"Invalid property name: {0}",emptyExpression:"Empty expression",invalidFunctionParameter:"Invalid function parameter: {0}"};function y(e){return e||p}function x(r,...t){for(let e=0;e{let t;if(0===r.length)t=e;else{t={...e};for(let e=0;e"===e.operator&&r.greaterThan)return r.greaterThan(t);if("<="===e.operator&&r.lessThanOrEqual)return r.lessThanOrEqual(t);if(">"===e.operator&&r.greaterThanOrEqual)return r.greaterThanOrEqual(t)}if(i(t)){if("+"===e.operator&&t.added)return t.added(r);if("-"===e.operator&&t.subtracted)return t.subtracted(r);if("*"===e.operator&&t.multiplied)return t.multiplied(r);if("/"===e.operator&&t.divided)return t.divided(r);if("%"===e.operator&&t.remainered)return t.remainered(r);if("**"===e.operator&&t.powered)return t.powered(r);if(("=="===e.operator||"==="===e.operator)&&t.equal)return t.equal(r);if(("!="===e.operator||"!=="===e.operator)&&t.equal)return!t.equal(r);if("<"===e.operator&&t.greaterThanOrEqual)return t.greaterThanOrEqual(r);if(">"===e.operator&&t.lessThanOrEqual)return t.lessThanOrEqual(r);if("<="===e.operator&&t.greaterThan)return t.greaterThan(r);if(">="===e.operator&&t.lessThan)return t.lessThan(r)}}if("+"===e.operator){if("string"!=typeof r){if("number"!=typeof r||isNaN(r))throw new k(x(n.expect,"Number",e.left.range[0]),e.left.range);if("string"!=typeof t&&("number"!=typeof t||isNaN(t)))throw new k(x(n.expect,"Number",e.right.range[0]),e.right.range)}return r+t}if("=="===e.operator||"==="===e.operator||"!="===e.operator||"!=="===e.operator)return"=="===e.operator||"==="===e.operator?r===t:r!==t;if("string"==typeof r&&"string"==typeof t){if(">"===e.operator)return t="===e.operator)return t<=r;if("<"===e.operator)return r"===e.operator)return t(r);if("number"!=typeof r)throw new k(x(n.expect,"Number",e.left.range[0]),e.left.range);if("number"!=typeof t)throw new k(x(n.expect,"Number",e.right.range[0]),e.right.range);if("-"===e.operator)return r-t;if("*"===e.operator)return r*t;if("/"===e.operator)return r/t;if("%"===e.operator)return r%t;if(">"===e.operator)return t="===e.operator)return t<=r;if("<"===e.operator)return r>"===e.operator)return r>>t;if("<<"===e.operator)return r<>>"===e.operator)return r>>>t;if("&"===e.operator)return r&t;if("^"===e.operator)return r^t;if("|"===e.operator)return r|t;throw new k(n.unexpectToken,e.range)}function T(e,r,t){if("!"===e.operator)return!r;if("+"===e.operator&&("number"==typeof r||"string"==typeof r))return+r;if("number"!=typeof r||isNaN(r))throw new k(x(t.expect,"Number",e.argument.range[0]),e.argument.range);if("-"===e.operator)return-r;if("~"===e.operator)return~r;if("%"===e.operator)return r/100;if("await"===e.operator)return r;throw new k(t.unexpectToken,e.range)}class k extends Error{constructor(e,r){super(e),this.range=r}}e.ExpressionError=k,e.defaultLocale=p,e.evaluateExpression=function(e,r,t,n){return new(function r(e){if("NumericLiteral"===e.type)return!1;if("StringLiteral"===e.type)return!1;if("Identifier"===e.type)return!1;if("ThisExpression"===e.type)return!1;if("NullLiteral"===e.type)return!1;if("BooleanLiteral"===e.type)return!1;if("SpreadElement"===e.type||"RestElement"===e.type)return r(e.argument);if("AssignmentPattern"===e.type)return r(e.left)||r(e.right);if("ArrayExpression"===e.type)return e.elements.some(e=>r(e));if("ArrowFunctionExpression"===e.type)return e.params.some(e=>r(e))||r(e.body);if("UnaryExpression"===e.type)return"await"===e.operator||r(e.argument);if("BinaryExpression"===e.type||"LogicalExpression"===e.type)return r(e.left)||r(e.right);if("MemberExpression"===e.type)return r(e.object)||r(e.property);if("CallExpression"===e.type)return e.arguments.some(e=>r(e))||r(e.callee);if("ConditionalExpression"===e.type)return r(e.test)||r(e.consequent)||r(e.alternate);if("Property"===e.type)return r(e.key)||r(e.value);if("ObjectExpression"===e.type)return e.properties.some(e=>r(e));return e.params.some(e=>r(e))}(e)?v:d)(t,Array.isArray(n)?r=>n.some(e=>r instanceof e):n).evalutate(e,r,!0)},e.getLocale=y,e.parseExpression=function(e,r){return new i(r).parseExpression(e,l(e))},e.postfixUnaryOperators=c,e.printExpression=function(e,i){const a=(r,e=Number.MAX_SAFE_INTEGER)=>{var t,n;return"NumericLiteral"===r.type?r.value.toString():"StringLiteral"===r.type?`'${r.value}'`:"Identifier"===r.type?r.name:"ThisExpression"===r.type?"this":"NullLiteral"===r.type?"null":"BooleanLiteral"===r.type?r.value?"true":"false":"SpreadElement"===r.type||"RestElement"===r.type?"..."+a(r.argument):"AssignmentPattern"===r.type?a(r.left)+" = "+a(r.right):"ArrayExpression"===r.type?"["+r.elements.map(e=>a(e)).join(", ")+"]":"ArrowFunctionExpression"===r.type?(t=r.params.map(e=>a(e)).join(", "),n=a(r.body),1===r.params.length&&"Identifier"===r.params[0].type?t+" => "+n:`(${t}) => `+n):"UnaryExpression"===r.type?(t=a(r.argument,-1),c.includes(r.operator)?t+r.operator:"await"===r.operator?r.operator+" "+t:r.operator+t):"BinaryExpression"===r.type||"LogicalExpression"===r.type?(n=f.findIndex(e=>e.includes(r.operator)),t="+"===r.operator||"*"===r.operator?n:n-.1,t=a(r.left,n)+" "+r.operator+" "+a(r.right,t),ea(e)).join(", ")+")":a(r.callee)+"("+r.arguments.map(e=>a(e)).join(", ")+")":"ConditionalExpression"===r.type?a(r.test)+" ? "+a(r.consequent)+" : "+a(r.alternate):"Property"===r.type?r.shorthand?a(r.key):a(r.key)+": "+a(r.value):"ObjectExpression"===r.type?0===r.properties.length?"{}":"{ "+r.properties.map(e=>a(e)).join(", ")+" }":r.params.map(e=>a(e)).join(", ")};return a(e)},e.priorizedBinaryOperators=f,e.replaceLocaleParameters=x,e.tokenizeExpression=function(e){return new r(e).toTokens()}});