Skip to content

A small (1.78KB) parser to evaluate infix notation to values (without using eval).

Notifications You must be signed in to change notification settings

Renddslow/mathd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mathd

A small (1.78KB) parser to evaluate infix notation to values (without using eval).

Install

$ yarn add mathd

Usage

import mathd from 'mathd';

mathd('2 + 2');
// => 4

API

mathd(expression)

expression

  • Type: string
  • Required: ✅

An expression written in infix notation (the way math problems probably looked when you were in elementary school).

Supported operators

  • +: Addition
  • -: Subtraction
  • /: Division
  • *: Multiplication
  • ^: Exponents (alias: **)

mathd alsp supports parentheses for encapsulating expressions.