equal-n
v1.3.0
Published
A robust utility function for validating if two numbers are strictly equal, with robust error handling for non-integer inputs.
Downloads
166
Maintainers
Readme
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
: Returnstrue
ifx
is equal ton
, otherwisefalse
.
Errors:
- Throws an
Error
ifn
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.