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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@weable-tools/a11y-color-utils

v0.1.1

Published

Core utilities for web accessibility color analysis and manipulation (WCAG Contrast, Color Fixing, Palette Generation). Includes license verification.

Downloads

315

Readme

@weable-tools/a11y-color-utils

Version: 0.1.1

Overview

A standalone JavaScript/TypeScript library providing core functions for web accessibility color analysis and manipulation. Designed for developers and teams needing robust, reliable color accessibility logic in their own applications or design systems.

Built on the SACA principles of resilience, reusability, and self-contained value.

Requires initialization with a license key.

Key Features (Mini-Rangers)

  • WCAG Contrast Calculation: calculateContrastRatio()
  • Contrast Compliance Check: checkContrast() (AA/AAA)
  • Relative Luminance Calculation: calculateLuminance()
  • APCA Calculation: calculateAPCA() (Supports newer contrast model).
  • Intelligent Color Fixing:
    • findMinLightnessAdjustment(): Finds minimum visual change (DeltaE) to meet contrast.
    • fixWorstContrastPair(): Analyzes and fixes the most problematic color pair in a palette.
  • Basic Palette Generation: generatePalette() (Generates scheme from base color using chroma-js scale).
  • Color Manipulation: lightenColor(), darkenColor(), shiftHue(), adjustSaturation()
  • Color Conversion: hexToRgb(), rgbToHex()
  • Color Difference: deltaE() (Calculates DeltaE 2000).

Use Cases

  • Integrating accessibility checks into design tools or CI/CD pipelines.
  • Building custom theme generators.
  • Validating user-generated content for color compliance.
  • Powering automated accessibility auditing tools.
  • Enhancing UI development workflows.

Installation

This package is published publicly to the npm registry.

  1. Install the Package:
    npm install @weable-tools/a11y-color-utils
    # or
    yarn add @weable-tools/a11y-color-utils

Usage

First, initialize the library with your license key:

import { initLicense } from '@weable-tools/a11y-color-utils';

// Replace 'YOUR_LICENSE_KEY' with the actual key
initLicense('YOUR_LICENSE_KEY'); 

Then, use the exported functions:

import {
    checkContrast,
    fixWorstContrastPair,
    calculateLuminance,
    calculateAPCA,
    generatePalette,
    hexToRgb,
    deltaE
} from '@weable-tools/a11y-color-utils';

// Check WCAG Contrast
const { ratio, pass } = checkContrast('#FFFFFF', '#757575', 4.5); // Check white on grey for AA
console.log(`WCAG Contrast: ${ratio}, Passes AA: ${pass}`); // Output: WCAG Contrast: 4.54, Passes AA: true

// Check APCA Contrast
const apcaScore = calculateAPCA('#000000', '#FFFFFF'); // Black text on white bg
console.log(`APCA Score (Lc): ${apcaScore?.toFixed(1)}`); // Output: APCA Score (Lc): 106.X

// Calculate Luminance
const lum = calculateLuminance('#808080');
console.log(`Luminance of grey: ${lum.toFixed(3)}`); // Output: Luminance of grey: 0.216

// Fix a palette
const myPalette = ['#FFFFFF', '#000000', '#888888', '#777777']; // Contains a low-contrast pair (#777 vs #888)
const { fixedPalette, changedIndex, newColor, fixed } = fixWorstContrastPair(myPalette, 4.5);
if (fixed) {
  console.log(`Palette fixed! Index ${changedIndex} changed to ${newColor}`);
  console.log('New Palette:', fixedPalette);
}

// Generate a palette
const base = '#3366CC';
const palette = generatePalette(base, 5);
console.log(`Generated 5 colors from ${base}:`, palette);

// Convert Hex to RGB
const rgb = hexToRgb('#FF8C00'); // DarkOrange
console.log('#FF8C00 in RGB:', rgb); // Output: #FF8C00 in RGB: [ 255, 140, 0 ]

// Calculate Color Difference
const diff = deltaE('#FF0000', '#FE0000'); // Very similar reds
console.log(`DeltaE between #FF0000 and #FE0000: ${diff.toFixed(2)}`); // Output: DeltaE between #FF0000 and #FE0000: 0.XX (very small)

Contributing

Contributions are welcome! Please follow standard GitHub flow (fork, feature branch, pull request).

License

MIT License (See LICENSE file for details).