npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wcagpalette

v1.0.3

Published

Color palette tool for WCAG 2.1 compliant colors. Finds colors meeting the luminance ratio for any WCAG 2.1 standard, while preserving tone.

Downloads

1

Readme

wcagpalette

wcagpalette is a color conversion library for JavaScript and node.

This library provides a method for finding a color with a specific contrast ratio to another color and that matches the hue and saturation of the first.

Example

const { getContrastingHex } = require('wcagpalette');

const hex1 = getContrastingHex("#7524B7", "#7524B7", 4.5);
const hex2 = getContrastingHex("#7524B7", "#7524B7", "AA_text");

// hex1 = hex2 = "#D9BBF2" (contrast ratio = 4.58)
// the next lighter shade is "#DFBFF3" (contrast ratio = 4.79)
// the next darker shade is "#DAB6F1" (contrast ratio = 4.44)

const hex3 = getContrastingHex("#6D6D6D", 7);

// hex3 = null
// #000000 (black) has a contrast ratio of 4.05
// #FFFFFF (white) has a contrast ratio of 5.17
// thus, no color has sufficient contrast

API

getContrastingHex(color, contrastRatio)

Params

fixedColor

  • definition: the color you want to contrast against
  • type: string
  • pattern: /^#[\da-fA-F]{6}/
  • examples: "#db1f90", "#ffffff", "#123456"

alterColor

  • definition: the color you want to be altered into a lighter/darker color with the same hue and saturation
  • type: string
  • pattern: /^#[\da-fA-F]{6}/
  • examples: "#db1f90", "#ffffff", "#123456"

contrastRatio

  • definition: the minimum contrast ration between your fixedColor and the function's output color see w3 glossary definition here
  • type: number | string
  • default value: "AA" (equivilent to 3)
  • examples: 3, "AA", "AA_text", "AA_text_large", "AAA_text", "AAA_text_large";

Install

$ npm install wcagpalette

Contribute

If there is a new methods you would like to support, please make a pull request or reach out.

License

Licensed under the MIT License.

More info

  • https://www.w3.org/TR/WCAG21/#dfn-relative-luminance
  • https://www.w3.org/WAI/WCAG21/Techniques/general/G18
  • https://webaim.org/resources/contrastchecker/