A robust utility function for validating if two numbers are strictly equal, with robust error handling for non-integer inputs.
Install the package via npm or yarn:
npm install equal-n
or
yarn add equal-n
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.
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.
}
-
x
: The first number to compare. -
n
: The second number to compare (must be an integer).
-
boolean
: Returnstrue
ifx
is equal ton
, otherwisefalse
.
- Throws an
Error
ifn
is not an integer.
This project is licensed under the MIT License.
Contributions, issues, and feature requests are welcome! Feel free to check out the repository on GitHub.