CheeseNaN is a lightweight and versatile utility library for robust number validation in JavaScript and TypeScript. It simplifies working with numbers by providing a suite of functions to handle edge cases, perform checks, and validate mathematical properties.
- 🧀 Robust NaN checks: Beyond
isNaN
andNumber.isNaN
. - 🧮 Comprehensive number tests: Positive, negative, zero, even, odd, integers, floats.
- 📐 Mathematical utilities: Prime numbers, powers of
n
, perfect squares. - 🎛 Custom checks: Validate ranges, divisibility, and more.
Install via npm or yarn:
npm install cheesenan
Or use a CDN for vanilla projects:
import * as cheesenan from 'https://unpkg.com/statello@latest/dist/cheesenan.min.js'
import { cheeseNaN, cheeseValidNumber, cheeseInteger } from 'cheesenan';
console.log(cheeseNaN(NaN)); // true
console.log(cheeseValidNumber(42)); // true
console.log(cheeseInteger(42.5)); // false
import { cheesePrime, cheeseWithinRange, cheesePowerOfN } from 'cheesenan';
console.log(cheesePrime(7)); // true
console.log(cheeseWithinRange(10, 5, 15)); // true
console.log(cheesePowerOfN(16, 2)); // true (16 is 2^4)
console.log(cheesePowerOfN(27, 3)); // true (27 is 3^3)
import { cheeseAllAreNumbers, cheeseSomeAreNaN } from 'cheesenan';
console.log(cheeseAllAreNumbers([1, 2, 3])); // true
console.log(cheeseSomeAreNaN([1, NaN, 3])); // true
-
cheeseNaN(value: any): boolean
Returnstrue
if the value isNaN
or not a number. -
cheeseValidNumber(value: any): boolean
Returnstrue
if the value is a finite number. -
cheeseInteger(value: any): boolean
Returnstrue
if the value is an integer. -
cheeseFloat(value: any): boolean
Returnstrue
if the value is a finite float (non-integer). -
cheeseNonZeroNumber(value: any): boolean
Returnstrue
if the value is a non-zero number.
-
cheesePositive(value: any): boolean
Returnstrue
if the value is a positive number. -
cheeseNegative(value: any): boolean
Returnstrue
if the value is a negative number. -
cheesePrime(value: any): boolean
Returnstrue
if the value is a prime number. -
cheesePowerOfN(value: any, n: number): boolean
Returnstrue
if the value is a power ofn
. -
cheesePerfectSquare(value: any): boolean
Returnstrue
if the value is a perfect square.
-
cheeseWithinRange(value: any, min: number, max: number): boolean
Returnstrue
if the value is within the range[min, max]
. -
cheeseDivisibleBy(value: any, divisor: number): boolean
Returnstrue
if the value is divisible by the given divisor.
-
cheeseAllAreNumbers(values: any[]): boolean
Returnstrue
if all elements in the array are valid numbers. -
cheeseSomeAreNaN(values: any[]): boolean
Returnstrue
if at least one element in the array isNaN
.
- Performance Optimization: Improve speed for large datasets (e.g., prime number checks).
- Extended Mathematical Utilities: Add functions for Fibonacci checks, GCD/LCM, etc.
- Type-safe Input Validation: Enhance TypeScript support with stricter typings.
- Integration: Provide plugins for frameworks like React or Vue for runtime validation.
Contributions are welcome! Feel free to submit issues or pull requests.
Licensed under the MIT License.