All files / src/lib utils.ts

100% Statements 9/9
100% Branches 4/4
100% Functions 3/3
100% Lines 8/8

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        58x                 16x     15x     15x 3x   6x         12x     12x    
import { type ClassValue, clsx } from 'clsx'
import { twMerge } from 'tailwind-merge'
 
export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}
 
/**
 * Format nutrition key into human readable label.
 * Converts camelCase keys like 'carbohydrateContent' to 'Carbohydrate'.
 * Also handles snake_case like 'saturated_fat' to 'Saturated Fat'.
 */
export function formatNutritionKey(key: string): string {
  if (!key) return ''
 
  // Remove "Content" suffix
  let formatted = key.replace(/Content$/, '')
 
  // Handle snake_case
  if (formatted.includes('_')) {
    return formatted
      .split('_')
      .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
      .join(' ')
  }
 
  // Handle camelCase - insert space before capitals
  formatted = formatted.replace(/([a-z])([A-Z])/g, '$1 $2')
 
  // Capitalize first letter
  return formatted.charAt(0).toUpperCase() + formatted.slice(1)
}
 
← Back to Dashboard