Files
webapp/app/utils/profileAvatars.ts
2026-04-11 08:31:34 +07:00

24 lines
792 B
TypeScript

const DICEBEAR_STYLE = 'notionists'
const DICEBEAR_BACKGROUNDS = ['f6efe3', 'e7f4ee', 'eef2ff', 'fff1dc', 'fce7f3']
function hashProfileAvatarValue(value: string) {
return [...value].reduce((acc, char) => {
return (acc * 33 + char.charCodeAt(0)) >>> 0
}, 5381)
}
export function profileAvatarSeedFromValue(value?: string | null) {
const normalized = String(value || 'profile').trim() || 'profile'
return `gl-${hashProfileAvatarValue(normalized).toString(36)}`
}
export function profileAvatarUrl(seed?: string | null) {
const params = new URLSearchParams({
seed: String(seed || 'profile').trim() || 'profile',
radius: '32',
backgroundColor: DICEBEAR_BACKGROUNDS.join(','),
})
return `https://api.dicebear.com/9.x/${DICEBEAR_STYLE}/svg?${params.toString()}`
}