Gathering detailed insights and metrics for color-contrast-checker2
Gathering detailed insights and metrics for color-contrast-checker2
Gathering detailed insights and metrics for color-contrast-checker2
Gathering detailed insights and metrics for color-contrast-checker2
A lightweight npm package to check if two colors meet WCAG (Web Content Accessibility Guidelines) contrast guidelines.
npm install color-contrast-checker2
Typescript
Module System
Node Version
NPM Version
66.5
Supply Chain
98
Quality
76.9
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
120
Last Day
4
Last Week
10
Last Month
17
Last Year
120
2 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Mar 06, 2025
Minified
Minified + Gzipped
Latest Version
1.0.1
Package Id
color-contrast-checker2@1.0.1
Unpacked Size
6.64 kB
Size
2.37 kB
File Count
3
NPM Version
10.7.0
Node Version
20.15.0
Published on
Mar 06, 2025
Cumulative downloads
Total Downloads
Last Day
0%
4
Compared to previous day
Last Week
42.9%
10
Compared to previous week
Last Month
21.4%
17
Compared to previous month
Last Year
0%
120
Compared to previous year
1
A lightweight npm package to check if two colors meet WCAG (Web Content Accessibility Guidelines) contrast guidelines. It supports various color formats and provides functions to calculate relative luminance and contrast ratio.
Install the package using npm:
npm install color-contrast-checker2
const { isAccessible } = require("color-contrast-checker");
// Check if two colors meet WCAG AA guidelines
console.log(isAccessible("#000000", "#ffffff")); // true
console.log(isAccessible("#000000", "#111111")); // false
// Check for WCAG AAA
console.log(isAccessible("#000000", "#ffffff", "AAA")); // true
// Check for WCAG AA_LARGE
console.log(isAccessible("#000000", "#333333", "AA_LARGE")); // true
// Check for WCAG AAA_LARGE
console.log(isAccessible("#000000", "#666666", "AAA_LARGE")); // false
const { getRelativeLuminance, getContrastRatio, isAccessible } = require("color-contrast-checker");
// Calculating relative luminance
const luminance = getRelativeLuminance("#ff0000"); // Red
console.log(luminance); // 0.2126
// Calculating contrast ratio
const contrastRatio = getContrastRatio("#000000", "#ffffff");
console.log(contrastRatio); // 21
// Checking accessibility with custom level
const accessible = isAccessible("#000000", "#ffffff", "AAA");
console.log(accessible); // true
isAccessible(color1, color2, level)
Checks if two colors meet the specified WCAG contrast level.
color1
: The first color.color2
: The second color.level
(string): The WCAG level ("AA"
, "AAA"
, "AA_LARGE"
, or "AAA_LARGE"
). Defaults to "AA"
.true
if the contrast is sufficient, false
otherwise.getRelativeLuminance(color)
Calculates the relative luminance of a color.
color
: The color in any valid format.0
(black) and 1
(white).getContrastRatio(color1, color2)
Calculates the contrast ratio between two colors.
color1
: The first color.color2
: The second color.The package supports a wide variety of color formats as listed below:
#fff
, fff
#ffffff
, ffffff
#ffffff80
, ffffff80
rgb(255, 0, 0)
, rgb 255 0 0
, rgb(100%, 0%, 0%)
rgba(255, 0, 0, 0.5)
, rgba(100%, 0%, 0%, 0.5)
{ r: 255, g: 0, b: 0 }
, { r: 255, g: 0, b: 0, a: 0.5 }
{ r: 1, g: 0, b: 0 }
, { r: 1, g: 0, b: 0, a: 0.5 }
hsl(0, 100%, 50%)
, hsl 0 100% 50%
, hsl(0, 1.0, 0.5)
hsla(0, 100%, 50%, 0.5)
, hsla(0, 1.0, 0.5, 0.5)
{ h: 0, s: 100, l: 50 }
, { h: 0, s: 100, l: 50, a: 0.5 }
{ h: 1, s: 0, l: 0 }
, { h: 1, s: 0, l: 0, a: 0.5 }
hsv(0, 100%, 100%)
, hsv 0 100% 100%
, hsv(0, 1.0, 1.0)
hsva(0, 100%, 100%, 0.5)
, hsva(0, 1.0, 1.0, 0.5)
{ h: 0, s: 100, v: 100 }
, { h: 0, s: 100, v: 100, a: 0.5 }
{ h: 1, s: 0, v: 0 }
, { h: 1, s: 0, v: 0, a: 0.5 }
red
, blue
, green
, blanchedalmond
, darkblue
, etc.0xff0000
(red)0xff000080
(red with 50% transparency)0%-100%
or 0-1
.0%-100%
or 0-360
.0-255
or 0%-100%
.No vulnerabilities found.
No security vulnerabilities found.