feat: size conversion function & implementation

This commit is contained in:
Arman committed 2022-06-21 16:23:41 +02:00
1 parent db8b03daa4
commit 70bb0c7fea
3 files changed
+15 -2

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
export function bytesToSize(bytes: number, decimals = 1) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
@@ -7,6 +7,7 @@
import { toLocaleDate } from '$lib/helpers/date';
import { sdkForProject } from '$lib/stores/sdk';
import { addNotification } from '$lib/stores/notifications';
import { bytesToSize } from '$lib/helpers/sizeConvertion';
import Delete from './_deleteFile.svelte';
let showDelete = false;
@@ -99,7 +100,7 @@
</div>
<div>
<p>MIME Type: {$file.response.mimeType}</p>
<p>Size: {$file.response.sizeOriginal}</p>
<p>Size: {bytesToSize($file.response.sizeOriginal)}</p>
<p>Created: {toLocaleDate($file.response.dateCreated)}</p>
<p>Last Updated (to implement): {toLocaleDate($file.response.dateCreated)}</p>
</div>
@@ -14,6 +14,7 @@
TableCellLink
} from '$lib/elements/table';
import { toLocaleDate } from '$lib/helpers/date';
import { bytesToSize } from '$lib/helpers/sizeConvertion';
import { Container } from '$lib/layout';
import { base } from '$app/paths';
import { files } from './store';
@@ -79,7 +80,7 @@
</div>
</TableCellLink>
<TableCellText title="Type">{file.mimeType}</TableCellText>
<TableCellText title="Size">{file.sizeOriginal}</TableCellText>
<TableCellText title="Size">{bytesToSize(file.sizeOriginal)}</TableCellText>
<TableCellText title="Date Created"
>{toLocaleDate(file.dateCreated)}</TableCellText>
</TableRow>