A TypeScript utility library providing a comprehensive set of functions to validate, verify, and perform checks on numbers. This library includes functions to determine divisibility, check number properties like evenness or primality, and assess numeric ranges, among others. Designed with clean, descriptive function names, it’s an essential toolkit for any TypeScript project dealing with numeric validations.
NPM:
npx jsr add @checker/numberPNPM:
pnpm dlx jsr add @checker/numberDeno:
deno add @checker/numberYarn:
yarn dlx jsr add @checker/numberBun:
bunx jsr add @checker/numberChecks if a given number is cleanly divisible by a divisor.
check_is_cleanly_disible(10, 2); // 10 % 2 = 0
check_is_cleanly_disible(10, 3); // 10 % 3 = 1Checks if a given number is not cleanly divisible by a divisor.
check_is_not_cleanly_disible(10, 3); // true, 10 % 3 = 1
check_is_not_cleanly_disible(10, 2); // false, 10 % 2 = 0Checks if a given number is the cube root of a target number.
check_is_cube_root(3, 27); // true, 3 * 3 * 3 = 27
check_is_cube_root(2, 27); // false, 2 * 2 * 2 = 8 ≠ 27Checks if a given number is not the cube root of a target number.
check_is_not_cube_root(2, 27); // true, 2 * 2 * 2 = 8 ≠ 27
check_is_not_cube_root(3, 27); // false, 3 * 3 * 3 = 27Checks if the given number is a divisor of the target number.
check_is_divisor(3, 9);
// true, 9 % 3 = 0 => 3 is a divisor of 9
check_is_divisor(2, 9);
// false, 9 % 2 = 1 => 2 is not a divisor of 9Checks if the given number is not a divisor of the target number.
check_is_not_divisor(2, 9); // true
check_is_not_divisor(3, 9); // falseChecks if a given number is even.
check_is_even(4); // true
check_is_even(3); // falseChecks if a given number is not even (odd).
check_is_not_even(3); // false
check_is_not_even(4); // trueChecks if a given number is a Fibonacci number.
check_is_fibonacci(3); // true
check_is_fibonacci(5); // true
check_is_fibonacci(4); //false
check_is_fibonacci(6); // falseChecks if a given number is not a Fibonacci number.
check_is_not_fibonacci(4); // true
check_is_not_fibonacci(6); // true
check_is_not_fibonacci(3); // false
check_is_not_fibonacci(5); // falseChecks if the given number is a floating-point number.
check_is_float(1.2); // true
check_is_float(1); // false
check_is_float(1.0); // 1.0 % 1 = 0 => falseChecks if the given number is not a floating-point number.
check_is_not_float(1); // true
check_is_not_float(1.0); // true
check_is_not_float(1.2); // falseChecks if the given array of numbers forms a geometric sequence with the specified ratio.
check_is_geometric_sequence([2, 4, 8], 2); // true
check_is_geometric_sequence([2, 4, 9], 2); // falseChecks if the given array of numbers does not form a geometric sequence with the specified ratio.
check_is_not_geometric_sequence([2, 4, 9], 2); // false
check_is_not_geometric_sequence([2, 4, 8], 2); // trueChecks if the given number is greater than a specified threshold.
check_is_greater_than(10, 5); // true, 10 is greater than 5
check_is_greater_than(10, 15); // false, 10 is not greater than 15Checks if the given number is not greater than a specified threshold.
check_is_not_greater_than(10, 15); // true, 10 is not greater than 15
check_is_not_greater_than(10, 10); // false
check_is_not_greater_than(10, 5); // false, 10 is greater than 5Checks if a number is greater than or equal to a given threshold.
check_is_greater_than_or_equal(10, 10); // true, 10 is equal 10
check_is_greater_than_or_equal(10, 5); // true, 10 is greater than 5
check_is_greater_than_or_equal(10, 15); // false, 10 is not greater than 15Checks if a number is not greater than or equal to a given threshold.
check_is_not_greater_than_or_equal(10, 15); // true
check_is_not_greater_than_or_equal(10, 10); // false
check_is_not_greater_than_or_equal(10, 5); // falseChecks if the given value is Infinity.
If you want to know if a string is Infinity, use the
check_is_infinity_string() function.
check_is_infinity(Infinity); // true
check_is_infinity(-Infinity); // true
check_is_infinity("hello"); // false
check_is_infinity(123); // falseChecks if the given value is not Infinity.
check_is_not_infinity("hello"); // true
check_is_not_infinity(123); // true
check_is_not_infinity(Infinity); // false
check_is_not_infinity(-Infinity); // falseChecks if the given number is an integer.
check_is_integer(1); // true
check_is_integer(1.1); // falseChecks if the given number is not an integer.
check_is_not_integer(1.1); // true
check_is_not_integer(1); // falseChecks if a number is less than a specified threshold.
check_is_less_than(5, 10); // true, 5 is less than 10
check_is_less_than(15, 10); // false, 15 is not less than 10Checks if a number is not less than a specified threshold.
check_is_not_less_than(15, 10); // true
check_is_not_less_than(5, 10); // falseChecks if the given number is less than or equal to the specified threshold.
check_is_less_than_or_equal(10, 10); // true
check_is_less_than_or_equal(15, 10); // true
check_is_less_than_or_equal(5, 10); // falseChecks if the given number is not less than or equal to the specified threshold.
check_is_not_less_than_or_equal(5, 10); // true
checkIsLessTHanOrEqual(10, 10); // true
check_is_not_less_than_or_equal(15, 5); // falseChecks if a given number matches the logarithm of a target with a specified base.
check_is_logarithm(4, 2, 16); // log2(16) = 4
check_is_logarithm(4, 2, 8); // log2(8) = 3 ≠ 4Checks if a given number does not match the logarithm of a target with a specified base.
check_is_not_logarithm(4, 2, 8); // true
check_is_not_logarithm(4, 2, 16); // falseChecks if a given number is negative.
check_is_negative(-1); // true
check_is_negative(1); // falseChecks if a given number is not negative.
check_is_not_negative(1); // true
check_is_not_negative(-1); // trueChecks if the given value is of type number.
check_is_number(1); // true
check_is_number("string"); // falseChecks if the given value is not of type number.
check_is_not_number("string"); // true
check_is_not_number(1); // falseChecks if a given number is odd.
check_is_odd(3); // true
check_is_odd(-3); // true
check_is_odd(2); // false
check_is_odd(-2); // falseChecks if a given number is not odd.
check_is_not_odd(2); // true
check_is_not_odd(-2); // true
check_is_not_odd(3); // false
check_is_not_odd(-3); // falseChecks if a given number is a perfect number.
check_is_perfect_number(28); // true, 1 + 2 + 4 + 7 + 14 = 28
check_is_perfect_number(12); // false, 1 + 2 + 3 + 4 + 6 = 16Checks if a given number is not a perfect number.
check_is_not_perfect_number(12); // true
check_is_not_perfect_number(28); // falseChecks if a given number is a perfect square.
check_is_perfect_square(16); // true, 4 * 4 = 16
check_is_perfect_square(8); // false, 2 * 2 = 4 ≠ 8Checks if a given number is not a perfect square.
check_is_not_perfect_square(8); // true
check_is_not_perfect_square(16); // falseChecks if a given number is positive.
check_is_positive(1); // true
check_is_positive(0); // false
check_is_positive(-1); // falseChecks if a given number is not positive.
check_is_not_positive(0); // true
check_is_not_positive(-1); // true
check_is_not_positive(1); // falseChecks if a given number is a power of a specified base.
check_is_power(8, 2); // true, 8 is 2^3, so it's a power of 2
check_is_power(10, 2); // false, 10 is not a power of 2Checks if a given number is not a power of a specified base.
check_is_not_power(10, 2); // true
check_is_not_power(8, 2); // falseChecks if a given number is a prime number.
check_is_prime(7); // true
check_is_prime(10); // false, 10 is divisible by 2 and 5Checks if a given number is not a prime number.
check_is_not_prime(10); // true
check_is_not_prime(7); // falseChecks if a given number is the square root of the target number.
check_is_square_root(3, 9); // true, 3 * 3 = 9
check_is_square_root(4, 20); // false, 4 * 4 =16Checks if a given number is not the square root of the target number.
check_is_not_sequare_root(4, 20); // true
check_is_not_sequare_root(3, 9); // false, 3 * 3 = 9Checks if a given number is within a specified range, inclusive.
check_within_range(5, 1, 10); // true, 5 is within the range [1, 10]
check_within_range(15, 1, 10); // false, 15 is not within the range [1, 10]Checks if a given number is not within a specified range.
check_is_not_within_range(15, 1, 10); //
check_is_not_within_range(5, 1, 10);Checks if the given number is zero.
check_is_zero(0); // true
check_is_zero(5); // falseChecks if the given number is not zero.
check_is_not_zero(5); // true
check_is_not_zero(0); // false