@hkh12/node-calc

4.2.1 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i @hkh12/node-calc

Weekly Downloads

3

Version

4.2.1

License

MIT

Unpacked Size

16.4 kB

Total Files

16

Last publish

Collaborators

  • hkh12