
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
@ajaykrp/math-ops
Advanced tools
A versatile TypeScript library designed to handle a wide range of mathematical operations
The @ajaykrp/math-ops npm package provides functionalities for both basic arithmetic operations and complex arithmetic expression evaluations. It supports addition, subtraction, multiplication, and division, as well as the evaluation of complex expressions with parentheses.
You can install the package via npm:
npm install @ajaykrp/math-ops
For basic arithmetic operations (addition, subtraction, multiplication, and division), use the calculate function.
import { calculate } from '@ajaykrp/math-ops';
// Basic arithmetic operations
const result1 = calculate('addition', 1, 2, 3); // 6
const result2 = calculate('subtraction', 10, 5, 2); // 3
const result3 = calculate('multiplication', 2, 3, 4); // 24
const result4 = calculate('division', 12, 3, 2); // 2
console.log(result1); // 6
console.log(result2); // 3
console.log(result3); // 24
console.log(result4); // 2
For evaluating complex arithmetic expressions, use the ExpressionEvaluator class.
import ExpressionEvaluator from '@ajaykrp/math-ops';
// Evaluating complex expressions
const result1 = ExpressionEvaluator.evaluate('1 + 2 * 4 / 6'); // 2.3333
const result2 = ExpressionEvaluator.evaluate('(1 + 2) * 4 / 6'); // 2
const result3 = ExpressionEvaluator.evaluate('1 + (2 * (3 + 4)) / 5'); // 3.4
console.log(result1); // 2.3333
console.log(result2); // 2
console.log(result3); // 3.4
calculate(operation: string, ...args: number[]): numberPerforms the specified arithmetic operation.
Parameters:
operation (string): The operation to perform. Possible values: 'addition', 'subtraction', 'multiplication', 'division'....args (number[]): The numbers to operate on.Returns:
number: The result of the operation.ExpressionEvaluator.evaluate(expression: string): numberEvaluates the given arithmetic expression.
Parameters:
expression (string): The arithmetic expression to evaluate. Supports operators +, -, *, / and parentheses.Returns:
number: The result of the expression.Basic Arithmetic Operations:
Complex Arithmetic Expression Evaluation:
Basic Arithmetic:
calculate('addition', 1, 2, 3)calculate('subtraction', 10, 5, 2)calculate('multiplication', 2, 3, 4)calculate('division', 12, 3, 2)Complex Expressions:
ExpressionEvaluator.evaluate('1 + 2 * 4 / 6')ExpressionEvaluator.evaluate('(1 + 2) * 4 / 6')ExpressionEvaluator.evaluate('1 + (2 * (3 + 4)) / 5')ExpressionEvaluator.evaluate('1 / 0') (Throws error)MIT License
FAQs
A versatile TypeScript library designed to handle a wide range of mathematical operations
We found that @ajaykrp/math-ops demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.