A simple calculator logic package that provides an enum CalculatorButtons
and a class CalculatorLogic
for basic
calculator functionality.
You can install this package using npm or yarn:
npm install simple-calculator-logic
# or
yarn add simple-calculator-logic
You can import the CalculatorButtons
enum and the CalculatorLogic
class as follows:
import { CalculatorButtons, CalculatorLogic } from 'simple-calculator-logic';
CalculatorLogic is a class that represents a basic calculator with the following features:
- Arithmetic operations (addition, subtraction, multiplication, division)
- Square root calculation
- Percentage calculation
- Negation of numbers
- Clearing the calculator state
Example usage:
const calculator = new CalculatorLogic();
calculator
.pressKey(CalculatorButtons.Five)
.pressKey(CalculatorButtons.Plus)
.pressKey(CalculatorButtons.Three)
.pressKey(CalculatorButtons.Equals);
console.log(calculator.getDisplay()); // Output: "8"
CalculatorButtons
is an enum that provides a set of calculator button values for use with CalculatorLogic. The
available button values include:
- Plus
- Minus
- Multiply
- Divide
- SquareRoot
- Percentage
- Negate
- Equals
- Clear
- Decimal
- Numeric values (e.g., One, Two, ..., Nine, Zero)
To run tests for the simple-calculator-logic
package, you will need to have Node.js and npm or yarn installed on your
system.
-
First, ensure that you have installed the necessary development dependencies by running the following command in the package directory:
npm install # or yarn install
-
Once the development dependencies are installed, you can run the tests using the following command:
npm test # or yarn test
-
The test suite will run, and you will see the test results in your console.
This package is open-source and available under the MIT License.