Created
July 25, 2016 19:46
-
-
Save quocble/2be2d646a7df2d892b0650a90b9351a0 to your computer and use it in GitHub Desktop.
converts 3 hex into 6 hex
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
// 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