Utils: `booleans`
Table of contents
Functions
Functions
isBoolean
▸ isBoolean(input
): input is boolean
Returns true if the input is a boolean
Parameters
Name | Type |
---|---|
input | unknown |
Returns
input is boolean
Defined in
packages/utils/src/booleans.ts:56
isBooleanLike
▸ isBooleanLike(input
): boolean
Returns true if the input is like a boolean. Use toBoolean to convert it to one.
Parameters
Name | Type |
---|---|
input | unknown |
Returns
boolean
Example
isBooleanLike(); // false
isBooleanLike(null); // true
isBooleanLike(0); // true
isBooleanLike('0'); // true
isBooleanLike('false'); // true
isBooleanLike('no'); // true
Defined in
packages/utils/src/booleans.ts:73
isFalsy
▸ isFalsy(input
): boolean
Returns true if the value is a falsy like value
Parameters
Name | Type |
---|---|
input | unknown |
Returns
boolean
Defined in
packages/utils/src/booleans.ts:47
isTruthy
▸ isTruthy(input
): boolean
Returns true if the value is a truthy like value
Parameters
Name | Type |
---|---|
input | unknown |
Returns
boolean
Defined in
packages/utils/src/booleans.ts:38
toBoolean
▸ toBoolean(input
): boolean
Convert any input into a boolean, this will work with stringified boolean
Parameters
Name | Type |
---|---|
input | unknown |
Returns
boolean
Example
toBoolean(1); // true
toBoolean(0); // false
toBoolean('1'); // true
toBoolean('0'); // false
toBoolean('yes'); // true
toBoolean('NO'); // false
toBoolean('true'); // true
toBoolean('FALSE'); // false
Defined in
packages/utils/src/booleans.ts:16
toBooleanOrThrow
▸ toBooleanOrThrow(input
): boolean
Will throw if input is not booleanLike, converts input to a Boolean
Parameters
Name | Type |
---|---|
input | unknown |
Returns
boolean