import stringToHashCode from './string-to-hash-code'; /** * Returns a hexadecimal color code for a string. * @param {string} string a string * @returns {string} a hex color code for the given string */ function stringToColor(string: string) { let color = '#'; const hash = stringToHashCode(string); for (let i = 0; i < 3; i++) { const value = (hash >> (i * 8)) & 0xff; color += `00${value.toString(16)}`.slice(-2); } return color; } export default stringToColor;