feat: 🚀
This commit is contained in:
commit
e775435c9f
53 files changed
+14240
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
|
||||
// Cache de performance
|
||||
const perfCache = new Map<string, number>()
|
||||
|
||||
// Debounce utility
|
||||
export function debounce<T extends (...args: any[]) => any>(
|
||||
func: T,
|
||||
wait: number
|
||||
): (...args: Parameters<T>) => void {
|
||||
let timeout: NodeJS.Timeout
|
||||
|
||||
return (...args: Parameters<T>) => {
|
||||
clearTimeout(timeout)
|
||||
timeout = setTimeout(() => func(...args), wait)
|
||||
}
|
||||
}
|
||||
|
||||
// Memoização para cálculos pesados
|
||||
export function memoize<T extends (...args: any[]) => any>(
|
||||
func: T,
|
||||
resolver?: (...args: Parameters<T>) => string
|
||||
): T {
|
||||
const cache = new Map<string, ReturnType<T>>()
|
||||
|
||||
return ((...args: Parameters<T>) => {
|
||||
const key = resolver ? resolver(...args) : JSON.stringify(args)
|
||||
if (cache.has(key)) {
|
||||
return cache.get(key)
|
||||
}
|
||||
const result = func(...args)
|
||||
cache.set(key, result)
|
||||
return result
|
||||
}) as T
|
||||
}
|
||||
|
||||
// Medição de performance
|
||||
export function measurePerformance(key: string, callback: () => void) {
|
||||
const start = performance.now()
|
||||
callback()
|
||||
const end = performance.now()
|
||||
perfCache.set(key, end - start)
|
||||
}
|
||||
Reference in new issue
Block a user