https://github.com/negrel/mep
:heavy_division_sign: - MEP is a mathematical expression parser written in TypeScript
https://github.com/negrel/mep
expression-parser javascript math typescript
Last synced: 3 months ago
JSON representation
:heavy_division_sign: - MEP is a mathematical expression parser written in TypeScript
- Host: GitHub
- URL: https://github.com/negrel/mep
- Owner: negrel
- License: mit
- Created: 2021-01-07T19:20:16.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-11-07T19:27:41.000Z (over 1 year ago)
- Last Synced: 2025-02-08T22:04:30.998Z (4 months ago)
- Topics: expression-parser, javascript, math, typescript
- Language: TypeScript
- Homepage:
- Size: 672 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# :heavy_division_sign: - MEP is a dependency free mathematical expression parser written in TypeScript.
## Why ?
I needed an **extensible** mathematical expression parser for
[1Calc](https://github.com/OG-Suite/1calc)This package does the following:
- Lex mathematical expressions with **custom** operations, constants and
functions into tokens
- Parse tokens and return an
[RPN](https://en.wikipedia.org/wiki/Reverse_Polish_notation) array of
`numbers` / `Operation`.
- Compute an [RPN](https://en.wikipedia.org/wiki/Reverse_Polish_notation) array
and return the result## Installation
Using ES modules:
```js
import * mep from "https://deno.land/x/[email protected]/mod.ts";
```Using npm:
```shell
$ npm install @negrel/mep
```You can now import `mep` as an ES modules or a CommonJS module.
## Exemple
```js
import { compute, registerConstant } from "@negrel/mep";
// or
// const { compute, registerConstant } = require('@negrel/mep')console.log("Result:", compute("log2(5 * 65 + cos(PI ^ 2))"));
// Result: 8.340283256791498registerConstant("PI2", Math.PI ** 2);
console.log("Result:", compute("log2(5 * 65 + cos(PI2))"));
// Result: 8.340283256791498
```### Contributing
If you want to contribute to MEP to add a feature or improve the code contact me
at [[email protected]](mailto:[email protected]), open an
[issue](https://github.com/negrel/MEP/issues) or make a
[pull request](https://github.com/negrel/MEP/pulls).## :stars: Show your support
Please give a :star: if this project helped you!
[](https://www.buymeacoffee.com/negrel)
#### :scroll: License
MIT © [Alexandre Negrel](https://www.negrel.dev)