UNPKG

@onesy/utils

Version:
15 lines (12 loc) 599 B
import is from './is'; import clamp from './clamp'; import colorToRgb from './colorToRgb'; const lighten = (value, coefficient) => { const values = colorToRgb(value, undefined, true); if (is('array', values) && values.length >= 3) { values.slice(0, 3).forEach((item, index) => values[index] += (255 - item) * clamp(coefficient, 0, 1)); const [r, g, b, a] = [...values.slice(0, 3).map(item => Math.round(Number(item))), values[3]]; return "rgb".concat(a ? 'a' : '', "(").concat(r, ", ").concat(g, ", ").concat(b).concat(a ? ", ".concat(a) : '', ")"); } }; export default lighten;