wynn/ts/src/lib/util/wynnfmt.ts
a d5f3ea5848
Some checks failed
commit-tag / commit-tag-image (map[context:./migrations file:./migrations/Dockerfile name:migrations]) (push) Successful in 15s
commit-tag / commit-tag-image (map[context:./ts file:./ts/Dockerfile name:ts]) (push) Failing after 36s
noot
2025-06-14 16:55:31 -05:00

35 lines
905 B
TypeScript

/**
* Wynncraft formatting utilities
*/
/**
* Mapping of Wynncraft guild ranks to their corresponding emojis
*/
export const RANK_EMOJIS = {
"OWNER": "👑",
"CHIEF": "⭐",
"STRATEGIST": "🎯",
"CAPTAIN": "⚔️",
"RECRUITER": "📢",
"RECRUIT": "🌱",
} as const;
/**
* Get the emoji for a given guild rank
* @param rank - The guild rank name
* @returns The corresponding emoji or a default bullet point
*/
export function getRankEmoji(rank: string): string {
return RANK_EMOJIS[rank as keyof typeof RANK_EMOJIS] || "•";
}
/**
* Format large numbers with K/M suffixes
* @param num - The number to format
* @returns Formatted string with appropriate suffix
*/
export function formatNumber(num: number): string {
if (num >= 1_000_000) return `${(num / 1_000_000).toFixed(1)}M`;
if (num >= 1_000) return `${(num / 1_000).toFixed(0)}K`;
return num.toLocaleString();
}