server/frontend/ui/src/components/FileSize.svelte
Pierre-Olivier Mercier f2bf07fd28
All checks were successful
continuous-integration/drone/push Build is passing
ui: Add helpers for formating date and file size
2021-09-01 02:21:49 +02:00

29 lines
428 B
Svelte

<script>
export let size;
const units = [
"o",
"kio",
"Mio",
"Gio",
"Tio",
"Pio",
"Eio",
"Zio",
"Yio",
]
function formatSize(input) {
var res = input;
var unit = 0;
while (res > 1024) {
unit += 1;
res = res / 1024;
}
return (Math.round(res * 100) / 100) + " " + units[unit];
}
</script>
<span title="{size} octets">
{formatSize(size)}
</span>