Skip to content

Instantly share code, notes, and snippets.

@zhd4n
Created April 22, 2021 17:53
Show Gist options
  • Select an option

  • Save zhd4n/2e2fcf6b194c17fe58a9f1f54ee3dbe0 to your computer and use it in GitHub Desktop.

Select an option

Save zhd4n/2e2fcf6b194c17fe58a9f1f54ee3dbe0 to your computer and use it in GitHub Desktop.
JS get HSL color from string
getColor(initials: string) {
let hash = 0;
for (let i = 0; i < initials.length; i++) {
hash = initials.charCodeAt(i) + ((hash << 5) - hash);
}
const h = hash % 360;
return `hsl(${h}, 30%, 65%)`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment