contrast-audit
v0.4.0
Published
Accessible contrast calculations for color systems and interfaces.
Maintainers
Readme
Contrast Audit
Accessible contrast calculations for color systems and interfaces.
contrast-audit provides small WCAG contrast utilities for RGB colors: relative luminance, contrast ratios, threshold checks, and a sensible readable-text choice.
Not published yet. It builds from source in this repository.
Usage
import { contrastRatio, meetsContrast, readableText } from "contrast-audit";
const background = { red: 245, green: 247, blue: 250 };
const foreground = readableText(background);
console.log(contrastRatio(foreground, background));
console.log(meetsContrast(foreground, background));API
| Export | Purpose |
| --- | --- |
| relativeLuminance | Calculate WCAG relative luminance. |
| contrastRatio | Calculate the 1–21 contrast ratio. |
| minimumContrast | Return the AA or AAA threshold. |
| meetsContrast | Check a foreground/background pair. |
| readableText | Choose the higher-contrast light or dark text color. |
Development
npm run buildLicense
MIT
