Numeric Production Mechanism

    wcag-contrast
    DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/wcag-contrast package

    3.0.0 • Public • Published

    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

    Install

    npm i wcag-contrast

    DownloadsWeekly Downloads

    15,433

    Version

    3.0.0

    License

    BSD-2-Clause

    Unpacked Size

    25 kB

    Total Files

    11

    Last publish

    Collaborators

    • tmcw