(bytes: number, decimals = 2)
| 13 | } |
| 14 | |
| 15 | export function formatBytes(bytes: number, decimals = 2): string { |
| 16 | if (bytes === 0) return '0 Bytes' |
| 17 | const k = 1024 |
| 18 | const dm = decimals < 0 ? 0 : decimals |
| 19 | const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'] |
| 20 | const i = Math.floor(Math.log(bytes) / Math.log(k)) |
| 21 | return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i] |
| 22 | } |
| 23 | |
| 24 | export function generateRandomString(length: number): string { |
| 25 | const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' |
no outgoing calls
no test coverage detected