Gathering detailed insights and metrics for @roussos/contrast-checker
Gathering detailed insights and metrics for @roussos/contrast-checker
Gathering detailed insights and metrics for @roussos/contrast-checker
Gathering detailed insights and metrics for @roussos/contrast-checker
Give me an image and I give you the best color for your overlay text
npm install @roussos/contrast-checker
Typescript
Module System
Node Version
NPM Version
70.4
Supply Chain
98.8
Quality
84.5
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Built with Next.js • Fully responsive • SEO optimized • Open source ready
Total Downloads
49
Last Day
49
Last Week
49
Last Month
49
Last Year
49
MIT License
25 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Jul 29, 2025
Latest Version
0.2.6
Package Id
@roussos/contrast-checker@0.2.6
Unpacked Size
17.51 kB
Size
5.64 kB
File Count
10
NPM Version
10.9.2
Node Version
23.6.1
Published on
Jul 29, 2025
Cumulative downloads
Total Downloads
Last Day
0%
49
Compared to previous day
Last Week
0%
49
Compared to previous week
Last Month
0%
49
Compared to previous month
Last Year
0%
49
Compared to previous year
3
ColorChecker is a JavaScript utility for analyzing and comparing colors in relation to DOM elements. It computes the average color of a DOM element’s subregion (e.g. a child element) and matches it to the closest color from a provided palette based on luminance similarity.
You can include the script in your project by installing it from npm:
1npm install @roussos/contrast-checker
Create a new instance of ColorChecker and set the parent and child elements.
If you initialize the instance without the parent
option, it will try to find the closest element containing an image.
You can also initialize it without any options, but in that case, you must call the updateOptions
method manually.
1const checker = new ColorChecker({
2 child: '#childElement',
3 parent: document.querySelector('#parentElement')
4})
Use the compare
method to find the closest matching color from an array of colors.
The colors in the array MUST be in hexadecimal form.
1const closestColor = checker.compare(['#ffffff', '#d23d11', '#02004b']); 2console.log('Closest Color:', closestColor);
Use the updateOptions
method to change the provided element options.
1checker.updateOptions({
2 child: '#newChildElement',
3 parent: document.querySelector('#newParentElement')
4})
Enable debug mode to append the calculated average color to the DOM and log the results.
1const closestColor = checker.compare(['#ffffff', '#d23d11', '#02004b'], true);
ColorChecker(options)
Creates a new instance of ColorChecker.
Parameters:
Options | Type | Description |
---|---|---|
child | HTMLElement, String | The child element whose background is analyzed. |
parent | HTMLElement, String | The parent element behind the child. Must be an |
compare(color, debug)
Finds the closest matching color from the provided array.
Parameters:
Options | Type | Description |
---|---|---|
color | String[] | Array of hexadecimal colors to compare. |
debug | Boolean | Optional. If true, appends the calculated average color to the DOM. Default is false. |
Returns: The color from the array that has the most contrast to the average color of the parent element.
compareAsync(color, debug)
Same as compare
but it returns a promise with the computed color.
updateOptions(options)
Updates the instance's options with new Child and Parent elements.
Parameters:
Options | Type | Description |
---|---|---|
child | HTMLElement, String | The child element whose background is analyzed. |
parent | HTMLElement, String | The parent element behind the child. Must be an |
Returns: The ColorChecker instance, allowing method chaining.
1import ColorChecker from '@roussos/contrast-checker'; 2 3const checker = new ColorChecker({ 4 child: '#lorem', 5}) 6 7document.querySelector('#lorem').style.color = checker.compare([ 8 '#ffffff', 9 '#d23d11', 10 '#02004b' 11])
This project is licensed under the MIT License.
No vulnerabilities found.