Equation.js/equation.min.js
Mahdi Dibaiee d360065e1b rebuild
2015-06-18 17:32:28 +04:30

1 line
8.0 KiB
JavaScript

!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.Equation=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){"use strict";Object.defineProperty(c,"__esModule",{value:!0}),c["default"]={PI:Math.PI,E:Math.E,RAND:Math.random},b.exports=c["default"]},{}],2:[function(a,b,c){"use strict";Object.defineProperty(c,"__esModule",{value:!0});var d=function(a){var b=a.split("1");return{left:b[0].length,right:b[1].length}};c.parseFormat=d;var e=function(a){return!isNaN(+a)};c.isNumber=e;var f=function(a){function b(b){return a.apply(this,arguments)}return b.toString=function(){return a.toString()},b}(function(a){return a.map(function(a){return e(a)?parseFloat(a):Array.isArray(a)?f(a):a})});c.parseNumbers=f;var g=function(a,b){for(var c=a,d=0;b>d;++d)c=c[c.length-1];return c};c.dive=g;var h=function(a){function b(b,c){return a.apply(this,arguments)}return b.toString=function(){return a.toString()},b}(function(a,b){var c=void 0===arguments[2]?0:arguments[2];if(2>b)return{arr:a,index:c};var d=a.reduce(function(a,d,e){if(Array.isArray(d)){var f=h(d,b-1,e),g=f.arr,i=f.index,j=a.concat(g);return c=i,j}return a},[]);return{arr:d,index:c}});c.deep=h;var i=function(a){function b(b,c,d){return a.apply(this,arguments)}return b.toString=function(){return a.toString()},b}(function(a,b,c){var d=[];if(!b.some(Array.isArray))return a[b[0]]=c,c;var e=!0,f=!1,g=void 0;try{for(var h,j=b[Symbol.iterator]();!(e=(h=j.next()).done);e=!0){var k=h.value;d.push(i(a,k,c))}}catch(l){f=!0,g=l}finally{try{!e&&j["return"]&&j["return"]()}finally{if(f)throw g}}return d});c.diveTo=i;var j=function(a){function b(b){return a.apply(this,arguments)}return b.toString=function(){return a.toString()},b}(function(a){return Array.isArray(a)&&a.some(Array.isArray)?a.reduce(function(a,b){return a.concat(j(b))},[]):a});c.flatten=j;var k=function(a){return a.toString().replace(/\W/g,"")};c.removeSymbols=k},{}],3:[function(a,b,c){"use strict";var d=function(a){return a&&a.__esModule?a:{"default":a}},e=function(a,b){if(Array.isArray(a))return a;if(Symbol.iterator in Object(a)){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!b||c.length!==b);d=!0);}catch(i){e=!0,f=i}finally{try{!d&&h["return"]&&h["return"]()}finally{if(e)throw f}}return c}throw new TypeError("Invalid attempt to destructure non-iterable instance")},f=function(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}return Array.from(a)};Object.defineProperty(c,"__esModule",{value:!0});var g=a("./readstream"),h=d(g),i=a("./operators"),j=d(i),k=a("./constants"),l=d(k),m=a("./helpers"),n=d(m),o={solve:function(a){a=z(a);var b=t(a);return b=w(b),b=n.parseNumbers(b),b=p(b)},equation:function(a){var b=t(a);console.log(b);var c=[];return b.forEach(function d(a){return Array.isArray(a)?a.forEach(d):void(B(a)&&c.push(n.removeSymbols(a)))}),function(){for(var a=arguments.length,d=Array(a),e=0;a>e;e++)d[e]=arguments[e];return b.forEach(function f(a,b,e){if(Array.isArray(a))return a.forEach(f);var g=c.indexOf(a);g>-1&&(e[b]=d[g])}),b=w(b),b=n.parseNumbers(b),b=p(b)}},registerOperator:function(a,b){j["default"][a]=b},registerConstant:function(a,b){l["default"][a]=b}},p=function(a){function b(b){return a.apply(this,arguments)}return b.toString=function(){return a.toString()},b}(function(a){return a.some(Array.isArray)?(a=a.map(function(a){return Array.isArray(a)?p(a):a}),p(a)):x(a)}),q=Object.keys(j["default"]).map(function(a){return j["default"][a].precedence}),r=Math.max.apply(Math,f(q)),s=Math.min.apply(Math,f(q)),t=function(a){for(var b=new h["default"](a),c=[],d="",e=void 0,f=void 0;b.next();)if(e=b.current(),f=c.length-1," "!==e)if(n.isNumber(e)||j["default"][e]||"."===e||"("===e||")"===e)if(d.length){var g=f-(d.length-1);B(d)&&n.isNumber(c[g])&&c.push("*"),c.push(d,e),d=""}else if(n.isNumber(c[f])&&(n.isNumber(e)||"."===e))c[f]+=e;else if("-"===c[f]){var i=c[f-1];j["default"][i]?c[f]+=e:")"===i?(c[f]="+",c.push("-"+e)):n.isNumber(i)?c.push(e):c[f]+=e}else c.push(e);else d+=e;if(d.length){var g=f-(d.length-1);B(d)&&n.isNumber(c[g])&&c.push("*"),c.push(d)}return u(c)},u=function(a){var b=0;return a.reduce(function(a,c){return c.indexOf("(")>-1?(c.length>1?n.dive(a,b).push(c.replace("(",""),[]):n.dive(a,b).push([]),b++):")"===c?b--:n.dive(a,b).push(c),a},[])},v=function(a){var b="string"==typeof a?j["default"][a]:a;if(!b)return null;var c=b.format.split("1"),d=c[0].length,e=c[1].length;return{left:d,right:e}},w=function(a){function b(b){return a.apply(this,arguments)}return b.toString=function(){return a.toString()},b}(function(a){var b=!0,c=!1,d=void 0;try{for(var f,g=a.entries()[Symbol.iterator]();!(b=(f=g.next()).done);b=!0){var h=e(f.value,2),i=h[0],k=h[1];Array.isArray(k)&&a.splice(i,1,w(k))}}catch(l){c=!0,d=l}finally{try{!b&&g["return"]&&g["return"]()}finally{if(c)throw d}}for(var m=s;r>=m;m++)for(var i=0;i<a.length;++i){var k=a[i],n=j["default"][k];if(n&&n.precedence===m){var o=v(n),p=o.left,q=o.right,t=a.splice(i-p,p+q+1,[]);a[i-p]=t;for(var u=0;m>u;u++)t=[t];i-=q}}return a}),x=function(a){var b,c=y(a);if(!c)return a[0];var d=v(c),e=d.left,g=a.slice(0,e),h=a.slice(e+1);return A((b=j["default"][c]).fn.apply(b,f(g).concat(f(h))))},y=function(a){var b=!0,c=!1,d=void 0;try{for(var e,f=a[Symbol.iterator]();!(b=(e=f.next()).done);b=!0){var g=e.value;if("string"==typeof g)return g}}catch(h){c=!0,d=h}finally{try{!b&&f["return"]&&f["return"]()}finally{if(c)throw d}}return null},z=function(a){return a.replace(/[A-Z]*/g,function(a){var b=l["default"][a];return b?"function"==typeof b?b():b:a})},A=function(a){return+a.toFixed(15)},B=function(a){return"string"==typeof a&&!n.isNumber(a)&&!j["default"][a]&&a===a.toLowerCase()};c.isVariable=B,c["default"]=o},{"./constants":1,"./helpers":2,"./operators":4,"./readstream":5}],4:[function(a,b,c){"use strict";Object.defineProperty(c,"__esModule",{value:!0}),c["default"]={"^":{fn:function(a,b){return Math.pow(a,b)},format:"010",precedence:0},"*":{fn:function(a,b){return a*b},format:"010",precedence:1},"/":{fn:function(a,b){return a/b},format:"010",precedence:1},"%":{fn:function(a,b){return a%b},format:"010",precedence:1},"\\":{fn:function(a,b){return Math.floor(a/b)},format:"010",precedence:1},"+":{fn:function(a,b){return a+b},format:"010",precedence:2},"-":{fn:function(a,b){return a-b},format:"010",precedence:2},"!":{fn:function(a){for(var b=1,c=0;a>c;++c)b*=c;return b},format:"01",precedence:2},log:{fn:Math.log,format:"10",precedence:-1},ln:{fn:Math.log,format:"10",precedence:-1},lg:{fn:function(a){return Math.log(a)/Math.log(2)},format:"10",precedence:-1},sin:{fn:Math.sin,format:"10",precedence:-1},cos:{fn:Math.cos,format:"10",precedence:-1},tan:{fn:Math.tan,format:"10",precedence:-1},cot:{fn:Math.cot,format:"10",precedence:-1},round:{fn:Math.round,format:"10",precedence:-1},floor:{fn:Math.floor,format:"10",precedence:-1}},b.exports=c["default"]},{}],5:[function(a,b,c){"use strict";Object.defineProperty(c,"__esModule",{value:!0}),c["default"]=function(a){var b=0,c=[];return{next:function(){return c.push(a[b]),b>=a.length?null:a[b++]},current:function(){return a[b-1]},index:function(){return b-1},to:function(c){var d="",e=b+c;for(b=b;e>b;++b)d+=[a[b]];return d},drain:function(){return c.splice(0,c.length)},replace:function(a){function b(b,c,d){return a.apply(this,arguments)}return b.toString=function(){return a.toString()},b}(function(c,d,e){var f=a.split("");f.splice(c,d,e),a=f.join(""),b-=d-c}),go:function(a){b+=a},all:function(){return a}}},b.exports=c["default"]},{}]},{},[3])(3)});