math-expression-evaluator
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -0,1 +1,4 @@ | ||
/** math-expression-evaluator version 1.0.2 | ||
Dated:2015-07-16 */ | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.mexp = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
@@ -2,0 +5,0 @@ |
@@ -1,2 +0,26 @@ | ||
/*! math-expression-evaluator 2015-07-16 */ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) Ankit G. | ||
* | ||
* 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:</p> | ||
* | ||
* 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. | ||
*/ | ||
/** math-expression-evaluator version 1.0.2 | ||
Dated:2015-07-16 */ | ||
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.mexp=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){function d(a,b){for(var c=0;c<a.length;c++)a[c]+=b;return a}function e(a,b,c,d){for(var e=0;d>e;e++)if(a[c+e]!==b[e])return!1;return!0}var f=a("./math_function.js"),g=["sin","cos","tan","pi","(",")","Del","P","C","asin","acos","atan","7","8","9","int","cosh","acosh","ln","^","root","4","5","6","/","!","tanh","atanh","Mod","1","2","3","*","=","sinh","asinh","e","log","10^x","0",".","+","-",",","Sigma","n","Pi","pow"],h=["sin(","cos(","tan(","π","(",")","Del","P","C","asin(","acos(","atan(","7","8","9","Int(","cosh(","acosh("," ln(","^","root(","4","5","6","÷","!","tanh(","atanh("," Mod ","1","2","3","×","=","sinh(","asinh(","e"," log("," 10^(","0",".","+","-",",","Σ","n","Π","pow("],j=[f.math.sin,f.math.cos,f.math.tan,"PI","(",")","Del",f.math.P,f.math.C,f.math.asin,f.math.acos,f.math.atan,"7","8","9",Math.floor,f.math.cosh,f.math.acosh,Math.log,Math.pow,Math.pow,"4","5","6",f.math.div,f.math.fact,f.math.tanh,f.math.atanh,f.math.mod,"1","2","3",f.math.mul,"=",f.math.sinh,f.math.asinh,"E",f.math.log,f.math.pow10x,"0",".",f.math.add,f.math.sub,",",f.math.sigma,"n",f.math.Pi,Math.pow],k=[11,11,11,0,0,0,0,7,7,11,11,10,0,0,0,11,11,11,10,10,11,0,0,0,3,11,11,11,10,0,0,0,3,0,11,11,0,11,11,0,0,1,1,0,11,0,11,11],l=[0,0,0,3,4,5,12,11,11,0,0,0,1,1,1,0,0,0,0,11,11,1,1,1,2,7,0,0,2,1,1,1,2,13,0,0,3,0,0,1,6,9,9,21,22,23,22,8],m={0:!0,1:!0,3:!0,4:!0,6:!0,8:!0,9:!0,17:!0,22:!0,23:!0},n={0:!0,1:!0,2:!0,3:!0,4:!0,5:!0,6:!0,7:!0,8:!0,9:!0,10:!0,11:!0,13:!0,17:!0,21:!0,22:!0,23:!0},o={0:!0,3:!0,4:!0,8:!0,17:!0,22:!0,23:!0},p={},q={0:!0,1:!0,3:!0,4:!0,6:!0,8:!0,17:!0,22:!0,23:!0},r={1:!0},s=[[],["1","2","3","7","8","9","4","5","6","+","-","*","/","(",")","^","!","P","C","=","e","0",".",",","n"],["pi","ln","Pi"],["Ans","sin","cos","tan","Del","int","Mod","log","pow"],["asin","acos","atan","cosh","root","tanh","sinh","10^x"],["acosh","atanh","asinh","Sigma"]];f.addToken=function(a){a:for(i=0;i<a.length;i++){if(x=a[i].token.length,x<s.length)for(y=0;y<s[x].length;y++)if(a[i].token===s[x][y])continue a;g.push(a[i].token),l.push(a[i].type),s.length<=a[i].token.length&&(s[a[i].token.length]=[]),s[a[i].token.length].push(a[i].token),j.push(a[i].ev),k.push(a[i].preced),h.push(a[i].show)}},f.lex=function(a,b){"use strict";var c,i,t,u=[{type:4,value:"(",show:"(",pre:0}],v=[],w=a,x="",y=m,z=0,A=p,B="";"undefined"!=typeof b&&f.addToken(b);var C={};for(c=0;c<w.length;c++)if(" "!=w[c]){a:for(i=w.length-c>s.length-2?s.length-1:w.length-c;i>0;i--)for(t=0;t<s[i].length;t++)if(e(w,s[i][t],c,i)){x=s[i][t];break a}if(c+=x.length-1,""===x)return void console.error("Can't understand after "+w.slice(c));var D=g.indexOf(x),E=l[D],F=j[D],G=k[D],H=h[D],I=u[u.length-1];if(y[E]!==!0)return void console.error(x+" is not allowed after "+B);for(A[E]===!0&&(E=2,F=f.math.mul,H="×",G=3,c-=x.length),J=0;J<v.length;J++)0===v[J]&&-1!==[0,2,3,5,9,21,22,23].indexOf(E)&&(u.push({value:")",type:5,pre:3}),y=n,A=q,d(v,-1).splice(J,1),J=-1);if(C={value:F,type:E,pre:G,show:H},0===E)y=m,A=p,d(v,2).push(2),u.push(C),u.push({value:"(",type:4,pre:0,show:"("});else if(1===E)1===I.type?(I.value+=F,d(v,1)):u.push(C),y=n,A=o;else if(2===E)y=m,A=p,d(v,2),u.push(C);else if(3===E)u.push(C),y=n,A=q;else if(4===E){if(-1!=v.indexOf(1)&&4===I.type){v.splice(v.indexOf(1),1),z++;continue}d(v,2),z++,y=m,A=p,u.push(C)}else if(5===E){if(!z)return;z--,y=n,A=q,u.push(C)}else if(6===E){if(I.hasDec)return void console.error("Two decimals are not allowed in one number");1!=I.type&&(u.push({value:0,type:1,pre:0}),d(v,-1)),y=r,d(v,2),A=p,I.value+=F,I.hasDec=!0}else 7===E&&(y=n,A=q,d(v,1),u.push(C));8===E?(y=m,A=p,d(v,4).push(4),u.push(C),u.push({value:"(",type:4,pre:0,show:"("})):9===E?(9===I.type?"+"===I.value?(I.value=F,I.show=H,d(v,1)):"-"===I.value&&"-"===H&&(I.value="+",I.show="+",d(v,1)):5!==I.type&&7!==I.type&&1!==I.type&&3!==I.type&&23!==I.type?(u.push({value:f.changeSigna,type:0,pre:21,show:"-"}),d(v,1)):(u.push(C),d(v,2)),y=m,A=p):11===E?(y=m,A=p,d(v,2),u.push(C)):21===E?(y=m,A=p,u.push(C)):22===E?(y=m,A=p,d(v,6).push(6),u.push(C),u.push({value:"(",type:4,pre:0})):23===E&&(y=n,A=q,u.push(C)),d(v,-1),B=x}for(var J=0;J<v.length;J++)0===v[J]&&(u.push({value:")",type:5,pre:3}),d(v,-1).pop(J),J--);return u.push({type:5,value:")",show:")",pre:0}),new f(u)},b.exports=f},{"./math_function.js":2}],2:[function(a,b,c){var d=function(a){"use strict";this.value=a};d.math={isDegree:!1,acos:function(a){return d.isDegree?180/Math.PI*Math.acos(a):Math.acos(a)},add:function(a,b){return a+b},asin:function(a){return d.isDegree?180/Math.PI*Math.asin(a):Math.asin(a)},atan:function(a){return d.isDegree?180/Math.PI*Math.atan(a):Math.atan(a)},acosh:function(a){return Math.log(a+Math.sqrt(a*a-1))},asinh:function(a){return Math.log(a+Math.sqrt(a*a+1))},atanh:function(a){return Math.log((1+a)/(1-a))},C:function(a,b){var c=1,e=a-b,f=b;e>f&&(f=e,e=b);for(var g=f+1;a>=g;g++)c*=g;return c/d.fact(e)},changeSign:function(a){return-a},cos:function(a){return d.isDegree&&(a=d.math.toRadian(a)),Math.cos(a)},cosh:function(a){return(Math.pow(Math.E,a)+Math.pow(Math.E,-1*a))/2},div:function(a,b){return a/b},fact:function(a){if(a%1!==0)return"NAN";for(var b=1,c=2;a>=c;c++)b*=c;return b},inverse:function(a){return 1/a},log:function(a){return Math.log(a)/Math.log(10)},mod:function(a,b){return a%b},mul:function(a,b){return a*b},P:function(a,b){for(var c=1,d=Math.floor(a)-Math.floor(b)+1;d<=Math.floor(a);d++)c*=d;return c},Pi:function(a,b,c){for(var d=1,e=a;b>=e;e++)d*=c.postfixEval({n:e});return d},pow10x:function(a){for(var b=1;a--;)b*=10;return b},sigma:function(a,b,c){for(var d=0,e=a;b>=e;e++)d+=Number(c.postfixEval({n:e}));return d},sin:function(a){return d.isDegree&&(a=d.math.toRadian(a)),Math.sin(a)},sinh:function(a){return(Math.pow(Math.E,a)-Math.pow(Math.E,-1*a))/2},sub:function(a,b){return a-b},tan:function(a){return d.isDegree&&(a=d.math.toRadian(a)),Math.tan(a)},tanh:function(a){return d.sinha(a)/d.cosha(a)},toRadian:function(a){return a*Math.PI/180}},b.exports=d},{}],3:[function(a,b,c){var d=a("./lexer.js");Array.indexOf||(Array.prototype.indexOf=function(a){for(var b=0;b<this.length;b++)if(a==this[b])return b;return-1}),d.prototype.toPostfix=function(){"use strict";for(var a,b,c,e,f,g=[],h=[{value:"(",type:4,pre:0}],i=this.value,j=1;j<i.length;j++)if(1===i[j].type||3===i[j].type||23===i[j].type)1===i[j].type&&(i[j].value=Number(i[j].value)),g.push(i[j]);else if(4===i[j].type)h.push(i[j]);else if(5===i[j].type)for(;4!==(b=h.pop()).type;)g.push(b);else if(21===i[j].type){for(;4!==(b=h.pop()).type;)g.push(b);h.push(b)}else{a=i[j],e=a.pre,f=h[h.length-1],c=f.pre;var k="Math.pow"==f.value&&"Math.pow"==a.value;if(e>c)h.push(a);else{for(;c>=e&&!k||k&&c>e;)b=h.pop(),f=h[h.length-1],g.push(b),c=f.pre,k="Math.pow"==a.value&&"Math.pow"==f.value;h.push(a)}}return new d(g)},b.exports=d},{"./lexer.js":1}],4:[function(a,b,c){var d=a("./postfix.js");d.prototype.postfixEval=function(a){"use strict";a=a||{},a.PI=Math.PI,a.E=Math.E;for(var b,c,e,f=[],g=this.value,h="undefined"!=typeof a.n,i=0;i<g.length;i++)1===g[i].type?f.push({value:g[i].value,type:1}):3===g[i].type?f.push({value:a[g[i].value],type:1}):0===g[i].type?"undefined"==typeof f[f.length-1].type?f[f.length-1].push(g[i]):f[f.length-1].value=g[i].value(f[f.length-1].value):7===g[i].type?"undefined"==typeof f[f.length-1].type?f[f.length-1].push(g[i]):f[f.length-1].value=g[i].value(f[f.length-1].value):8===g[i].type?(b=f.pop(),c=f.pop(),f.push({type:1,value:g[i].value(c.value,b.value)})):11===g[i].type?(b=f.pop(),c=f.pop(),"undefined"==typeof b.type||"undefined"==typeof c.type?(c=c.concat(b),c.push(g[i]),f.push(c)):f.push({type:1,value:g[i].value(c.value,b.value)})):2===g[i].type||9===g[i].type?(b=f.pop(),c=f.pop(),"undefined"==typeof b.type||"undefined"==typeof c.type?(c=c.concat(b),c.push(g[i]),f.push(c)):f.push({type:1,value:g[i].value(c.value,b.value)})):22===g[i].type?(b=f.pop(),c=f.pop(),e=f.pop(),f.push({type:1,value:g[i].value(e.value,c.value,new d(b))})):23===g[i].type&&(h?f.push({value:a[g[i].value],type:3}):f.push([g[i]]));return f[0].value>1e15?"Infinity":Number(f[0].value.toFixed(15)).toPrecision()},b.exports=d},{"./postfix.js":3}]},{},[4])(4)}); |
{ | ||
"name": "math-expression-evaluator", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A flexible math expression evaluator", | ||
@@ -5,0 +5,0 @@ "main": "src/postfix_evaluator.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44453
1148