1.1.0 • Published 5 years ago
calculator-logic v1.1.0
Viewless Calculator
Very simple calculator logic without any view, just to show internal mechanics of a basic immediate-excution calculator.
For more information see:
Installation
npm install --save calculator-logic
Usage
import Calculator from 'calculator-logic';
const myCalculator = Calculator();
const { keys } = myCalculator;
myCalculator
.keyPress(keys.NUM_1)
.keyPress(keys.NUM_2)
.keyPress(keys.MULTIPLY)
.keyPress(keys.NUM_3)
.keyPress(keys.EQUALS);
const result = myCalculator.display();
console.log(result); // 36
API
Methods
Calculator: {
// Does a key press action on the calculator.
// Takes the pressed key as an argument.
// Returns the calculator instance to
// make chaining key presses possible.
keyPress (key: CalculatorKey) : Calculator;
// Returns the current number displayed on the calculator screen
display () : Number;
// List of available keys on the calculator
keys : {
NUM_0, ..., NUM_9,
ADD, SUBTRACT, MULTIPLY, DIVIDE,
SQRT,
EQUALS,
};
};
Test
npm run test
License
MIT