diff --git a/src/App.tsx b/src/App.tsx index a3ec488..686afad 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -10,6 +10,7 @@ import 'tippy.js/animations/shift-away.css'; import './app.sass'; import { Icon } from '@iconify-icon/solid'; +import { sizeFmt } from './utils'; interface File { name: string @@ -25,11 +26,6 @@ const host = "https://daisy-ddns.hydev.org/data/api" const path = window.location.pathname const fetchApi = async () => await (await fetch(urlJoin(host, path))).json() as File[] -function sizeFmt(size: number) { - var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024)); - return (size / Math.pow(1024, i)).toFixed(1) + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]; -} - function getIcon(f: File) { if (f.type == "directory") return "/mime/folder.svg" diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..5deab9c --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,10 @@ +/** + * Format bytes to human-readable size + * + * @param size Size in bytes + * @returns Human readable size in string + */ +export function sizeFmt(size: number): string { + var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024)); + return (size / Math.pow(1024, i)).toFixed(1) + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]; +} \ No newline at end of file