Human-readable sizes

This commit is contained in:
Leo Vasanko
2023-10-27 08:28:03 +03:00
parent 0d186726b5
commit 8cc3ed1a04
6 changed files with 18 additions and 8 deletions

View File

@@ -6,6 +6,14 @@ export function determineFileType(inputString: string): "file" | "folder" {
}
}
export function formatSize(size: number) {
for (const unit of [null, 'kB', 'MB', 'GB', 'TB', 'PB', 'EB']) {
if (size < 1e5) return size.toLocaleString().replace(',', '\u202F') + (unit ? `\u202F${unit}` : '')
size = Math.round(size / 1000)
}
return "huge"
}
export function formatUnixDate(t: number) {
const date = new Date(t * 1000)
const now = new Date()