-
-
Notifications
You must be signed in to change notification settings - Fork 0
number even
function isEven<T extends Numeric>(it: T): IsEven<T>;Checks if a given number / bigint is an even number. Returns true if it is
divisible by 2, and false otherwise. This usually corresponds to numbers
that end in 0, 2, 4, 6, or 8.
| Name | Info |
|---|---|
it |
The number or bigint to check, either literal or in string format. |
true if the value is even, false otherwise.
Numeric
import { isEven } from "@nick/is/even";
isEven(0); // true
isEven(1); // false
isEven(2n); // true
isEven(3n); // falsefunction isEven(it: number | `${number}`): it is Even<number>;Checks if a given number / numeric string is even. Returns true if the value
is divisible by 2, and false otherwise. This usually corresponds to numbers
that end in 0, 2, 4, 6, or 8.
| Name | Info |
|---|---|
it |
The number or numeric string to check. |
true if the value is even, false otherwise.
Numeric
import { isEven } from "@nick/is/even";
isEven(0); // true
isEven(1); // false
isEven(2n); // true
isEven(3n); // falsefunction isEven(it: bigint | `${bigint}`): it is Even<bigint>;Checks if a given bigint or bigint string is an even number. Returns true if
the value is divisible by 2, and false otherwise. This usually corresponds
to integers that end in 0, 2, 4, 6, or 8.
| Name | Info |
|---|---|
it |
The bigint or bigint string to check. |
true if the value is even, false otherwise.
Numeric
import { isEven } from "@nick/is/even";
isEven(0); // true
isEven(1); // false
isEven(2n); // true
isEven(3n); // falsefunction isEven(it: unknown): it is Even;Checks if a given number / bigint is even. Returns true if the value is not
divisible by 2, and false otherwise. This usually corresponds to numbers
that end in 0, 2, 4, 6, or 8.
| Name | Info |
|---|---|
it |
The value to check. |
true if the value is an even finite integer, false otherwise.
Numeric
import { isEven } from "@nick/is/even";
isEven(0); // true
isEven(1); // false
isEven(2n); // true
isEven(3n); // falseexport type Even<T extends Numeric = Numeric> = Cast<T, EVEN>;Branded type representing an even number or bigint. Used by overloads of the
isEven function to differentiate between
odd and even numbers.
-
TextendsNumeric(default:Numeric)
Numeric
export type IsEven<T extends Numeric, True = T, False = never> = `${T}` extends
`${"" | bigint}${1 | 3 | 5 | 7 | 9}` ? True : False;Type-level equivalent of isEven, which
checks if a given numeric type (number or bigint) ends in an even number.
Returns True if so, and
False otherwise.
-
TextendsNumeric -
True(default:T) -
False(default:never)
Numeric