is-dark-color
Detects if a hex color is dark or light. It is based on the w3 documentation for color luminance: https://www.w3.org/TR/WCAG20/#relativeluminancedef.
Useful when trying to make the text color visible on certain background colors. This is why I needed this:
Installation
npm i -S is-dark-color
Usage
es6 snippet
// obviousconst whiteIsDark = // falseconst blackIsDark = // true const someColor = '#ff9900' // some sort of orangeconsole // try it to find out
Optionally, you can override the return value for certain colors:
const options = override: '#319FB5': true '#383939': false // false // true
Credits
Inspired from
- https://stackoverflow.com/a/3943023/491075
- https://stackoverflow.com/a/5624139/491075
- https://www.w3.org/TR/WCAG20/#relativeluminancedef