Skip to content

Instantly share code, notes, and snippets.

@PabloAlexandre
Last active November 17, 2020 14:35
Show Gist options
  • Save PabloAlexandre/ee8db7e29320a9babf4ce977cdd88dd8 to your computer and use it in GitHub Desktop.
Save PabloAlexandre/ee8db7e29320a9babf4ce977cdd88dd8 to your computer and use it in GitHub Desktop.
Color Generator from String
export const createColorFromName = (name, saturation = 30, lightness = 60) => {
if (name.length === 0) return hash;
const nameHash = name.split('').reduce((hash, letter, i) => {
hash = name.charCodeAt(i) + ((hash << 5) - hash)
return hash & hash
}, 0);
return `hsl(${nameHash % 360}, ${saturation}%, ${lightness}%)`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment