Conversions
Utilities for converting data types.
Example:
import { toBoolean } from "@travisspomer/tidbits"
const trueOrFalse: boolean = toBoolean(value)
toBoolean
toBoolean(value: any): boolean
value
: A string or number to be converted to a Boolean. (Or, an existing Boolean will be returned as-is.)- Returns:
true
ifvalue
istrue
,1
, or"true"
(case- and whitespace-insensitive).false
ifvalue
is"false"
or any falsy value (false
,0
,""
,null
,undefined
,NaN
).- Anything else (
"daffodil"
, 42,{}
, etc.) throws an exception.