Created
May 29, 2019 08:38
-
-
Save nblackburn/9bd24959f148cb046ae4206502916358 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(''); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment