feat: mail composition
Signed-off-by: Sebastian <krupinski01@gmail.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
export function formatFileSize(bytes: number | null | undefined): string {
|
||||
if (bytes == null || !Number.isFinite(bytes)) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if (bytes < 1024) {
|
||||
return `${Math.max(0, Math.round(bytes))} B`
|
||||
}
|
||||
|
||||
const units = ['KB', 'MB', 'GB', 'TB']
|
||||
let value = bytes / 1024
|
||||
let unitIndex = 0
|
||||
|
||||
while (value >= 1024 && unitIndex < units.length - 1) {
|
||||
value /= 1024
|
||||
unitIndex += 1
|
||||
}
|
||||
|
||||
const precision = value >= 10 || unitIndex === 0 ? 1 : 2
|
||||
return `${value.toFixed(precision)} ${units[unitIndex]}`
|
||||
}
|
||||
Reference in New Issue
Block a user