22 lines
727 B
TypeScript
22 lines
727 B
TypeScript
import CryptoJS from 'crypto-js';
|
|
|
|
export function getGravatarUrl(email: string, size = 100): string {
|
|
if (!email) return `https://www.gravatar.com/avatar/00000000000000000000000000000000?s=${size}&d=mp`;
|
|
const hash = CryptoJS.MD5(email.trim().toLowerCase()).toString();
|
|
return `https://www.gravatar.com/avatar/${hash}?s=${size}&d=mp`;
|
|
}
|
|
|
|
export function getInitials(name?: string, email?: string): string {
|
|
if (name) {
|
|
const parts = name.trim().split(/\s+/);
|
|
if (parts.length >= 2) {
|
|
return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
|
|
}
|
|
return name.trim().substring(0, 2).toUpperCase();
|
|
}
|
|
if (email) {
|
|
return email.trim().substring(0, 2).toUpperCase();
|
|
}
|
|
return '??';
|
|
}
|