Skip to content

Instantly share code, notes, and snippets.

@webinista
Last active June 5, 2017 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webinista/505b5443f6e224cf1185e8ade77a765f to your computer and use it in GitHub Desktop.
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
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