# Code coverage report for src/lib/utils.ts

# All files / src/lib utils.ts

100% Statements 47/47
100% Branches 10/10
100% Functions 6/6
100% Lines 47/47

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    481x
    1x
    1x
    1x
    1x
    2704x
    2704x
    1x
    1x
    1x
    1x
    1x
    10x
    9x
    9x
    9x
    9x
    9x
    1x
    1x
    1x
    1x
    1x
    7x
    7x
    7x
    7x
    7x
    7x
    13x
    7x
    7x
    7x
    13x
    13x
    6x
    6x
    13x
    13x
    7x
    1x
    1x
    1x
    1x
    1x
    6x
    6x
     /**
     * 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))
    }