(bytes)
| 20 | } |
| 21 | |
| 22 | export const formatFileSize = (bytes) => { |
| 23 | if (bytes === 0 || bytes === '0') return '0 B' |
| 24 | if (!bytes) return '-' |
| 25 | const k = 1024 |
| 26 | const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] |
| 27 | const i = Math.floor(Math.log(bytes) / Math.log(k)) |
| 28 | return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i] |
| 29 | } |
| 30 | |
| 31 | export const getDisplayFileName = (pathOrName, fallback = '文件') => { |
| 32 | const value = String(pathOrName || '').trim() |
no outgoing calls
no test coverage detected