Detalhes do pacote

isxxxx

Lightweight library for checking number properties and mathematical classifications

utility, validation, numbers, prime

readme (leia-me)

isxxxx

npm version MIT License

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 even
  • isOdd(num) - Checks if number is odd
  • isPositive(num) - Checks if number is positive
  • isNegative(num) - Checks if number is negative
  • isZero(num) - Checks if number is zero
  • isInteger(num) - Checks if number is an integer
  • isSafeInteger(num) - Checks if number is a safe integer in JavaScript
  • isInRange(num, min, max) - Checks if number is within range (inclusive)

Mathematical Properties

  • isPrime(num) - Checks if number is prime
  • isPerfectSquare(num) - Checks if number is a perfect square
  • isMultipleOf(num, multiple) - Checks if number is a multiple of another
  • isPowerOfTwo(num) - Checks if number is a power of two
  • isPowerOf(num, base) - Checks if number is a power of a given base
  • isSquareFree(num) - Checks if number has no squared prime factors

Special Sequences

  • isFibonacci(num) - Checks if number is in the Fibonacci sequence
  • isLucas(num) - Checks if number is in the Lucas sequence
  • isCatalan(num) - Checks if number is a Catalan number
  • isBell(num) - Checks if number is a Bell number
  • isTriangular(num) - Checks if number is triangular (1+2+3+...)
  • isPentagonal(num) - Checks if number is pentagonal
  • isHexagonal(num) - Checks if number is hexagonal
  • isFactorial(num) - Checks if number is a factorial (n!)
  • isRepunit(num) - Checks if number consists only of 1s
  • isPronic(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 number
  • isArmstrong(num) - Checks if number equals sum of its digits each raised to power of number of digits
  • isNarcissistic(num) - Alias for isArmstrong
  • isHappy(num) - Checks if a number is "happy" (process leads to 1)
  • isHarshad(num) - Checks if number is divisible by sum of its digits
  • isSmith(num) - Checks if digit sum equals digit sum of prime factors
  • isApocalyptic(num) - Checks if 2^n contains "666"

Number Classifications

  • isPerfect(num) - Checks if number equals sum of its proper divisors
  • isAbundant(num) - Checks if number is less than sum of proper divisors
  • isDeficient(num) - Checks if number is greater than sum of proper divisors
  • isPowerful(num) - Checks if all prime factors also divide as squares
  • isPractical(num) - Checks if every smaller number is sum of distinct divisors
  • isSelfNumber(num) - Checks if number cannot be generated as n+sum(digits(n))
  • isAutomorphic(num) - Checks if square ends with the number itself
  • isPalindrome(num) - Checks if number reads the same forward and backward
  • isAlternating(num) - Checks if digits alternate between odd and even
  • isUndulant(num) - Checks if digits rise and fall alternately
  • isCarmichael(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