0.1.2 • Published 3 years ago

extendable-calculator v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Extendable calculator

yes extendable

Where is extend

import Calculator from "extendable-calculator"

const calculator = new Calculator()

calculator.addOperation('+', (a, b) => a + b)

calculator.calc("12 + 4") // 16

// Unregistered operations will throw exception
calculator.calc("12 * 4") // Error: undefined operation

calculator.addOperation('*', (a, b) => a * b)
calculator.calc("12 * 4") // 48

// We can use words for operation keyword
calculator.addOperation('mod', (a, b) => a % b)
calculator.calc("12 mod 4") // 0

// But be carefully keywords with numbers can not be calculated
calculator.addOperation('s0meNum0perat1on', (a, b) => a % b)
calculator.calc("12 s0meNum0perat1on 4") // Error: undefined operation
0.1.2

3 years ago

0.1.0

3 years ago