Skip to content

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 .

License

Notifications You must be signed in to change notification settings

gion/is-dark-color

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: this is why I needed this

Installation

npm i -S is-dark-color

Usage

es6 snippet

import isDarkColor from 'is-dark-color'

// obvious
const whiteIsDark = isDarkColor('#ffffff') // false
const blackIsDark = isDarkColor('#000000') // true

const someColor = '#ff9900' // some sort of orange
console.log(isDarkColor(someColor)) // try it to find out

Optionally, you can override the return value for certain colors:

import isDarkColor from 'is-dark-color'

const options = {
  override: {
    '#319FB5': true,
    '#383939': false,
  }
}

isDarkColor('#319FB5') // false
isDarkColor('#319FB5', options) // true

Credits

Inspired from

LICENCE

MIT

About

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 .

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published