30 lines
627 B
TypeScript
30 lines
627 B
TypeScript
const AVATAR_COLORS = [
|
|
'#d12655',
|
|
'#c42685',
|
|
'#a334c2',
|
|
'#853de0',
|
|
'#6548db',
|
|
'#485ddd',
|
|
'#2670cf',
|
|
'#087caa',
|
|
'#008579',
|
|
'#148348',
|
|
'#7846c7',
|
|
'#d13243',
|
|
];
|
|
|
|
export const avatarColor = (seed: string): string => {
|
|
let hash = 0;
|
|
for (let i = 0; i < seed.length; i++) {
|
|
hash = (hash * 31 + seed.charCodeAt(i)) >>> 0;
|
|
}
|
|
|
|
return AVATAR_COLORS[hash % AVATAR_COLORS.length]!;
|
|
};
|
|
|
|
export const avatarInitial = (name: string | null | undefined): string => {
|
|
const first = Array.from((name ?? '').trim())[0];
|
|
|
|
return first ? first.toUpperCase() : '?';
|
|
};
|