Skip to content

Instantly share code, notes, and snippets.

@kouameYao
Created April 2, 2026 15:44
Show Gist options
  • Select an option

  • Save kouameYao/7d118e043d0d2bc170162986f834295d to your computer and use it in GitHub Desktop.

Select an option

Save kouameYao/7d118e043d0d2bc170162986f834295d to your computer and use it in GitHub Desktop.
Avatar Color
const alphabetColors: string[] = [
'#735CDE', // A
'#30B0C7', // B
'#3053FF', // C
'#009597', // D
'#FFBF00', // E
'#2B63E3', // F
'#C95AD1', // G
'#63AF00', // H
'#F26E1C', // I
'#A426FF', // J
'#FF3B30', // K
'#5EC564', // L
'#B9007E', // M
'#A45908', // N
'#30B0C7', // O
'#DDA164', // P
'#EF9335', // Q
'#737373', // R
'#A2845E', // S
'#6B567F', // T
'#FF3B30', // U
'#A45908', // V
'#515298', // W
'#F4BA7F', // X
'#00CBFF', // Y
'#E46962', // Z
]
/**
* Returns a deterministic color based on the first letter of the name.
* Non-letter characters fall back to default color.
*/
export function colorForName(name: string): string {
const defaultColor = '#000000'
if (!name || name.length === 0) return defaultColor
const firstChar = name[0].toUpperCase()
const index = firstChar.charCodeAt(0) - 65 // 'A' = 65
if (index < 0 || index >= alphabetColors.length) {
return defaultColor
}
return alphabetColors[index]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment