improve downloads dialog

This commit is contained in:
SpikeHD
2022-05-11 21:27:43 -07:00
parent 4fa269d75e
commit cd4fe6b9fb
3 changed files with 15 additions and 1 deletions

View File

@@ -1,3 +1,11 @@
export function capitalize(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1)
}
export function byteToString(bytes: number) {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
if (bytes === 0) return '0 Bytes'
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)).toString(), 10)
if (i === 0) return `${bytes} ${sizes[i]}`
return `${(bytes / Math.pow(1024, i)).toFixed(2)} ${sizes[i]}`
}