castToBoolean
Cast any input to a boolean value.
Signature
castToBoolean(input: any, default?: boolean): boolean;
Parameters
Name | Type | Optional | Description |
---|---|---|---|
input | any | No | Specifies the input. |
default | boolean | Yes | Optional 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/builder";
castToBoolean(1); // Returns `true`
castToBoolean("true"); // Returns `true`
castToBoolean("false"); // Returns `false`