1.3.0 • Published 7 months ago

equal-n v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

equalN

A robust utility function for validating if two numbers are strictly equal, with robust error handling for non-integer inputs.


Installation

Install the package via npm or yarn:

npm install equal-n

or

yarn add equal-n

Usage

The equalN function checks if a number x is strictly equal to another number n. It ensures that both x and n are integers and throws an error if n is not an integer.

Example:

import equalN from 'equal-n';

// Valid comparison
console.log(equalN(5, 5)); // true
console.log(equalN(5, 6)); // false

// Invalid `x`
console.log(equalN(5.5, 5)); // false

// Invalid `n` (throws an error)
try {
    console.log(equalN(5, 5.5));
} catch (error) {
    console.error(error.message);
    // Output: Input n must strictly be an integer, got 5.5 instead.
}

API

equalN(x: number, n: number): boolean

Parameters:

  • x: The first number to compare.
  • n: The second number to compare (must be an integer).

Returns:

  • boolean: Returns true if x is equal to n, otherwise false.

Errors:

  • Throws an Error if n is not an integer.

License

This project is licensed under the MIT License.


Contributing

Contributions, issues, and feature requests are welcome! Feel free to check out the repository on GitHub.

1.3.0

7 months ago

1.2.0

7 months ago

1.0.0

7 months ago