master @ 70 LINES
[ HISTORY ] [ UP ]
┌─ TS ───────────────────────────────────────────────────────────────────────┐
│ // Client-side utility functions │
│ │
│ import { │
│ CLASS_COLORS, │
│ SPEC_MAP, │
│ SPEC_ICON_MAP, │
│ getClassColor, │
│ getSpecInfo, │
│ getSpecIcon, │
│ } from "./wow-constants"; │
│ │
│ // Time formatting utilities │
│ export function formatDurationMMSS(milliseconds: number): string { │
│ return `${Math.floor(milliseconds / 60000)}:${String(Math.floor((milliseconds % │
│ 60000) / 1000)).padStart(2, "0")}`; │
│ } │
│ │
│ export function formatTimestamp(timestamp: number): string { │
│ return new Date(timestamp).toLocaleDateString(); │
│ } │
│ │
│ export function formatTimestampDetailed(timestamp: number): string { │
│ return new Date(timestamp).toLocaleDateString("en-US", { │
│ month: "short", │
│ day: "numeric", │
│ hour: "2-digit", │
│ minute: "2-digit", │
│ }); │
│ } │
│ │
│ // DOM utility functions (commonly used in client scripts) │
│ export function createElement( │
│ tag: string, │
│ className?: string, │
│ textContent?: string, │
│ ): HTMLElement { │
│ const element = document.createElement(tag); │
│ if (className) element.className = className; │
│ if (textContent) element.textContent = textContent; │
│ return element; │
│ } │
│ │
│ // Type helper functions for DOM elements (commonly used pattern) │
│ export const asHtml = (el: Element | null): HTMLElement | null => │
│ el as HTMLElement | null; │
│ │
│ export const asButton = (el: Element | null): HTMLButtonElement | null => │
│ el as HTMLButtonElement | null; │
│ │
│ // Client-side ranking formatter (similar to server-side but for client scripts) │
│ export function formatRankingWithBracket( │
│ ranking: any, │
│ bracket: string, │
│ ): string { │
│ if (!ranking || ranking === "-") return "-"; │
│ const bracketClass = getBracketClass(bracket); │
│ return `<span class="ranking-number ${bracketClass}">#${ranking}</span>`; │
│ } │
│ │
│ // Client-side bracket class helper │
│ function getBracketClass(bracket: string): string { │
│ if (!bracket) return "bracket-common"; │
│ return `bracket-${bracket}`; │
│ } │
│ │
│ // Re-exports for backward compatibility in client code │
│ export { getClassColor, getSpecInfo, getSpecIcon }; │
│ export const specMap = SPEC_MAP; │
│ export const specIconMap = SPEC_ICON_MAP; │
│ export const classColors = CLASS_COLORS; │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ TS ─────────────────────────────────┐
│ // Client-side utility functions │
│ │
│ import { │
│ CLASS_COLORS, │
│ SPEC_MAP, │
│ SPEC_ICON_MAP, │
│ getClassColor, │
│ getSpecInfo, │
│ getSpecIcon, │
│ } from "./wow-constants"; │
│ │
│ // Time formatting utilities │
│ export function formatDurationMMSS(milliseco │
│ nds: number): string { │
│ return `${Math.floor(milliseconds / 60000) │
│ }:${String(Math.floor((milliseconds % 60000) │
│ / 1000)).padStart(2, "0")}`; │
│ } │
│ │
│ export function formatTimestamp(timestamp: n │
│ umber): string { │
│ return new Date(timestamp).toLocaleDateStr │
│ ing(); │
│ } │
│ │
│ export function formatTimestampDetailed(time │
│ stamp: number): string { │
│ return new Date(timestamp).toLocaleDateStr │
│ ing("en-US", { │
│ month: "short", │
│ day: "numeric", │
│ hour: "2-digit", │
│ minute: "2-digit", │
│ }); │
│ } │
│ │
│ // DOM utility functions (commonly used in c │
│ lient scripts) │
│ export function createElement( │
│ tag: string, │
│ className?: string, │
│ textContent?: string, │
│ ): HTMLElement { │
│ const element = document.createElement(tag │
│ ); │
│ if (className) element.className = classNa │
│ me; │
│ if (textContent) element.textContent = tex │
│ tContent; │
│ return element; │
│ } │
│ │
│ // Type helper functions for DOM elements (c │
│ ommonly used pattern) │
│ export const asHtml = (el: Element | null): │
│ HTMLElement | null => │
│ el as HTMLElement | null; │
│ │
│ export const asButton = (el: Element | null) │
│ : HTMLButtonElement | null => │
│ el as HTMLButtonElement | null; │
│ │
│ // Client-side ranking formatter (similar to │
│ server-side but for client scripts) │
│ export function formatRankingWithBracket( │
│ ranking: any, │
│ bracket: string, │
│ ): string { │
│ if (!ranking || ranking === "-") return "- │
│ "; │
│ const bracketClass = getBracketClass(brack │
│ et); │
│ return `<span class="ranking-number ${brac │
│ ketClass}">#${ranking}</span>`; │
│ } │
│ │
│ // Client-side bracket class helper │
│ function getBracketClass(bracket: string): s │
│ tring { │
│ if (!bracket) return "bracket-common"; │
│ return `bracket-${bracket}`; │
│ } │
│ │
│ // Re-exports for backward compatibility in │
│ client code │
│ export { getClassColor, getSpecInfo, getSpec │
│ Icon }; │
│ export const specMap = SPEC_MAP; │
│ export const specIconMap = SPEC_ICON_MAP; │
│ export const classColors = CLASS_COLORS; │
└──────────────────────────────────────────────┘
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET