Created
June 15, 2022 11:46
-
-
Save thybzi/72f3d2bcfde15cc26b2e29be90b5c29f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Convert #1a2b3c to { r: 26, g: 43, b: 60 } | |
* @param {string} hex | |
* @returns {*} | |
* @see https://stackoverflow.com/a/5624139 | |
*/ | |
function hexToRgb(hex) { | |
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); | |
return result ? { | |
r: parseInt(result[1], 16), | |
g: parseInt(result[2], 16), | |
b: parseInt(result[3], 16), | |
} : null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment