Initial commit

This commit is contained in:
dk
2025-12-22 13:24:30 +02:00
commit f1aa44bc84
308 changed files with 64920 additions and 0 deletions

15
src/utils/debounce.ts Normal file
View File

@@ -0,0 +1,15 @@
export function debounce<T extends (...args: unknown[]) => void>(
func: T,
wait: number
): (...args: Parameters<T>) => void {
let timeout: NodeJS.Timeout | null = null;
return function (...args: Parameters<T>) {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => {
func(...args);
}, wait);
};
}

24
src/utils/throttle.ts Normal file
View File

@@ -0,0 +1,24 @@
export function throttle<T extends (...args: unknown[]) => void>(
func: T,
wait: number
): (...args: Parameters<T>) => void {
let inThrottle: boolean = false;
let lastArgs: Parameters<T> | null = null;
return function (...args: Parameters<T>) {
if (!inThrottle) {
func(...args);
inThrottle = true;
setTimeout(() => {
inThrottle = false;
if (lastArgs) {
func(...lastArgs);
lastArgs = null;
}
}, wait);
} else {
lastArgs = args;
}
};
}