https://github.com/lochungtin/node-exp-solver
Mathematical expression solver / Reverse Polish Notation calculator for NodeJS
https://github.com/lochungtin/node-exp-solver
equation-solver nodejs rpn rpn-calculator rpn-expression
Last synced: 3 months ago
JSON representation
Mathematical expression solver / Reverse Polish Notation calculator for NodeJS
- Host: GitHub
- URL: https://github.com/lochungtin/node-exp-solver
- Owner: lochungtin
- License: mit
- Created: 2021-07-05T22:51:21.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-01T20:58:17.000Z (over 2 years ago)
- Last Synced: 2025-08-08T15:54:41.692Z (11 months ago)
- Topics: equation-solver, nodejs, rpn, rpn-calculator, rpn-expression
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@enigmaoffline/node-exp-solver
- Size: 15.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Node Expression Solver
Mathematical expression solver / Reverse Polish Notation calculator for NodeJS
**Features**
- Solve infix-notated mathematical expressions
- Solve RPN expressions
- Converts infix-notated expressions to RPN
- Tokenize infix-notated expressions
- From string to array
- Able to handle negative numbers
- Spacing independent
## Install
With NPM:
```
npm install --save @enigmaoffline/node-exp-solver
```
## Usage
```js
const Solver = require('@enigmaoffline/node-exp-solver');
// Tokenization
console.log(Solver.tokenize('-1+2*(3-4)/5+(-6+-7)'));
// => [ '-1', '+', '2', '*', '(', '3', '-', '4', ')', '/', '5', '+', '(', '-6', '+', '-7', ')' ]
console.log(Solver.tokenize('1*2^3+3'));
// => [ '1', '*', '2', '^', '3', '+', '3' ]
// Infix to RPN
console.log(Solver.toRPN(Solver.tokenize('1+2*3')));
// => [ '1', '2', '3', '*', '+' ]
// Basic Solve
console.log(Solver.solve(Solver.tokenize('1+2*3')));
// => 7
// Solve RPN
console.log(Solver.solveRPN(Solver.toRPN(Solver.tokenize('-2+3^2+1'))));
// => 8
```
## Next Steps
1. Ability to handle Min / Max functions
2. Ability to handle trig functions
3. Ability to handle log functions