🪖 Moves humanFileSize to string utilities

This commit is contained in:
Rune Harlyk
2024-02-22 23:47:25 +01:00
parent 74bf4a8656
commit 162b148973
4 changed files with 8 additions and 6 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
<script lang="ts">
import { socket, isConnected, systemInfo } from "../../lib/socket";
import { onMount } from 'svelte'
import { humanFileSize } from "../../lib/utils";
import { humanFileSize } from "$lib/utilities";
onMount(() => {
if ($isConnected) {
+2
View File
@@ -0,0 +1,2 @@
export * from './result'
export * from './string-utilities'
@@ -0,0 +1,5 @@
export const humanFileSize = (size:number):string => {
const units = ['B', 'kB', 'MB', 'GB', 'TB']
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
return Number((size / Math.pow(1024, i)).toFixed(2)) * 1 + units[i];
}
-5
View File
@@ -1,10 +1,5 @@
import { writable } from 'svelte/store';
export const humanFileSize = (size:number):string => {
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
return Number((size / Math.pow(1024, i)).toFixed(2)) * 1 + ['B', 'kB', 'MB', 'GB', 'TB'][i];
}
export const lerp = (start: number, end: number, amt: number) => {
return (1 - amt) * start + amt * end;
};