All files / utils avatar.ts

0% Statements 0/10
0% Branches 0/4
0% Functions 0/3
0% Lines 0/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23                                             
const DICEBEAR_AVATAR_BASE_URL = "https://api.dicebear.com/7.x/adventurer/svg";
 
export function getAvatarUrl(seedValue: string) {
  const seed = encodeURIComponent(seedValue.trim().toLowerCase());
  return `${DICEBEAR_AVATAR_BASE_URL}?seed=${seed}`;
}
 
export function getInitialsFromName(name: string) {
  const words = name
    .trim()
    .split(/\s+/)
    .filter(Boolean);
 
  if (words.length === 0) {
    return "U";
  }
 
  return words
    .slice(0, 2)
    .map((word) => word[0]?.toUpperCase() ?? "")
    .join("");
}