blue.js 678 B

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