1.2.0 • Published 6 months ago
hue-check v1.2.0
:art: Hue Check ·

Hue check is a lightweight library for checking color contrast and generating accessible color palettes.
Features
:arrow_right: isRatioOk
- Determines if the contrast ratio between two colors meets the specified WCAG accessibility level.
- Returns:
true
if the contrast ratio meets the specified WCAG level.false
if it doesn’t meet the level.undefined
if the input colors are invalid.
:arrow_right: contrastColors
- 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.
:arrow_right: contrastRatio
- Calculates the contrast ratio between two colors.
- Returns:
- The contrast ratio between the two colors.
undefined
if the input colors are invalid.
:arrow_right: hexToNamedColor
- 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
:arrow_right: cssNamedColors
- An object containing all css named colors as keys and the corresponding hex codes as values.
Example
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"
Contributing
Create a branch on your fork, add commits to your fork, and open a pull request from your fork to this repository.
Changelog
To check full changelog click here