UNPKG

685 BJavaScriptView Raw
1var nodes = require('../nodes')
2 , rgba = require('./rgba');
3
4/**
5 * Return the green component of the given `color`,
6 * or set the green component to the optional second `value` argument.
7 *
8 * Examples:
9 *
10 * green(#0c0)
11 * // => 204
12 *
13 * green(#000, 255)
14 * // => #0f0
15 *
16 * @param {RGBA|HSLA} color
17 * @param {Unit} [value]
18 * @return {Unit|RGBA}
19 * @api public
20 */
21
22function green(color, value){
23 color = color.rgba;
24 if (value) {
25 return rgba(
26 new nodes.Unit(color.r),
27 value,
28 new nodes.Unit(color.b),
29 new nodes.Unit(color.a)
30 );
31 }
32 return new nodes.Unit(color.g, '');
33};
34green.params = ['color', 'value'];
35module.exports = green;