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