Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
thelounge/client/js/helpers/colorClass.ts /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
15 lines (13 sloc)
383 Bytes
This file contains 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
| // Generates a string from "color-1" to "color-32" based on an input string | |
| export default (str: string) => { | |
| let hash = 0; | |
| for (let i = 0; i < str.length; i++) { | |
| hash += str.charCodeAt(i); | |
| } | |
| /* | |
| Modulo 32 lets us be case insensitive for ascii | |
| due to A being ascii 65 (100 0001) | |
| while a being ascii 97 (110 0001) | |
| */ | |
| return "color-" + (1 + (hash % 32)).toString(); | |
| }; |