[O] Split util function
This commit is contained in:
+1
-5
@@ -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"
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
Reference in New Issue
Block a user