index.js 740 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var color = require('color')
  3. , hex = require('text-hex');
  4. /**
  5. * Generate a color for a given name. But be reasonably smart about it by
  6. * understanding name spaces and coloring each namespace a bit lighter so they
  7. * still have the same base color as the root.
  8. *
  9. * @param {string} namespace The namespace
  10. * @param {string} [delimiter] The delimiter
  11. * @returns {string} color
  12. */
  13. module.exports = function colorspace(namespace, delimiter) {
  14. var split = namespace.split(delimiter || ':');
  15. var base = hex(split[0]);
  16. if (!split.length) return base;
  17. for (var i = 0, l = split.length - 1; i < l; i++) {
  18. base = color(base)
  19. .mix(color(hex(split[i + 1])))
  20. .saturate(1)
  21. .hex();
  22. }
  23. return base;
  24. };