hex-contrast-color

Return a contrasting hex text color for a specific hex background color

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
hex-contrast-color
1.0.16 years ago6 years agoMinified + gzip package size for hex-contrast-color in KB

Readme

hex-contrast-color
Javascript utility for getting a contrasting hex color string (#ffffff or #000000) based on a supplied hex color string.
The function accepts full 6 character strings and 3 character shorthand strings. Returns null if supplied value is not a correct hex color string.

Node

Install

npm install --save hex-contrast-color

var hexContrastColor = require('hex-contrast-color');

hexContrastColor('#000000')
> '#ffffff'
hexContrastColor('#ffffff')
> '#000000'
hexContrastColor('#f00')
> '#ffffff'

// Returns null if supplied value is not a correct hex color string
hexContrastColor(123);
> null
hexContrastColor(null);
> null