KitsuneOffline/gstatic/external_hosted/expr_eval/dist/bundle.min.js

27 lines
20 KiB
JavaScript
Raw Normal View History

2021-08-24 05:49:23 +00:00
/**
* @license
* The MIT License (MIT)
*
* Copyright (c) 2015 Matthew Crumley
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.exprEval=e()}(this,function(){"use strict";function t(t,e){this.type=t,this.value=void 0!==e&&null!==e?e:0}function e(e){return new t(Q,e)}function s(e){return new t(Y,e)}function r(e){return new t(Z,e)}function n(e,s,r,i,o){for(var a,h,p,u,c=[],l=[],f=0;f<e.length;f++){var v=e[f],x=v.type;if(x===K)c.push(v);else if(x===tt&&o.hasOwnProperty(v.value))v=new t(K,o[v.value]),c.push(v);else if(x===Y&&c.length>1)h=c.pop(),a=c.pop(),u=r[v.value],v=new t(K,u(a.value,h.value)),c.push(v);else if(x===Z&&c.length>2)p=c.pop(),h=c.pop(),a=c.pop(),"?"===v.value?c.push(a.value?h.value:p.value):(u=i[v.value],v=new t(K,u(a.value,h.value,p.value)),c.push(v));else if(x===Q&&c.length>0)a=c.pop(),u=s[v.value],v=new t(K,u(a.value)),c.push(v);else if(x===st){for(;c.length>0;)l.push(c.shift());l.push(new t(st,n(v.value,s,r,i,o)))}else if(x===rt&&c.length>0)a=c.pop(),c.push(new t(K,a.value[v.value]));else{for(;c.length>0;)l.push(c.shift());l.push(v)}}for(;c.length>0;)l.push(c.shift());return l}function i(n,o,a){for(var h=[],p=0;p<n.length;p++){var u=n[p],c=u.type;if(c===tt&&u.value===o)for(var l=0;l<a.tokens.length;l++){var f,v=a.tokens[l];f=v.type===Q?e(v.value):v.type===Y?s(v.value):v.type===Z?r(v.value):new t(v.type,v.value),h.push(f)}else c===st?h.push(new t(st,i(u.value,o,a))):h.push(u)}return h}function o(t,e,s){for(var r,n,i,a,h=[],p=0;p<t.length;p++){var u=t[p],c=u.type;if(c===K)h.push(u.value);else if(c===Y)n=h.pop(),r=h.pop(),a=e.binaryOps[u.value],h.push(a(r,n));else if(c===Z)i=h.pop(),n=h.pop(),r=h.pop(),"?"===u.value?h.push(o(r?n:i,e,s)):(a=e.ternaryOps[u.value],h.push(a(r,n,i)));else if(c===tt)if(u.value in e.functions)h.push(e.functions[u.value]);else{var l=s[u.value];if(void 0===l)throw new Error("undefined variable: "+u.value);h.push(l)}else if(c===Q)r=h.pop(),a=e.unaryOps[u.value],h.push(a(r));else if(c===et){for(var f=u.value,v=[];f-- >0;)v.unshift(h.pop());if(!(a=h.pop()).apply||!a.call)throw new Error(a+" is not a function");h.push(a.apply(void 0,v))}else if(c===st)h.push(u.value);else{if(c!==rt)throw new Error("invalid Expression");r=h.pop(),h.push(r[u.value])}}if(h.length>1)throw new Error("invalid Expression (parity)");return h[0]}function a(t,e){for(var s,r,n,i,o=[],p=0;p<t.length;p++){var u=t[p],c=u.type;if(c===K)"number"==typeof u.value&&u.value<0?o.push("("+u.value+")"):o.push(h(u.value));else if(c===Y)r=o.pop(),s=o.pop(),i=u.value,e?"^"===i?o.push("Math.pow("+s+", "+r+")"):"and"===i?o.push("(!!"+s+" && !!"+r+")"):"or"===i?o.push("(!!"+s+" || !!"+r+")"):"||"===i?o.push("(String("+s+") + String("+r+"))"):"=="===i?o.push("("+s+" === "+r+")"):"!="===i?o.push("("+s+" !== "+r+")"):o.push("("+s+" "+i+" "+r+")"):o.push("("+s+" "+i+" "+r+")");else if(c===Z){if(n=o.pop(),r=o.pop(),s=o.pop(),"?"!==(i=u.value))throw new Error("invalid Expression");o.push("("+s+" ? "+r+" : "+n+")")}else if(c===tt)o.push(u.value);else if(c===Q)s=o.pop(),"-"===(i=u.value)||"+"===i?o.push("("+i+s+")"):e?"not"===i?o.push("(!"+s+")"):"!"===i?o.push("fac("+s+")"):o.push(i+"("+s+")"):"!"===i?o.push("("+s+"!)"):o.push("("+i+" "+s+")");else if(c===et){for(var l=u.value,f=[];l-- >0;)f.unshift(o.pop());i=o.pop(),o.push(i+"("+f.join(", ")+")")}else if(c===rt)s=o.pop(),o.push(s+"."+u.value);else{if(c!==st)throw new Error("invalid Expression");o.push("("+a(u.value,e)+")")}}if(o.length>1)throw new Error("invalid Expression (parity)");return String(o[0])}function h(t){return"string"==typeof t?JSON.stringify(t).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029"):t}function p(t,e){for(var s=0;s<t.length;s++)if(t[s]===e)return!0;return!1}function u(t,e,s){for(var r=!!(s=s||{}).withMembers,n=null,i=0;i<t.length;i++){var o=t[i];o.type!==tt||p(e,o.value)?o.type===rt&&r&&null!==n?n+="."+o.value:o.type===st?u(o.value,e,s):null!==n&&(p(e,n)||e.push(n),n=null):r?null!==n?(p(e,n)||e.push(n),n=o.value):n=o.value:e.push(o.value)}null===n||p(e,n)||e.push(n)}function c(t,e){this.tokens=t,this.parser=e,this.unaryOps=e.unaryOps,this.binar