(bytes: number, decimals = 2)
| 1134 | * Formats a byte count into a human-readable file size string. |
| 1135 | */ |
| 1136 | export function formatFilesize(bytes: number, decimals = 2): string { |
| 1137 | if (bytes <= 0) return "0 Bytes"; |
| 1138 | const k = 1024; |
| 1139 | const dm = decimals < 0 ? 0 : decimals; |
| 1140 | const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; |
| 1141 | const i = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1); |
| 1142 | return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i]; |
| 1143 | } |
| 1144 | |
| 1145 | export type Limit = <T>(fn: () => Promise<T>) => Promise<T>; |
| 1146 |
no test coverage detected
searching dependent graphs…