🚀 Socket Launch Week 🚀 Day 5: Introducing Socket Fix.Learn More
Socket
Sign inDemoInstall
Socket

contrast

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contrast

Determine if the given color is light or dark

1.0.1
latest
Source
npm
Version published
Weekly downloads
2.9K
-47.28%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

background

FAQs

Package last updated on 01 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts