export const isLight = ( color ) : boolean => { let r ; let g ; let b ; if ( color . match ( /^rgb/ ) ) { const rgbComponents = color . match ( /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/ ) ; [ r , g , b ] = rgbComponents as RegExpMatchArray ; } else { const hexColor = color ; const colorRgb = + `0x${ hexColor . slice ( 1 ) . replace ( hexColor . length < 5 && /./g , '$&$&' ) }` ; r = colorRgb >> 16 ; g = ( colorRgb >> 8 ) & 255 ; b = colorRgb & 255 ; } const hsp = Math . sqrt ( 0.299 * ( r * r ) + 0.587 * ( g * g ) + 0.114 * ( b * b ) ) ; return hsp > 127.5 ; } ;