@flarimo/calculator
v1.0.0
Published
Simple four-operation arithmetic calculator library with CLI support
Readme
@flarimo/calculator
Simple four-operation arithmetic calculator library with CLI support. Supports + - * / and parentheses. Zero dependencies, ESM, Node 18+.
Install
npm install @flarimo/calculator
# global CLI
npm install -g @flarimo/calculatorCLI
# Single expression
flarimo-calc "3 + 4 * 2" # 11
flarimo-calc "(1 + 2) * (5 - 3)" # 6
flarimo-calc 10 / 4 # 2.5
# Interactive REPL
flarimo-calc --replAPI
import { add, sub, mul, div, calc } from '@flarimo/calculator';
add(3, 4) // 7
sub(10, 3) // 7
mul(3, 4) // 12
div(10, 4) // 2.5
div(1, 0) // throws RangeError: Division by zero
// Full expression evaluator (supports parentheses & operator precedence)
calc('3 + 4 * 2') // 11
calc('(1 + 2) * 3') // 9
calc('10 / (2 + 3)') // 2
calc('-5 * (3 + 2)') // -25add(a, b) / sub(a, b) / mul(a, b) / div(a, b)
Basic arithmetic on two numbers. div throws RangeError when b is 0.
calc(expression)
Evaluates a mathematical expression string. Supports:
+-*/- Parentheses for grouping
- Decimal numbers
- Unary minus (e.g.
-5 * 2)
Throws SyntaxError on invalid input, RangeError on division by zero.
License
MIT
