Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fparser

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fparser - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

8

examples/node-example.js

@@ -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:

2

package.json
{
"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']
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc