do to formatters
This commit is contained in:
189
apps/website/lib/formatters/ProfileFormatter.ts
Normal file
189
apps/website/lib/formatters/ProfileFormatter.ts
Normal file
@@ -0,0 +1,189 @@
|
||||
/**
|
||||
* Profile Display Objects
|
||||
*
|
||||
* Deterministic formatting for profile data.
|
||||
* NO Intl.*, NO Date.toLocale*, NO dynamic formatting.
|
||||
*/
|
||||
|
||||
export interface CountryFlagDisplayData {
|
||||
flag: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export interface AchievementRarityDisplayData {
|
||||
text: string;
|
||||
badgeClasses: string;
|
||||
borderClasses: string;
|
||||
}
|
||||
|
||||
export interface AchievementIconDisplayData {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface SocialPlatformDisplayData {
|
||||
name: string;
|
||||
hoverClasses: string;
|
||||
}
|
||||
|
||||
export interface TeamRoleDisplayData {
|
||||
text: string;
|
||||
badgeClasses: string;
|
||||
}
|
||||
|
||||
export class ProfileFormatter {
|
||||
private static readonly countryFlagDisplay: Record<string, CountryFlagDisplayData> = {
|
||||
US: { flag: '🇺🇸', label: 'United States' },
|
||||
GB: { flag: '🇬🇧', label: 'United Kingdom' },
|
||||
DE: { flag: '🇩🇪', label: 'Germany' },
|
||||
FR: { flag: '🇫🇷', label: 'France' },
|
||||
IT: { flag: '🇮🇹', label: 'Italy' },
|
||||
ES: { flag: '🇪🇸', label: 'Spain' },
|
||||
JP: { flag: '🇯🇵', label: 'Japan' },
|
||||
AU: { flag: '🇦🇺', label: 'Australia' },
|
||||
CA: { flag: '🇨🇦', label: 'Canada' },
|
||||
BR: { flag: '🇧🇷', label: 'Brazil' },
|
||||
DEFAULT: { flag: '🏁', label: 'Unknown' },
|
||||
};
|
||||
|
||||
static getCountryFlag(countryCode: string): CountryFlagDisplayData {
|
||||
const code = countryCode.toUpperCase();
|
||||
return ProfileFormatter.countryFlagDisplay[code] || ProfileFormatter.countryFlagDisplay.DEFAULT;
|
||||
}
|
||||
|
||||
private static readonly achievementRarityDisplay: Record<string, AchievementRarityDisplayData> = {
|
||||
common: {
|
||||
text: 'Common',
|
||||
badgeClasses: 'bg-gray-400/10 text-gray-400',
|
||||
borderClasses: 'border-gray-400/30',
|
||||
},
|
||||
rare: {
|
||||
text: 'Rare',
|
||||
badgeClasses: 'bg-primary-blue/10 text-primary-blue',
|
||||
borderClasses: 'border-primary-blue/30',
|
||||
},
|
||||
epic: {
|
||||
text: 'Epic',
|
||||
badgeClasses: 'bg-purple-400/10 text-purple-400',
|
||||
borderClasses: 'border-purple-400/30',
|
||||
},
|
||||
legendary: {
|
||||
text: 'Legendary',
|
||||
badgeClasses: 'bg-yellow-400/10 text-yellow-400',
|
||||
borderClasses: 'border-yellow-400/30',
|
||||
},
|
||||
};
|
||||
|
||||
static getAchievementRarity(rarity: string): AchievementRarityDisplayData {
|
||||
return ProfileFormatter.achievementRarityDisplay[rarity] || ProfileFormatter.achievementRarityDisplay.common;
|
||||
}
|
||||
|
||||
private static readonly achievementIconDisplay: Record<string, AchievementIconDisplayData> = {
|
||||
trophy: { name: 'Trophy' },
|
||||
medal: { name: 'Medal' },
|
||||
star: { name: 'Star' },
|
||||
crown: { name: 'Crown' },
|
||||
target: { name: 'Target' },
|
||||
zap: { name: 'Zap' },
|
||||
};
|
||||
|
||||
static getAchievementIcon(icon: string): AchievementIconDisplayData {
|
||||
return ProfileFormatter.achievementIconDisplay[icon] || ProfileFormatter.achievementIconDisplay.trophy;
|
||||
}
|
||||
|
||||
private static readonly socialPlatformDisplay: Record<string, SocialPlatformDisplayData> = {
|
||||
twitter: {
|
||||
name: 'Twitter',
|
||||
hoverClasses: 'hover:text-sky-400 hover:bg-sky-400/10',
|
||||
},
|
||||
youtube: {
|
||||
name: 'YouTube',
|
||||
hoverClasses: 'hover:text-red-500 hover:bg-red-500/10',
|
||||
},
|
||||
twitch: {
|
||||
name: 'Twitch',
|
||||
hoverClasses: 'hover:text-purple-400 hover:bg-purple-400/10',
|
||||
},
|
||||
discord: {
|
||||
name: 'Discord',
|
||||
hoverClasses: 'hover:text-indigo-400 hover:bg-indigo-400/10',
|
||||
},
|
||||
};
|
||||
|
||||
static getSocialPlatform(platform: string): SocialPlatformDisplayData {
|
||||
return ProfileFormatter.socialPlatformDisplay[platform] || ProfileFormatter.socialPlatformDisplay.discord;
|
||||
}
|
||||
|
||||
static formatMonthYear(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
const month = months[date.getUTCMonth()];
|
||||
const year = date.getUTCFullYear();
|
||||
return `${month} ${year}`;
|
||||
}
|
||||
|
||||
static formatMonthDayYear(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
const month = months[date.getUTCMonth()];
|
||||
const day = date.getUTCDate();
|
||||
const year = date.getUTCFullYear();
|
||||
return `${month} ${day}, ${year}`;
|
||||
}
|
||||
|
||||
static formatPercentage(value: number | null | undefined): string {
|
||||
if (value === null || value === undefined) return '0.0%';
|
||||
return `${(value * 100).toFixed(1)}%`;
|
||||
}
|
||||
|
||||
static formatFinishPosition(position: number | null | undefined): string {
|
||||
if (position === null || position === undefined) return 'P-';
|
||||
return `P${position}`;
|
||||
}
|
||||
|
||||
static formatAvgFinish(avg: number | null | undefined): string {
|
||||
if (avg === null || avg === undefined) return 'P-';
|
||||
return `P${avg.toFixed(1)}`;
|
||||
}
|
||||
|
||||
static formatRating(rating: number | null | undefined): string {
|
||||
if (rating === null || rating === undefined) return '0';
|
||||
return Math.round(rating).toString();
|
||||
}
|
||||
|
||||
static formatConsistency(consistency: number | null | undefined): string {
|
||||
if (consistency === null || consistency === undefined) return '0%';
|
||||
return `${Math.round(consistency)}%`;
|
||||
}
|
||||
|
||||
static formatPercentile(percentile: number | null | undefined): string {
|
||||
if (percentile === null || percentile === undefined) return 'Top -%';
|
||||
return `Top ${Math.round(percentile)}%`;
|
||||
}
|
||||
|
||||
private static readonly teamRoleDisplay: Record<string, TeamRoleDisplayData> = {
|
||||
owner: {
|
||||
text: 'Owner',
|
||||
badgeClasses: 'bg-yellow-500/10 text-yellow-500 border-yellow-500/30',
|
||||
},
|
||||
manager: {
|
||||
text: 'Manager',
|
||||
badgeClasses: 'bg-blue-500/10 text-blue-400 border-blue-500/30',
|
||||
},
|
||||
admin: {
|
||||
text: 'Admin',
|
||||
badgeClasses: 'bg-purple-500/10 text-purple-400 border-purple-500/30',
|
||||
},
|
||||
steward: {
|
||||
text: 'Steward',
|
||||
badgeClasses: 'bg-blue-500/10 text-blue-400 border-blue-500/30',
|
||||
},
|
||||
member: {
|
||||
text: 'Member',
|
||||
badgeClasses: 'bg-primary-blue/10 text-primary-blue border-primary-blue/30',
|
||||
},
|
||||
};
|
||||
|
||||
static getTeamRole(role: string): TeamRoleDisplayData {
|
||||
return ProfileFormatter.teamRoleDisplay[role] || ProfileFormatter.teamRoleDisplay.member;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user