contrast

1.0.1 • Public • Published

contrast

Determine if the given color is light or dark.

This is useful for dynamically deciding which color a foreground color should be when placed over a given background color.

Install

npm install contrast --save

Usage

var contrast = require('contrast');
 
var el = document.querySelector('#some-element');
var bgColor = e.style.backgroundColor;
 
if (contrast(bgColor) === 'light') {
  textColor = '#000';
}
else {
  textColor = '#fff'
}
 
el.style.color = textColor;

Run Tests

npm install
npm test

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    6,082
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    6,082
  • 1.0.0
    1

Package Sidebar

Install

npm i contrast

Weekly Downloads

6,083

Version

1.0.1

License

MIT

Last publish

Collaborators

  • scottcorgan