Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

wcag-contrast

tmcw269.3kBSD-2-Clause3.0.0TypeScript support: definitely-typed

evaluate the wcag color contrast score for two colors

color, contrast, wcag

readme

wcag color contrast

CircleCI

This module produces WCAG contrast ratio measurement and scoring. It's an accessibility standard, intended to make sure websites have high enough contrast to be readable by everyone, including people with low vision and age-related vision problems. This module is a low-level utility, useful for its implementation of the underlying math: to test a page, you'll want to use something like Google Chrome’s Lighthouse tools, or the axe extension for Chrome and Firefox.

I (personally, speaking as Tom) have doubts about the universality, accuracy, and application of this particular standard. High contrast is a good value, but I argue that the standard is over-strict and doesn't precisely match human perception.

API

luminance

Get the contrast ratio between two relative luminance values

Parameters

Examples

luminance(1, 1); // = 1

Returns number contrast ratio

rgb

Get a score for the contrast between two colors as rgb triplets

Parameters

Examples

rgb([0, 0, 0], [255, 255, 255]); // = 21

Returns number contrast ratio

hex

Get a score for the contrast between two colors as hex strings

Parameters

Examples

hex('#000', '#fff'); // = 21

Returns number contrast ratio

score

Get a textual score from a numeric contrast value

Parameters

Examples

score(10); // = 'AAA'

Returns string score

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

3.0.0 (2019-11-05)

⚠ BREAKING CHANGES

  • alters the output of failing tests. If you're using the empty string as a failure status, please adjust to looking for 'Fail' instead.

This adds AA Large from 3-4.5 and returns 'Fail' when under 3 now. The empty string I think could be misconstrued as an error, since the output is not explicit.

Features

2.1.2-0 (2018-09-24)

2.1.1 (2018-09-24)

2.1.0 (2018-08-20)

Features

2.0.0 (2018-08-20)

Features

  • use microbundle, switch from tap to tape, improve structure (3db73e2)

BREAKING CHANGES

  • new entry points, dependencies now bundled.

1.2.0 (2018-04-16)

Bug Fixes

  • Move esm dependency out of devDeps (26a1553)

Features

  • Internalize hexRgb dependency, making this and its dependents all es6-safe (def207c)

1.1.0 (2018-03-21)

Features

  • Internalize hexRgb dependency, making this and its dependents all es6-safe (95a16e9)

1.0.0 (2018-03-21)

Bug Fixes

  • package: update relative-luminance to version 1.0.0 (59d9229)

0.1.2-0 (2018-03-21)

0.1.1 (2018-01-10)

Bug Fixes

  • package: update hex-rgb to version 2.0.0 (2ef3eb7)
  • package: update relative-luminance to version 0.0.1 (497542e)

0.1.0

  • Add hex(a, b) method