Created
February 24, 2017 09:15
-
-
Save jeystaats/7d3171b6a5310c33bbd5196a86b5e820 to your computer and use it in GitHub Desktop.
Turn a string ( username e.g ) into a RGB ( 15e5de ) . Only put the hashtag in front of it.
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
// Turn a string ( like a username , into a RGB code (15e5de) , you can use this for styling purposes per user in chat examples | |
hashCode(str) { // java String#hashCode | |
var hash = 0; | |
for (var i = 0; i < str.length; i++) { | |
hash = str.charCodeAt(i) + ((hash << 5) - hash); | |
} | |
return hash; | |
}, | |
intToRGB(i){ | |
var c = (i & 0x00FFFFFF) | |
.toString(16) | |
.toUpperCase(); | |
return "00000".substring(0, 6 - c.length) + c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment