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