revamp template

This commit is contained in:
fro1991
2025-02-01 16:44:51 +07:00
parent c432df568a
commit 276a289580
1212 changed files with 112762 additions and 0 deletions

58
src/lib/helpers.ts Normal file
View File

@ -0,0 +1,58 @@
export const throttle = (func: (...args: any[]) => void, limit: number) => {
let lastFunc: any;
let lastRan: number;
return function (this: any, ...args: any[]) {
if (!lastRan) {
func.apply(this, args);
lastRan = Date.now();
} else {
clearTimeout(lastFunc);
lastFunc = setTimeout(
() => {
if (Date.now() - lastRan >= limit) {
func.apply(this, args);
lastRan = Date.now();
}
},
limit - (Date.now() - lastRan)
);
}
};
};
export function debounce<T extends (...args: any[]) => any>(
func: T,
wait: number
): (...args: Parameters<T>) => void {
let timeout: NodeJS.Timeout | null = null;
return function (...args: Parameters<T>): void {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => {
func(...args);
}, wait);
};
}
export function deepMerge(obj1: any, obj2: any): any {
const output = Object.assign({}, obj1);
for (const key in obj2) {
if (Object.prototype.hasOwnProperty.call(obj2, key)) {
if (typeof obj2[key] === 'object' && obj2[key] !== null && obj1[key]) {
output[key] = deepMerge(obj1[key], obj2[key]);
} else {
output[key] = obj2[key];
}
}
}
return output;
}
export function uniqueID(): string {
return (Date.now() + Math.floor(Math.random() * 1000)).toString();
}

6
src/lib/utils.ts Normal file
View File

@ -0,0 +1,6 @@
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}