@mateusznejman/mathparser-js

1.0.9 • Public • Published

MathParser-JS

Simple Mathematical string parser.

Installing

npm i @mateusznejman/mathparser-js
yarn add @mateusznejman/mathparser-js

Using

import { MathBuffer } from '@mateusznejman/mathparser-js';

//Constants
//POW = ^
//SQRT = √
//PI = π

/*
Working calculations
- Add / Substract / Multiply / Divide
- Square root / Power by X
- Percents
*/
let mathString = "2+(3+8)√(2+2)*5^4^5";
let buffer = new MathBuffer(mathString);
buffer.Add('+');
buffer.Add('5');

let val = buffer.Eval();

Other Functions

import { LeftSide, RightSide, GetBracketContentLeft, GetBracketContentRight } from '@mateusznejman/mathparser-js';

const leftSide = LeftSide(text, startIndex, withBracket = false); //Get left side of sign in startIndex(to nearest sign other than 1234567890.,;'). If withBracket = true, return value contains brackets(if exists)
const rightSide = Rightide(text, startIndex, withBracket = false); //Get right side of sign in startIndex(to nearest sign other than 1234567890.,;'). If withBracket = true, return value contains brackets(if exists)
const leftBracket = GetBracketContentLeft(text, startIndex, withBracket = false); //Used when in prev char is end bracket
const rightBracket = GetBracketContentRight(text, startIndex, withBracket = false); //Used when in next char is start bracket

Package Sidebar

Install

npm i @mateusznejman/mathparser-js

Weekly Downloads

0

Version

1.0.9

License

ISC

Unpacked Size

10.2 kB

Total Files

3

Last publish

Collaborators

  • mateusznejman