Created
October 21, 2021 23:28
-
-
Save a1xon/bf5ccf88f009ee27e484b8e2cb294796 to your computer and use it in GitHub Desktop.
js hex-value to hashtag notation string
This file contains 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
const hexToHashtagNotation = (hexColor) => { | |
let splittedColor = { | |
red : (hexColor >> 16) & 0xFF, | |
green : (hexColor >> 8) & 0xFF, | |
blue : hexColor & 0xFF, | |
} | |
return Object.values(splittedColor).reduce((hexString, channelValue) => { | |
const colorValueString = channelValue.toString(16).toUpperCase(); | |
hexString += colorValueString.length === 1 ? `0${colorValueString}` : `${colorValueString}`; | |
return hexString; | |
}, '#'); | |
} | |
//// 0xEDF5FC => "#EDF5FC" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment