import { R } from './libs' ; param { Array } value return { Array } export const compact = ( value ) => R . pipe ( R . reject ( R . isNil ) , R . reject ( R . isEmpty ) ) ( value ) ; param value return { Boolean } export const isPlainObject = ( value ) : boolean => { if ( R . is ( Object , value ) === false ) { return false ; } const ctr = value . constructor ; if ( typeof ctr !== 'function' ) { return false ; } const prot = ctr . prototype ; if ( R . is ( Object , prot ) === false ) { return false ; } if ( prot . hasOwnProperty ( 'isPrototypeOf' ) === false ) { return false ; } return true ; } ; /**
 * A safe way to test any value as to wheather is is 'blank'
 * meaning it can be either:
 *   - null
 *   - undefined
 *   - empty-string ('')
 *   - empty-array ([]).
 */ export const isBlank = ( value ) : boolean => { if ( value === null || value === undefined ) { return true ; } if ( R . is ( Array , value ) && compact ( value ) . length === 0 ) { return true ; } if ( R . is ( String , value ) && value . trim ( ) === '' ) { return true ; } return false ; } ; param value returns export const isNumeric = ( value ) => { if ( isBlank ( value ) ) { return false ; } const num = parseFloat ( value ) ; if ( num === undefined ) { return false ; } if ( num . toString ( ) . length !== value . toString ( ) . length ) { return false ; } return ! Number . isNaN ( num ) ; } ; param value returns export const toNumber = ( value ) => { if ( isBlank ( value ) ) { return value ; } const num = parseFloat ( value ) ; if ( num === undefined ) { return value ; } if ( num . toString ( ) . length !== value . toString ( ) . length ) { return value ; } return Number . isNaN ( num ) ? value : num ; } ; param value param defaultValue returns export const toBool = ( value , defaultValue = undefined ) => { if ( R . isNil ( value ) ) { return defaultValue ; } if ( R . is ( Boolean , value ) ) { return value ; } const asString = value . toString ( ) . trim ( ) . toLowerCase ( ) ; if ( asString === 'true' ) { return true ; } if ( asString === 'false' ) { return false ; } return defaultValue ; } ; param { string } string return export const toType = ( value ) => { if ( ! R . is ( String , value ) ) { return value ; } const lowerCase = value . toLowerCase ( ) . trim ( ) ; if ( lowerCase === 'true' ) { return true ; } if ( lowerCase === 'false' ) { return false ; } const num = toNumber ( lowerCase ) ; if ( R . is ( Number , num ) ) { return num ; } return value ; } ;