UNPKG

@onesy/utils

Version:
15 lines (12 loc) 583 B
import is from './is'; import clamp from './clamp'; import colorToRgb from './colorToRgb'; const darken = (value, coefficient) => { const values = colorToRgb(value, undefined, true); if (is('array', values) && values.length >= 3) { values.slice(0, 3).forEach((_, index) => values[index] *= 1 - 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 darken;