contrast-color
Determines the best contrast color to use. Give it a background color and it returns a foreground color (black or white by default but customizable).
FYI
Installation
$ npm install contrast-color
Usage
const ContrastColor = require('contrast-color');
const cc = new ContrastColor({
bgColor: "navy",
fgDarkColor: "navy",
fgLightColor: "water",
customNamedColors: {
water: "#00D0FF",
},
});
const defaultFgColor = cc.contrastColor();
const hasAquaBgColor = cc.contrastColor({ bgColor: "aqua" });
const { contrastColor } = require('contrast-color');
const hasRedBg = contrastColor({ bgColor: '#f00' });
const hasRedBgWithBlackFg = contrastColor({ bgColor: '#f00', threshold: 76 });
const hasYellowBg = contrastColor({ bgColor: 'yellow' });
const hasWhiteBgWithGreenFg = contrastColor({ fgDarkColor: '#008000' });
const hasBlackBgWithLimeFg = contrastColor({ bgColor: '#000000', fgLightColor: 'lime' });
const hasKitchenSink = contrastColor({
bgColor: '#808080',
fgDarkColor: 'dirty',
fgLightColor: 'clean',
threshold: 129,
customNamedColors: {
dirty: '#f90',
clean: '#ff99ff'
}
});
API
ContrastColor(defaults)
.contrastColor(options)
License
ISC © Buster Collings