Skip to content

Instantly share code, notes, and snippets.

@kirpalmakanga
Last active October 19, 2018 12:55
Show Gist options
  • Save kirpalmakanga/76dc25f1754f9f06a56df0ee56f39f2b to your computer and use it in GitHub Desktop.
Save kirpalmakanga/76dc25f1754f9f06a56df0ee56f39f2b to your computer and use it in GitHub Desktop.
hex to RGBA
const parseHex = (hex) => (startChar, endChar) =>
parseInt(hex.slice(startChar, endChar), 16);
function hexToRGBA(hex, a = 1) {
const r = parseHex(hex)(1, 3);
const g = parseHex(hex)(3, 5);
const b = parseHex(hex)(5, 7);
return `rgba(${r},${g},${b},${a})`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment