import { getTypeOf } from './deps' ; example export function toBoolean ( input ) { if ( isFalsy ( input ) ) return false ; if ( isTruthy ( input ) ) return true ; return Boolean ( input ) ; } const _falsy = Object . freeze ( { 0 : true , false : true , no : true , } ) ; const _truthy = Object . freeze ( { 1 : true , true : true , yes : true , } ) ; /**
 * Returns true if the value is a truthy like value
*/ export function isTruthy ( input ) { if ( input === true ) return true ; const val = typeof input === 'string' ? input . trim ( ) . toLowerCase ( ) : String ( input ) ; return _truthy [ val ] === true ; } /**
 * Returns true if the value is a falsy like value
*/ export function isFalsy ( input ) { if ( input === false || input == null || input === '' ) return true ; const val = typeof input === 'string' ? input . trim ( ) . toLowerCase ( ) : String ( input ) ; return _falsy [ val ] === true ; } /**
 * Returns true if the input is a boolean
*/ export function isBoolean ( input ) { return typeof input === 'boolean' ; } example export function isBooleanLike ( input ) { return isFalsy ( input ) || isTruthy ( input ) ; } /** Will throw if input is not booleanLike, converts input to a Boolean */ export function toBooleanOrThrow ( input ) { if ( ! isBooleanLike ( input ) ) { throw new TypeError ( `Expected ${ input } (${ getTypeOf ( input ) }) to be boolean like` ) ; } return toBoolean ( input ) ; }