1/**
2 * Formats file size in bytes to human readable format
3 * Supports Bytes, KB, MB, and GB
4 *
5 * @param bytes - File size in bytes (or unknown for safety)
6 * @returns Formatted file size string
7 */
8export function formatFileSize(bytes: number | unknown): string {
9 if (typeof bytes !== 'number') return 'Unknown';
10 if (bytes === 0) return '0 Bytes';
11
12 const k = 1024;
13 const sizes = ['Bytes', 'KB', 'MB', 'GB'];
14 const i = Math.floor(Math.log(bytes) / Math.log(k));
15
16 return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
17}
18
19/**
20 * Format parameter count to human-readable format (B, M, K)
21 *
22 * @param params - Parameter count
23 * @returns Human-readable parameter count
24 */
25export function formatParameters(params: number | unknown): string {
26 if (typeof params !== 'number') return 'Unknown';
27
28 if (params >= 1e9) {
29 return `${(params / 1e9).toFixed(2)}B`;
30 }
31
32 if (params >= 1e6) {
33 return `${(params / 1e6).toFixed(2)}M`;
34 }
35
36 if (params >= 1e3) {
37 return `${(params / 1e3).toFixed(2)}K`;
38 }
39
40 return params.toString();
41}
42
43/**
44 * Format number with locale-specific thousands separators
45 *
46 * @param num - Number to format
47 * @returns Human-readable number
48 */
49export function formatNumber(num: number | unknown): string {
50 if (typeof num !== 'number') return 'Unknown';
51
52 return num.toLocaleString();
53}