2.1.1 • Published 5 days ago

@chriscodesthings/rgb-color-is-dark v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 days ago

rgb-color-is-dark Test workflow status NPM Version License: MIT

Determine if a color in RGB format is dark using YIQ calculation

Description

Determine if a colour is dark using the YIQ calculation.

See...


Install

npm install --save @chriscodesthings/rgb-color-is-dark

Usage

import rgbColorIsDark from '@chriscodesthings/rgb-color-is-dark';

console.log(rgbColorIsDark([100, 149, 237])); // cornflowerblue
// => false

Syntax

rgbColorIsDark([r, g, b, (a)]);

Parameters

  • r, g, b: Red, green and blue color components
  • a (optional): Alpha value is ignored if present

Return Value

Returns boolean true if color is dark based on YIQ calculation, false otherwise.

Examples

// get contrasting text colour for a given background colour
function getTextColourForBackground(r, g, b) {
    if( rgbColorIsDark([r, g, b])) {
        // colour is dark, return white
        return [255, 255, 255];
    }

    // colour is light, return black
    return [0, 0, 0];
} 

See Also...

2.1.1

5 days ago

2.1.0

20 days ago

2.0.1

2 months ago

2.0.0

2 months ago

1.0.0

2 months ago