
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
A beginner-friendly math utility package for Node.js — add, subtract, multiply, divide, and square numbers with ease.
A beginner-friendly math utility package for Node.js. Perform common arithmetic operations — addition, subtraction, multiplication, division, and squaring — with clean, well-documented functions.
npm install mathguru
const mathguru = require('mathguru');
console.log(mathguru.add(3, 5)); // 8
console.log(mathguru.subtract(10, 4)); // 6
console.log(mathguru.multiply(4, 3)); // 12
console.log(mathguru.divide(10, 2)); // 5
console.log(mathguru.square(5)); // 25
You can also import individual functions using destructuring:
const { add, subtract, multiply, divide, square } = require('mathguru');
add(2, 3); // 5
subtract(9, 4); // 5
multiply(3, 4); // 12
divide(10, 2); // 5
square(6); // 36
add(a, b)Returns the sum of two numbers.
| Parameter | Type | Description |
|---|---|---|
a | number | The first number |
b | number | The second number |
add(2, 3); // 5
subtract(a, b)Returns the difference between two numbers (a - b).
| Parameter | Type | Description |
|---|---|---|
a | number | The number to subtract from |
b | number | The number to subtract |
subtract(10, 4); // 6
multiply(a, b)Returns the product of two numbers.
| Parameter | Type | Description |
|---|---|---|
a | number | The first number |
b | number | The second number |
multiply(4, 3); // 12
divide(a, b)Returns the quotient of two numbers (a / b).
⚠️ Throws an
Errorifbis0.
| Parameter | Type | Description |
|---|---|---|
a | number | The dividend (number to divide) |
b | number | The divisor (must not be zero) |
divide(10, 2); // 5
// Division by zero
try {
divide(5, 0);
} catch (err) {
console.error(err.message); // 'Division by zero is not allowed.'
}
square(x)Returns the square of a number (x * x).
| Parameter | Type | Description |
|---|---|---|
x | number | The number to square |
square(5); // 25
square(3); // 9
divide(a, b) will throw an Error when the divisor b is 0:
try {
mathguru.divide(10, 0);
} catch (err) {
console.error(err.message); // 'Division by zero is not allowed.'
}
Always wrap divide calls in a try/catch block when the divisor is user-supplied.
FAQs
MathGuru ecosystem-grade developer terminal toolkit. Powered by Kontyra.
The npm package mathguru receives a total of 16 weekly downloads. As such, mathguru popularity was classified as not popular.
We found that mathguru demonstrated a healthy version release cadence and project activity because the last version was released less than 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.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.