redux-devtools/packages/redux-devtools-log-monitor/src/brighten.js

17 lines
436 B
JavaScript
Raw Normal View History

export default function(hexColor, lightness) {
let hex = String(hexColor).replace(/[^0-9a-f]/gi, '');
if (hex.length < 6) {
hex = hex.replace(/(.)/g, '$1$1');
}
let lum = lightness || 0;
let rgb = '#';
let c;
for (let i = 0; i < 3; ++i) {
c = parseInt(hex.substr(i * 2, 2), 16);
2019-01-10 21:51:14 +03:00
c = Math.round(Math.min(Math.max(0, c + c * lum), 255)).toString(16);
rgb += ('00' + c).substr(c.length);
}
return rgb;
}