culori
A general-purpose color library for JavaScript
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).
hex2rgb
Converts hex color to rgb and calculates appropriate corresponding foreground.
yiq
Returns light when a color is dark and dark when a color is light (and a little more).