0.1.2 • Published 8 months ago

simple-math-evaluator v0.1.2

Weekly downloads
-
License
Apache 2.0
Repository
github
Last release
8 months ago

simple-math-evaluator

I was in need for simple arithmetic expression evaluator.

So I wrote one by myself. It uses regex lexer and syntax tree evaluator. Written in Typescript and contains zero dependencies.

Inspired by Math Evaluator in JavaScript

functionality

Just call function evaluate with expression string as argument.

result

Function returns Result object with result as value property and variables object containing all varibles with assigned values

value

Returned object can be used directly as Number, it's valueOf() function return value property.

variables

If expression contains assignement to variables resulting variables property will contain object with variable name as property name and variable value as property value, i.e. x = 5+2 => {x: 7}.

Operators

Built in Javascript operators and Math functions are used for calculations.

unary

Unary minus - can be used to negate value.

binary

Binary + - * / and power ^ can be used.

Functions

Some functions from JS Math also can be used. Separate multiple arguments with comma ,.

0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago