<script type="module">
import buildoutHotFormulaParser from 'https://cdn.skypack.dev/@buildout/hot-formula-parser';
</script>
README
formula-parser fork for ShadowGrid
Local development
When opening a pull request, please do not submit version changes or changes to build output in dist.
Publishing
yarn upgrade @buildout/formulajs
yarn build
Bump the version number in package.json per semver
Commit both changes to master in a Version <version number> commit
Tag the commit with the version number and push it
npm publish
TODO
Avoid relative paths
For example, it is would be nice to be able to import test/helpers/formulas.js with require(~formulas).
This would look something like the following in the Jest config in package.json, but it isn't working for some reason:
"moduleNameMapper": {
"~(.*)
quot;: "<rootDir>/test/helpers/$1"
}
Original readme:
Formula Parser
Library provides a Parser class that evaluates excel and mathematical formulas.
Install
A recommended way to install Formula Parser is through NPM using the following command:
$ npm install hot-formula-parser --save
Node.js:
var FormulaParser = require('hot-formula-parser').Parser;
var parser = new FormulaParser();
parser.parse('SUM(1, 6, 7)'); // It returns `Object {error: null, result: 14}`
Browser:
<script src="/node_modules/hot-formula-parser/dist/formula-parser.min.js"></script>
<script>
var parser = new formulaParser.Parser();
parser.parse('SUM(1, 6, 7)'); // It returns `Object {error: null, result: 14}`
</script>
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 (methods)
var parser = new formulaParser.Parser();
.parse(expression)
Parses and evaluates provided expression. It always returns an object with result and error properties. result property
always keep evaluated value. If error occurs error property will be set as:
#ERROR! General error;
#DIV/0! Divide by zero error;
#NAME? Not recognised function name or variable name;
#N/A Indicates that a value is not available to a formula;
#NUM! Occurs when formula encounters an invalid number;
#VALUE! Occurs when one of formula arguments is of the wrong type.
Fired while calling function. If function was defined earlier using setFunction you can overwrite it's result by this hook.
You can also use this to override result of build-in formulas.