4.2.1 • Published 4 years ago

@hkh12/node-calc v4.2.1

Weekly downloads
26
License
MIT
Repository
github
Last release
4 years ago

node-calc

Build Status Coverage Status Minzipped size

A small, fast, zero-dependency library/CLI to help you parse and calculate basic math expressions. It supports +, -, *, / and ^ operators, parenthesis, and functions such as:

  • Trigonometric functions: sin, cos, tan, cot
  • sqrt, cbrt
  • Factorial: x! (or fact(x))
  • abs
  • log (base 10), ln

Functions are written in the form of f(x), fx syntax is not supported yet!

Installation

npm i @hkh12/node-calc

Examples

const { evalExpression, tokenize, Token, evalTokens } = require('@hkh12/node-calc');
evalExpression('2*2') // 4

const tokens = tokenize('2*2') // -> Token[]
evalTokens(tokens); // 4

CLI

Once installed, you can node-calc in your terminal:

# node-calc [expr...]
node-calc "2*2" "2+2" "1*3" # always wrap your expressions in quotes
node-calc # prompts you
4.2.1

4 years ago

4.2.0

4 years ago

4.1.0

4 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

4.0.0-beta.0

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.0.0

5 years ago

1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago