import parseToRgba from './parseToRgba' ; import guard from './guard' ; /**
 * Takes in any color and returns it as a hex code.
 */ function toHex ( color ) { const [ r , g , b , a ] = parseToRgba ( color ) ; let hex = ( x ) => { const h = guard ( 0 , 255 , x ) . toString ( 16 ) ; return h . length === 1 ? `0${ h }` : h ; } ; return `#${ hex ( r ) }${ hex ( g ) }${ hex ( b ) }${ a < 1 ? hex ( Math . round ( a * 255 ) ) : '' }` ; } export default toHex ;