param { any } param param { ... string } types return { boolean } export const isExpectType = ( param , ... types ) : boolean => { return types . some ( type => Object . prototype . toString . call ( param ) . slice ( 8 , - 1 ) . toLowerCase ( ) === type ) ; } ; param { string } str return { string } export const removeEnter = ( str ) : string => { return [ ] . filter . call ( str , s => s !== '\n' ) . join ( '' ) ; } ; param num export const getNumber = ( num ) : number => { if ( num === null ) return 0 ; if ( typeof num === 'object' ) return NaN ; if ( typeof num === 'number' ) return num ; if ( typeof num === 'string' ) { if ( num [ num . length - 1 ] === '%' ) { return Number ( num . slice ( 0 , - 1 ) ) / 100 ; } return Number ( num ) ; } return NaN ; } ; param color export const hasBackground = ( color ) : boolean => { if ( typeof color !== 'string' ) return false ; color = color . toLocaleLowerCase ( ) . trim ( ) ; if ( color === 'transparent' ) return false ; if ( /^rgba/ . test ( color ) ) { const alpha = /([^\s,]+)\)$/ . exec ( color ) ; if ( getNumber ( alpha ) === 0 ) return false ; } return true ; } ; return { object } export const computePadding = ( block ) : [ number , number , number , number ] => { let padding = block . padding ?. replace ( /px/g , '' ) . split ( ' ' ) . map ( n => ~ ~ n ) || [ 0 ] , paddingTop = 0 , paddingBottom = 0 , paddingLeft = 0 , paddingRight = 0 ; switch ( padding . length ) { case 1 : paddingTop = paddingBottom = paddingLeft = paddingRight = padding [ 0 ] ; break ; case 2 : paddingTop = paddingBottom = padding [ 0 ] ; paddingLeft = paddingRight = padding [ 1 ] ; break ; case 3 : paddingTop = padding [ 0 ] ; paddingLeft = paddingRight = padding [ 1 ] ; paddingBottom = padding [ 2 ] ; break ; default : paddingTop = padding [ 0 ] ; paddingBottom = padding [ 1 ] ; paddingLeft = padding [ 2 ] ; paddingRight = padding [ 3 ] ; } const res = { paddingTop , paddingBottom , paddingLeft , paddingRight } ; for ( let key in res ) { res [ key ] = Object . prototype . hasOwnProperty . call ( block , key ) && isExpectType ( block [ key ] , 'string' , 'number' ) ? ~ ~ String ( block [ key ] ) . replace ( /px/g , '' ) : res [ key ] ; } return [ paddingTop , paddingBottom , paddingLeft , paddingRight ] ; } ;