Skip to content

bpetermann/hue-check

Repository files navigation

🎨 Hue Check · NPM version npm-typescript GitHub License NPM Downloads

Hue check is a lightweight library for checking color contrast and generating accessible color palettes.

Features

➡️ 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.

➡️ 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.

➡️ contrastRatio

  • Calculates the contrast ratio between two colors.
  • Returns:
    • The contrast ratio between the two colors.
    • undefined if the input colors are invalid.

➡️ hexToNamedColor

  • Converts a hex color code to its corresponding CSS named color.
  • Returns:
    • The CSS named color if found, otherwise undefined.

➡️ 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

License

MIT

About

Check color contrast and generate accessible palettes

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •