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

color-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

color-contrast

performance-sensitive wcag contrast ratio calculation between two colors

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.3K
increased by14.3%
Maintainers
1
Weekly downloads
 
Created
Source

color-contrast

npm tests dependencies coverage

Performance-sensitive WCAG contrast ratio calculation.

Note: This project is in early development, and versioning is a little different. Read this for more details.

Why should you care?

There are several projects that give you the contrast ratio, but I was unable to find any that didn't have too many dependencies to be viable for performance-conscious browser use and were also wcag-compliant. This one is both. It's ~5kb gzipped, and supports all color formats supported by css, so no need to run any type of color conversions in or out.

Installation

npm install color-contrast

Usage

This is a very simple module, it only exposes a single export and can be used as such:

import colorContrast from 'color-contrast'

colorContrast('#fff', '#000') // => 21
colorContrast('#fff', '#eee') // => 1.1602304710270739

WCAG standards dictate that you want >=4.5 as a ratio for AA compliance and >= 7 for AAA compliance. You should aim for the latter if possible.

License & Contributing

FAQs

Package last updated on 23 Aug 2020

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