Socket
Socket
Sign inDemoInstall

@mdhnpm/wcag-contrast-checker

Package Overview
Dependencies
2
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @mdhnpm/wcag-contrast-checker

A module to access the color contrast between background and foreground based on Web Contenet Accessibility Guideline (WCAG).


Version published
Maintainers
1
Created

Readme

Source

wcag-contrast-checker

A module to access the color contrast between background and foreground based on Web Contenet Accessibility Guideline (WCAG).

This tool takes two inputs (foreground and background color) and return the results according to the documentation here

WCAG 2.0 level AA requires a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text. WCAG 2.1 requires a contrast ratio of at least 3:1 for graphics and user interface components (such as form input borders). WCAG Level AAA requires a contrast ratio of at least 7:1 for normal text and 4.5:1 for large text.

Large text is defined as 14 point (typically 18.66px) and bold or larger, or 18 point (typically 24px) or larger.

Usage

wcagContrastChecker takes two arguments:

  • foregroundColor: a hexadecimal string (with or without #) or an array of RBG.
  • backgroundColor: a hexadecimal string (with or without #) or an array of RBG.
import { wcagContrastChecker } from '@mdhnpm/wcag-contrast-checker';

wcagContrastChecker('11AA55', 'AA8811');

wcagContrastChecker('#E9FAF5', '#FFFFFF');

wcagContrastChecker([0, 0, 0], [255, 255, 255]);

Output

It will return the result object to inform if the test passed for each criteria as below. The below example is when the ratio is 3.95.

expectedOutput: {
  regularText: {
    aa: false,
    aaa: false,
  },
  largeText: {
    aa: true,
    aaa: false,
  },
  uiComponent: {
    aa: true
  }
}

FAQs

Last updated on 27 Feb 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc