isxxxx
Lightweight library for checking number properties and mathematical classifications.
Installation
npm install isxxxx
# or
yarn add isxxxx
# or
pnpm add isxxxx
Usage
// Import specific functions
const { isEven, isPrime, isHappy } = require('isxxxx');
// Or import everything
const isxxxx = require('isxxxx');
// Examples
isEven(4); // true
isPrime(17); // true
isFibonacci(8); // true
isHappy(19); // true
Available Functions
Basic Properties
isEven(num)
- Checks if number is evenisOdd(num)
- Checks if number is oddisPositive(num)
- Checks if number is positiveisNegative(num)
- Checks if number is negativeisZero(num)
- Checks if number is zeroisInteger(num)
- Checks if number is an integerisSafeInteger(num)
- Checks if number is a safe integer in JavaScriptisInRange(num, min, max)
- Checks if number is within range (inclusive)
Mathematical Properties
isPrime(num)
- Checks if number is primeisPerfectSquare(num)
- Checks if number is a perfect squareisMultipleOf(num, multiple)
- Checks if number is a multiple of anotherisPowerOfTwo(num)
- Checks if number is a power of twoisPowerOf(num, base)
- Checks if number is a power of a given baseisSquareFree(num)
- Checks if number has no squared prime factors
Special Sequences
isFibonacci(num)
- Checks if number is in the Fibonacci sequenceisLucas(num)
- Checks if number is in the Lucas sequenceisCatalan(num)
- Checks if number is a Catalan numberisBell(num)
- Checks if number is a Bell numberisTriangular(num)
- Checks if number is triangular (1+2+3+...)isPentagonal(num)
- Checks if number is pentagonalisHexagonal(num)
- Checks if number is hexagonalisFactorial(num)
- Checks if number is a factorial (n!)isRepunit(num)
- Checks if number consists only of 1sisPronic(num)
- Checks if number is pronic (n*(n+1))
Named Numbers
isMersennePrime(num)
- Checks if number is a Mersenne prime (2^n-1)isFermat(num)
- Checks if number is a Fermat number (2^(2^n)+1)isCullen(num)
- Checks if number is a Cullen number (n*2^n+1)isWoodall(num)
- Checks if number is a Woodall number (n*2^n-1)isKaprekar(num)
- Checks if number is a Kaprekar numberisArmstrong(num)
- Checks if number equals sum of its digits each raised to power of number of digitsisNarcissistic(num)
- Alias for isArmstrongisHappy(num)
- Checks if a number is "happy" (process leads to 1)isHarshad(num)
- Checks if number is divisible by sum of its digitsisSmith(num)
- Checks if digit sum equals digit sum of prime factorsisApocalyptic(num)
- Checks if 2^n contains "666"
Number Classifications
isPerfect(num)
- Checks if number equals sum of its proper divisorsisAbundant(num)
- Checks if number is less than sum of proper divisorsisDeficient(num)
- Checks if number is greater than sum of proper divisorsisPowerful(num)
- Checks if all prime factors also divide as squaresisPractical(num)
- Checks if every smaller number is sum of distinct divisorsisSelfNumber(num)
- Checks if number cannot be generated as n+sum(digits(n))isAutomorphic(num)
- Checks if square ends with the number itselfisPalindrome(num)
- Checks if number reads the same forward and backwardisAlternating(num)
- Checks if digits alternate between odd and evenisUndulant(num)
- Checks if digits rise and fall alternatelyisCarmichael(num)
- Checks if number satisfies Fermat's little theorem
Error Handling
All functions validate inputs and throw appropriate errors:
// Throws TypeError: Expected a number
isEven('not a number');
// Throws TypeError: Expected numbers
isMultipleOf('ten', 5);
// Throws Error: Cannot check for multiples of zero
isMultipleOf(10, 0);
License
MIT © Alexander KOP