Skip to content

Instantly share code, notes, and snippets.

@a1xon
Created October 21, 2021 23:28
Show Gist options
  • Save a1xon/bf5ccf88f009ee27e484b8e2cb294796 to your computer and use it in GitHub Desktop.
Save a1xon/bf5ccf88f009ee27e484b8e2cb294796 to your computer and use it in GitHub Desktop.
js hex-value to hashtag notation string
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