Comparing version 1.2.0 to 1.2.1
@@ -35,2 +35,3 @@ var Formula = require('../fparser.js'); | ||
var f3 = new Formula('max(x,y)'); | ||
var res3 = f3.evaluate([ | ||
@@ -44,2 +45,7 @@ {x: 1, y: 2 }, | ||
); | ||
console.log(res3); | ||
console.log(res3); | ||
// Get all used variables: | ||
var f4 = new Formula('x*sin(PI*y) + y / (2-x*a) + z'); | ||
console.log(f4.getVariables()); |
@@ -25,4 +25,6 @@ /** | ||
*/ | ||
var Formula = function(fStr) { | ||
var Formula = function(fStr, topFormula) { | ||
this.formulaExpression = null; | ||
this.variables = []; | ||
this.topFormula = topFormula || null; | ||
@@ -157,2 +159,7 @@ this.formulaStr = fStr; | ||
expressions.push(this.createVariableEvaluator(char)); | ||
if (this.topFormula instanceof Formula) { | ||
this.topFormula.registerVariable(char); | ||
} else { | ||
this.registerVariable(char); | ||
} | ||
state = 0; | ||
@@ -206,3 +213,3 @@ tmp = ''; | ||
expressions.push(new Formula(tmp)); | ||
expressions.push(new Formula(tmp,this)); | ||
} else if (state === 'within-func-parentheses') { | ||
@@ -237,3 +244,17 @@ // Function found: return a function that, | ||
Formula.prototype.registerVariable = function(varName) { | ||
if (this.variables.indexOf(varName) < 0) { | ||
this.variables.push(varName); | ||
} | ||
}; | ||
Formula.prototype.getVariables = function() { | ||
if (this.topFormula instanceof Formula) { | ||
return this.topFormula.variables; | ||
} else { | ||
return this.variables; | ||
} | ||
}; | ||
/** | ||
@@ -378,3 +399,3 @@ * here we do 3 steps: | ||
for (var i = 0; i < args.length; i++) { | ||
args[i] = new Formula(args[i]); | ||
args[i] = new Formula(args[i],me); | ||
} | ||
@@ -381,0 +402,0 @@ // Args now is an array of function expressions: |
{ | ||
"name": "fparser", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "A Math Formula parser library for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "fparser.js", |
@@ -92,1 +92,6 @@ fparse | ||
### Get all used variables | ||
```javascript | ||
// Get all used variables in the order of their appereance: | ||
var f4 = new Formula('x*sin(PI*y) + y / (2-x*a) + z'); | ||
console.log(f4.getVariables()); // ['x','y','a','z'] |
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
18277
480
97