| 1 |
export const formatFileSize = (bytes: number): string => { |
| 2 |
if (bytes === 0) return '0 Bytes' |
| 3 |
const k = 1024 |
| 4 |
const sizes = ['Bytes', 'KB', 'MB', 'GB'] |
| 5 |
const i = Math.floor(Math.log(bytes) / Math.log(k)) |
| 6 |
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i] |
| 7 |
} |
| 8 |
|
| 9 |
export const removeFileFromList = (fileList: FileList, indexToRemove: number): FileList => { |
| 10 |
const dt = new DataTransfer() |
| 11 |
for (let i = 0; i < fileList.length; i++) { |
| 12 |
if (i !== indexToRemove) { |
| 13 |
dt.items.add(fileList[i]) |
| 14 |
} |
| 15 |
} |
| 16 |
return dt.files |
| 17 |
} |
| 18 |
|