Dough Git

clove/pkviewer

web/src/lib/badges.ts

back to web/src/lib

/* web/src/lib/badges.ts */
import type { BadgeIconId } from "@pkviewer/shared";
import type { IconName } from "$lib/icons.ts";

/**
 * Badge icons come from a fixed vocabulary, never a stored string. An unknown
 * icon falls back to the neutral patch rather than nothing, so a catalogue
 * change cannot silently blank a badge.
 */
export const BADGE_ICONS: Record<BadgeIconId, IconName> = {
  star: "star-fill",
  heart: "heart-fill",
  people: "people-fill",
  bug: "bug",
  shield: "shield-fill",
  code: "code",
  patch: "patch-check-fill",
  gem: "gem",
};

export function badgeIcon(icon: string): IconName {
  return BADGE_ICONS[icon as BadgeIconId] ?? "patch-check-fill";
}