npm.io
1.0.14 • Published 5 years ago

@dev-syco/quick-math

Licence
MIT
Version
1.0.14
Deps
0
Size
37 kB
Vulns
0
Weekly
0

Quick-math

codecov Build Status

What is this

Implementation of shunting-yard algorithm to calculate string as mathematical expression.

How does this work?

While passing expression as infix mathematical expression QuickMath will parse it and transform into RPN. After this you can simply calculate result of RPN by calling calculate method. If your expression contains syntax errors class will throw exception.

Example
import { QuickMath } from 'quick-math';
const data = '5/2+25-3^2';

try {
  const expression = new QuickMath(data);
  console.log(expression.calculate() === QuickMath.calculate(data));
} catch (e) {
  console.error(e);
}

Keywords