UNPKG

801 BJavaScriptView Raw
1var nodes = require('../nodes')
2 , hsla = require('./hsla')
3 , component = require('./component');
4
5/**
6 * Return the saturation component of the given `color`,
7 * or set the saturation component to the optional second `value` argument.
8 *
9 * Examples:
10 *
11 * saturation(#00c)
12 * // => 100%
13 *
14 * saturation(#00c, 50%)
15 * // => #339
16 *
17 * @param {RGBA|HSLA} color
18 * @param {Unit} [value]
19 * @return {Unit|RGBA}
20 * @api public
21 */
22
23function saturation(color, value){
24 if (value) {
25 var hslaColor = color.hsla;
26 return hsla(
27 new nodes.Unit(hslaColor.h),
28 value,
29 new nodes.Unit(hslaColor.l),
30 new nodes.Unit(hslaColor.a)
31 )
32 }
33 return component(color, new nodes.String('saturation'));
34}
35saturation.params = ['color', 'value'];
36module.exports = saturation;