simple-calculator-logic
v0.2.2
Published
A simple Calculator object
Downloads
2
Readme
Simple Calculator Logic
A simple calculator logic package that provides an enum CalculatorButtons
and a class CalculatorLogic
for basic
calculator functionality.
Installation
You can install this package using npm or yarn:
npm install simple-calculator-logic
# or
yarn add simple-calculator-logic
Usage
Importing
You can import the CalculatorButtons
enum and the CalculatorLogic
class as follows:
import { CalculatorButtons, CalculatorLogic } from 'simple-calculator-logic';
CalculatorLogic
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
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)
Testing
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.
License
This package is open-source and available under the MIT License.