is-dark-color
Version:
Detects if a hex color is dark or light. It is based on the w3 documentation for color luminance: https://www.w3.org/TR/WCAG20/#relativeluminancedef
15 lines (13 loc) • 399 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
// credits go to https://stackoverflow.com/a/5624139/491075
var hexToRgb = exports.hexToRgb = function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
};