cal/packages/lib/defaultAvatarImage.ts
Aldrin 3e08c66888
refactor: Use template literal instead of '+' operator (#11444)
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: zomars <zomars@me.com>
2023-10-03 11:52:19 -07:00

17 lines
670 B
TypeScript

/**
* Given an avatar URL and a name, return the appropriate avatar URL. In the
* event that no avatar URL is provided, return a placeholder avatar URL from
* ui-avatars.com.
*
* ui-avatars.com is a free service that generates placeholder avatars based on
* a name. It is used here to provide a consistent placeholder avatar for users
* who have not uploaded an avatar.
*/
export function getPlaceholderAvatar(avatar: string | null | undefined, name: string | null | undefined) {
return avatar
? avatar
: `https://eu.ui-avatars.com/api/?background=fff&color=f9f9f9&bold=true&background=000000&name=${encodeURIComponent(
name || ""
)}`;
}