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
| // Based on Gist by DutchGhost | |
| // https://gist.github.com/DutchGhost/d8604a3c796479777fe9f5e25d855cfd | |
| // Changes: | |
| // - Conditional compilation to support either 64 or 32-bit | |
| // - Added panic error message | |
| // - Added convenience function parse_unwrap | |
| // - Added tests | |
| #![feature(const_if_match)] | |
| #![feature(const_panic)] |
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
| function getFontColorFromBackgroundColor (bgColor) { | |
| if (!bgColor.match(/#[0-9a-z]{6}/i)) { | |
| return 'white'; | |
| } | |
| const [r, g, b] = [1, 3, 5].map((o) => parseInt(bgColor.slice(o, o + 2), 16)); | |
| const greyscale = (0.2125 * r) + (0.7154 * g) + (0.0721 * b); | |
| return (greyscale > 127) ? 'black' : 'white'; | |
| } |