https://github.com/kdinev/epsilonjs
A JavaScript calculator and an expression parser.
https://github.com/kdinev/epsilonjs
calculator expression-evaluator expression-parser javascript typescript
Last synced: 10 months ago
JSON representation
A JavaScript calculator and an expression parser.
- Host: GitHub
- URL: https://github.com/kdinev/epsilonjs
- Owner: kdinev
- License: mit
- Created: 2014-02-17T23:02:03.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2022-04-20T06:35:10.000Z (almost 4 years ago)
- Last Synced: 2025-03-18T19:05:48.534Z (11 months ago)
- Topics: calculator, expression-evaluator, expression-parser, javascript, typescript
- Language: JavaScript
- Homepage: http://kdinev.github.io/EpsilonJS
- Size: 144 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
EpsilonJS
=========
[](https://www.codacy.com/public/kdinev/EpsilonJS) [](https://travis-ci.org/kdinev/EpsilonJS)
EpsilonJS us a JavaScript calculator and an expression parser. The framework allows for parsing mathematical expressions from string or from DOM attributes. It also allows evaluation of mathematical expressions as part of DOM attributes which reference other DOM elements.
You can get EpsilonJS through Bower:
bower install epsilonjs
How to build EpsilonJS
=========
Clone the repo:
git clone https://github.com/kdinev/EpsilonJS.git
Go to the EpsilonJS folder and install dependencies:
cd epsilonjs
npm install
Build:
grunt default
Description
=========
Parses and evaluates mathematical expressions. The expression is provided to the expression parser as a string.
var expr = "1/(2+8)*2",
parser = new Epsilon.ExpressionParser(expr);
parser.evaluate(); // Yeilds 0.2 as a number type
Supported operators:
* Addition (+)
* Subtraction (-)
* Multiplication (*)
* Division (/)
* Negative values (-)
* Brackets (())
The epsilon expression parser handles DOM formula references as well. The epsilon expression parser will evaluate all elements containing a `data-formula` attribute. In order to get the DOM evaluated the `Epsilon.epsilon()` method needs to be called after loading the DOM. The references need to be like excel cells (e.g. `A10`, `C2`) and will be looked-up by `id` and by `data-formula-ref` attribute if not found by `id`. The referenced elements can contain and formula and epsilon will evaluate them according to their `data-formula`. Circular references are not handled at this point and will result in out of stack space exception.
Example:
- 10
-
Epsilon.epsilon();
The result will be:
* 10
* 20
Epsilon can evaluate only specific DOM elements as well and can be invoked at any point for those elements. If the reference elements contain formulas, then their formulas will be evaluated as part of the requested element's formula but their DOM values will not be changed.
Example:
- 10
-
-
Epsilon.epsilon(document.getElementById("A3"));
The result will be:
* 10
*
* 25
======
There is also a jQuery UI epsilon calculator widget provided by [https://github.com/kdinev/calculatorjs](https://github.com/kdinev/calculatorjs). This widget was created to test the epsilon expression parser. The calculator widget is dependent on jQuery and jQuery UI. In order to use it:
$(document).ready(function () {
$("#calculator").calculator();
});
The calculator widget is used in a Windows 8.1 store application which you may download and play with here: [http://apps.microsoft.com/windows/app/epsilon-calculator/ec41ebdd-00c6-4654-a2a2-b297a0118a87](http://apps.microsoft.com/windows/app/epsilon-calculator/ec41ebdd-00c6-4654-a2a2-b297a0118a87)