fxparser
Version:
Formula parser designed for Yotta Needs.
74 lines (44 loc) • 1.46 kB
Markdown
# F(x) parser
Library provides a `Parser` class that evaluates excel and mathematical formulas.
1. [Installation](#installation)
2. [Implementation](#prompt-customization)
1. [Html](#html)
2. [js](#js)
3. [Features](#features)
4. [API](#api)
### Installation
```sh
$ npm install fxparser --save
```
### Implementation
### Html
```html
<script src="/node_modules/fx-parser/dist/fxparser.min.js"></script>
var parser = new fxParser.Parser();
parser.parse('SUM(1, 3, 9)');
// It returns `Object {error: null, result: 13}`
```
### js
```js
var FxParser = require('fxparser').Parser;
var parser = new FxParser();
parser.parse('SUM(1, 3, 9)');
// It returns `Object {error: null, result: 13}`
```
### Features
It supports:
* Any numbers, negative and positive as float or integer;
* Arithmetic operations like `+`, `-`, `/`, `*`, `%`, `^`;
* Logical operations like `AND()`, `OR()`, `NOT()`, `XOR()`;
* Comparison operations like `=`, `>`, `>=`, `<`, `<=`, `<>`;
* All JavaScript Math constants like `PI()`, `E()`, `LN10()`, `LN2()`, `LOG10E()`, `LOG2E()`, `SQRT1_2()`, `SQRT2()`;
* String operations like `&` (concatenation eq. `parser.parse('-(2&5)');` will return `-25`);
* Relative and absolute cell coordinates like `A1`, `$A1`, `A$1`, `$A$1`;
* Build-in variables like `TRUE`, `FALSE`, `NULL`
* Custom variables;
* Custom functions/formulas;
* Node and Browser environment.
### API
```sh
$ node runthistest.js
```