Last active
June 5, 2017 00:42
-
-
Save webinista/505b5443f6e224cf1185e8ade77a765f to your computer and use it in GitHub Desktop.
Expand a 3-character hex string (beginning with #) into a 6 character one
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
export function expandRGB(string) { | |
if(!(/#[a-f0-9]{3}$/i).test(string)) return string; | |
const rgb = string.split(''); | |
return `#${rgb[1]}${rgb[1]}${rgb[2]}${rgb[2]}${rgb[3]}${rgb[3]}`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment