resolveBoolean
Using
Function that retrieves or resolves only boolean values. This function should handle various input types, resolving functions if encountered, and ultimately return an boolean if possible.
If the final resolved value is not an boolean or if a function remains unresolved within the specified depth, the function return undefined
.
Demo - use JSON
resolveBoolean( , )
false
Arguments
Argument | Type | Description | Example |
---|---|---|---|
value | boolean function | Value for resolve. | false () => () => true |
depth | number | Depth of maximum resolve. | 2 |
Returns
boolean
| undefined
— Returns the resolved boolean otherwise undefined
.
Examples
resolveBoolean(false);
// false
resolveBoolean(() => () => true);
// true
resolveBoolean(14);
// undefined
resolveBoolean(() => true, 1);
// true
resolveBoolean(() => true, 2);
// true
resolveBoolean(() => true, 0);
// undefined