Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-dark-color

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22K
decreased by-2.13%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 06 Jul 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc