(bytes: number, decimals = 2)
| 3 | export const truthyFilter = <T>(x: T | null | undefined): x is T => Boolean(x); |
| 4 | |
| 5 | export const formatFileSize = (bytes: number, decimals = 2) => { |
| 6 | if (bytes === 0) return "0 Bytes"; |
| 7 | |
| 8 | const k = 1024; |
| 9 | const dm = decimals < 0 ? 0 : decimals; |
| 10 | const sizes = ["Bytes", "KB", "MB", "GB", "TB"]; |
| 11 | |
| 12 | for (const size of sizes) { |
| 13 | if (bytes < k) return `${parseFloat(bytes.toFixed(dm))} ${size}`; |
| 14 | bytes /= k; |
| 15 | } |
| 16 | |
| 17 | return "> 1024 TB"; |
| 18 | }; |
| 19 | |
| 20 | export const ensureDefaultExport = <T>(module: T) => { |
| 21 | const defaultExport = module as unknown as { default: T }; |
no outgoing calls
no test coverage detected