Hue check is a lightweight library for checking color contrast and generating accessible color palettes.
- Determines if the contrast ratio between two colors meets the specified WCAG accessibility level.
- Returns:
trueif the contrast ratio meets the specified WCAG level.falseif it doesn’t meet the level.undefinedif the input colors are invalid.
- Generates an array of CSS named colors that meet the specified contrast ratio requirements with a given color.
- Returns:
- An array of CSS named colors.
- Calculates the contrast ratio between two colors.
- Returns:
- The contrast ratio between the two colors.
undefinedif the input colors are invalid.
- Converts a hex color code to its corresponding CSS named color.
- Returns:
- The CSS named color if found, otherwise
undefined.
- The CSS named color if found, otherwise
- An object containing all css named colors as keys and the corresponding hex codes as values.
import { contrastColors, contrastRatio, isRatioOk } from 'hue-check';
const sufficentRatio = isRatioOk('papayawhip', '#000'); // true
const contrastColor = contrastColors('papayawhip')?.[0] ?? ''; // "black"
const ratio = contrastRatio('white', '#000000'); // 21
const colorName = hexToNamedColor('#fff'); // "white"Create a branch on your fork, add commits to your fork, and open a pull request from your fork to this repository.
To check full changelog click here