Skip to content

Instantly share code, notes, and snippets.

@quocble
Created July 25, 2016 19:46
Show Gist options
  • Save quocble/2be2d646a7df2d892b0650a90b9351a0 to your computer and use it in GitHub Desktop.
Save quocble/2be2d646a7df2d892b0650a90b9351a0 to your computer and use it in GitHub Desktop.
converts 3 hex into 6 hex
// converts 3 hex into 6 hex
function normalizeHex(hex) {
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
return '#' + r + r + g + g + b + b;
});
return hex;
}
console.log(normalizeHex("#F3F3F3"));
console.log(normalizeHex("#F22"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment