add missing lib

This commit is contained in:
Km.Van
2026-07-10 15:27:15 +08:00
parent da41c8bfdd
commit b84ab4f2d4
2 changed files with 21 additions and 3 deletions
@@ -1,14 +1,14 @@
export const formatBytes = (bytes: number, decimals = 2): string => {
if (bytes === 0) {
return '0';
return "0";
}
const k = 1024;
const sizes = ['B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
const sizes = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"];
let i = Math.floor(Math.log(bytes) / Math.log(k));
i = i < 0 ? 0 : i;
const num = Number.parseFloat((bytes / k ** i).toFixed(decimals));
if (!num) {
return '0';
return "0";
}
return `${num.toFixed(2)} ${sizes[i]}`;
};
@@ -0,0 +1,18 @@
import { useEffect, useRef } from "react";
export function useInterval(callback: () => void, delay: number | null) {
const savedCallback = useRef<() => void>(callback);
useEffect(() => {
savedCallback.current = callback;
}, [callback]);
useEffect(() => {
if (delay === null) {
return;
}
const tick = () => {
savedCallback.current();
};
const id = setInterval(tick, delay);
return () => clearInterval(id);
}, [delay]);
}