Last active
November 23, 2021 13:55
-
-
Save rodmcnew/df8c753020ad0f33bca5baa034fbfd63 to your computer and use it in GitHub Desktop.
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
// Returns black or white foreground color depending on the background | |
var textColor = function (backgroundColor) { | |
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(backgroundColor); | |
if (!result) { | |
return '#000000';//Happens when not given hex | |
} | |
var shade = (parseInt(result[1], 16) + parseInt(result[2], 16) + parseInt(result[3], 16)) / 3; | |
return shade > 128 ? '#000000' : '#FFFFFF'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment