Skip to main content

castToBoolean

Cast any input to a boolean value.

Signature

castToBoolean(input: any, default?: boolean): boolean;

Parameters

NameTypeOptionalDescription
inputanyNoSpecifies the input.
defaultbooleanYesOptional parameter which specifies the default boolean value if the supplied input cannot be casted.

Return value

Returns the boolean value.

Example

import { castToBoolean } from "@tripetto/runner";

castToBoolean(1); // Returns `true`
castToBoolean("true"); // Returns `true`
castToBoolean("false"); // Returns `false`