mirror of
https://github.com/kmvan/x-prober.git
synced 2026-08-13 03:41:41 +08:00
add missing lib
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
Reference in New Issue
Block a user