import random from 'lodash.random' ; export function getRandomPairOfColors ( ) { const colors = [ '#37B679' , '#DA3C3C' , '#3291FF' , '#7928CA' , '#79FFE1' ] ; const getRandomIdx = ( ) => random ( 0 , colors . length - 1 ) ; let idx = getRandomIdx ( ) ; let idx2 = getRandomIdx ( ) ; while ( idx2 === idx ) { idx2 = getRandomIdx ( ) ; } return [ colors [ idx ] , colors [ idx2 ] ] ; } function hexToRgb ( hex = '' ) { const match = hex . toString ( 16 ) . match ( /[a-f0-9]{6}|[a-f0-9]{3}/i ) ; if ( ! match ) { return [ 0 , 0 , 0 ] ; } let colorString = match [ 0 ] ; if ( match [ 0 ] . length === 3 ) { colorString = colorString . split ( '' ) . map ( ( char ) => { return char + char ; } ) . join ( '' ) ; } const integer = parseInt ( colorString , 16 ) ; const r = ( integer >> 16 ) & 0xff ; const g = ( integer >> 8 ) & 0xff ; const b = integer & 0xff ; return [ r , g , b ] ; } export function isDark ( color = '' ) { const rgb = hexToRgb ( color . toLowerCase ( ) ) ; const res = ( rgb [ 0 ] * 299 + rgb [ 1 ] * 587 + rgb [ 2 ] * 114 ) / 1000 ; return res < 128 ; }