Guest User

Untitled

a guest
May 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. const hexToRgb = hex => {
  2. const extendHex = shortHex =>
  3. '#' + shortHex.slice(shortHex.startsWith('#') ? 1 : 0).split('').map(x => x+x).join('');
  4. const extendedHex = hex.slice(hex.startsWith('#') ? 1 : 0).length === 3 ? extendHex(hex) : hex;
  5. return `rgb(${parseInt(extendedHex.slice(1), 16) >> 16}, ${(parseInt(extendedHex.slice(1), 16) & 0x00ff00) >> 8}, ${parseInt(extendedHex.slice(1), 16) & 0x0000ff})`;
  6. }
  7. // hexToRgb('#27ae60') -> 'rgb(39, 174, 96)'
  8. // hexToRgb('#acd') -> 'rgb(170, 204, 221)'
Add Comment
Please, Sign In to add comment