Created
April 22, 2021 17:53
-
-
Save zhd4n/2e2fcf6b194c17fe58a9f1f54ee3dbe0 to your computer and use it in GitHub Desktop.
JS get HSL color from string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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