Files
snippet-pastebin/src/lib/utils.ts
johndoe6345789 d1f47830a8 fix: Resolve ESLint configuration and fix all linting errors
- Changed npm lint script from 'next lint' to direct ESLint invocation
- Added 'lint:fix' script for auto-fixing linting errors
- Fixed 25 ESLint errors across the codebase:
  - 8 auto-fixed with --fix flag
  - 17 manual fixes (empty function warnings, type definitions)

ESLint now properly validates TypeScript and React code without
Next.js config wrapper incompatibility.

Test Results:
-  npm run lint - No errors
-  npm test - All tests passing
-  npm run build - Clean build

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-01-20 19:17:17 +00:00

48 lines
1.1 KiB
TypeScript

/**
* Utility function to combine class names
* Replaces tailwind-merge and clsx with a simple implementation
*/
export function cn(...classes: (string | undefined | null | false)[]): string {
return classes.filter(Boolean).join(' ')
}
/**
* Format bytes to human readable string
*/
export function formatBytes(bytes: number): string {
if (bytes === 0) return '0 Bytes'
const k = 1024
const sizes = ['Bytes', 'KB', 'MB', 'GB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i]
}
/**
* Debounce function
*/
export function debounce<T extends (...args: unknown[]) => unknown>(
func: T,
wait: number
): (...args: Parameters<T>) => void {
let timeout: NodeJS.Timeout | null = null
return function executedFunction(...args: Parameters<T>) {
const later = () => {
timeout = null
func(...args)
}
if (timeout) {
clearTimeout(timeout)
}
timeout = setTimeout(later, wait)
}
}
/**
* Sleep utility
*/
export function sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms))
}