MCPcopy Create free account
hub / github.com/bvaughn/react-window / stringToColor

Function stringToColor

lib/utils/colors/stringToColor.ts:1–13  ·  view source on GitHub ↗
(string: string)

Source from the content-addressed store, hash-verified

1export function stringToColor(string: string) {
2 let hash = 0;
3 string.split("").forEach((char) => {
4 hash = char.charCodeAt(0) + ((hash << 5) - hash);
5 });
6
7 let color = "#";
8 for (let i = 0; i < 3; i++) {
9 const value = (hash >> (i * 8)) & 0xff;
10 color += value.toString(16).padStart(2, "0");
11 }
12 return color;
13}

Callers 1

debugFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected