🚀 Socket Launch Week Day 4:Socket MCP Adds Org Alerts, Threat Feed Review, and Package Inspection.Learn more
Sign In

mathguru

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mathguru

A beginner-friendly math utility package for Node.js — add, subtract, multiply, divide, and square numbers with ease.

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
16
-23.81%
Maintainers
1
Weekly downloads
 
Created
Source

mathguru

npm version license

A beginner-friendly math utility package for Node.js. Perform common arithmetic operations — addition, subtraction, multiplication, division, and squaring — with clean, well-documented functions.

Installation

npm install mathguru

Usage

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

Functions

add(a, b)

Returns the sum of two numbers.

ParameterTypeDescription
anumberThe first number
bnumberThe second number
add(2, 3); // 5

subtract(a, b)

Returns the difference between two numbers (a - b).

ParameterTypeDescription
anumberThe number to subtract from
bnumberThe number to subtract
subtract(10, 4); // 6

multiply(a, b)

Returns the product of two numbers.

ParameterTypeDescription
anumberThe first number
bnumberThe second number
multiply(4, 3); // 12

divide(a, b)

Returns the quotient of two numbers (a / b).

⚠️ Throws an Error if b is 0.

ParameterTypeDescription
anumberThe dividend (number to divide)
bnumberThe 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).

ParameterTypeDescription
xnumberThe number to square
square(5); // 25
square(3); // 9

Error Handling

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.

License

MIT

Keywords

math

FAQs

Package last updated on 12 May 2026

Did you know?

Socket

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.

Install

Related posts