nblackburn
5/29/2019 - 8:38 AM

RGB To Hex

module.exports = (red, green, blue, preferShorthand = false) => {
    let colours = [red, green, blue].map(value => value.toString(16));
    let canBeCondensed = colours.every(value => value.charAt(0) === value.charAt(1));

    if (canBeCondensed && preferShorthand) {
        colours = colours.map(v => v.charAt(0));
    }
    
    return '#' + colours.join('');
};