MCPcopy
hub / github.com/socketio/socket.io / getUsernameColor

Function getUsernameColor

examples/chat/public/main.js:176–185  ·  view source on GitHub ↗
(username)

Source from the content-addressed store, hash-verified

174
175 // Gets the color of a username through our hash function
176 const getUsernameColor = (username) => {
177 // Compute hash code
178 let hash = 7;
179 for (let i = 0; i < username.length; i++) {
180 hash = username.charCodeAt(i) + (hash << 5) - hash;
181 }
182 // Calculate color
183 const index = Math.abs(hash % COLORS.length);
184 return COLORS[index];
185 }
186
187 // Keyboard events
188

Callers 1

addChatMessageFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected