https://github.com/malikzh/computejs
An expression calculator library for JavaScript
https://github.com/malikzh/computejs
calculator compute computejs expression formula function javascript js lexer library math parser secure
Last synced: 4 days ago
JSON representation
An expression calculator library for JavaScript
- Host: GitHub
- URL: https://github.com/malikzh/computejs
- Owner: malikzh
- License: mit
- Created: 2019-06-28T13:34:00.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-15T19:43:06.000Z (almost 6 years ago)
- Last Synced: 2025-03-03T11:16:55.038Z (over 1 year ago)
- Topics: calculator, compute, computejs, expression, formula, function, javascript, js, lexer, library, math, parser, secure
- Language: JavaScript
- Homepage: https://github.com/malikzh/computejs
- Size: 10.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Compute.js
An expression calculator for JavaScript
## Features
- Basic math operators:
- `+` - Addition
- `-` - Subtraction
- `*` - Multltiplication
- `/` - Division
- `^` - Power (right associative)
- `%` - Modulo division
- Brackets support
- Operators precedence support
- Custom functions support
- Function recursion support
- Variables support
- Unary operators support
## Demo
You can try it [on JSFiddle](https://jsfiddle.net/malikzh/bLgsv3uz/)
## How it use
Just call a function:
```js
Compute(expression, functions, variables);
```
### Simple usage
```js
let result = Compute('5 * (3 + 4) + 3');
console.log(result); // displays 38
```
### Functions call
```js
let result = Compute('10 + dist(5, dist(3, 4))', {
dist: function (args) {
return (args[0] ** 2) + (args[1] ** 2);
}
});
console.log(result); // displays 660
```
### Variables support
```
let result = Compute('myvar ^ 2', {}, {
myvar: 32
});
console.log(result); // displays 1024
```
## License
This project licensed with [MIT](LICENSE) license
---
Made with ❤️