const typeString = 'Boolean Number String Function Array Date RegExp Object Error Symbol' ; const class2type = { } ; typeString . split ( ' ' ) . forEach ( ( type ) => { class2type [ `[object ${ type }]` ] = type . toLowerCase ( ) ; } ) ; export function type ( object ) { const type = class2type . toString . call ( object ) ; if ( object === null ) return object + '' ; if ( Number . isNaN ( object ) ) return 'NaN' ; const isObject = typeof object === 'object' ; const isFn = typeof object === 'function' ; return isObject || isFn ? class2type [ type ] || 'object' : typeof object ; } export const is = { primitive ( tar ) { return [ 'string' , 'number' ] . includes ( type ( tar ) ) ; } , array ( tar ) { return type ( tar ) === 'array' ; } , str ( tar ) { return type ( tar ) === 'string' ; } , obj ( tar ) { return type ( tar ) === 'object' ; } , arr ( tar ) { return type ( tar ) === 'array' ; } , num ( tar ) { return type ( tar ) === 'number' ; } , fn ( tar ) { return type ( tar ) === 'function' ; } , undef ( tar ) { return type ( tar ) === 'undefined' ; } , def ( tar ) { return ! is . undef ( tar ) ; } , null ( tar ) { return type ( tar ) === 'null' ; } , empty ( tar ) { const t = type ( tar ) ; switch ( t ) { case 'object' : return Object . keys ( tar ) . length === 0 ; case 'array' : return tar . length === 0 ; case 'string' : return ! ( tar . trim ( ) ) ; case 'undefined' : case 'null' : case 'NaN' : case 'boolean' : return true ; default : return false ; } } , Nil ( tar ) { return [ 'null' , 'undefined' ] . includes ( type ( tar ) ) ; } , NaN ( tar ) { return type ( tar ) === 'NaN' ; } , promise ( tar ) { return ! ! tar && ( is . obj ( tar ) || is . fn ( tar ) ) && is . fn ( tar [ 'then' ] ) ; } } ;