utils.ts 752 B

1234567891011121314151617181920212223
  1. import { type ClassValue, clsx } from 'clsx'
  2. import { twMerge } from 'tailwind-merge'
  3. export function cn(...inputs: ClassValue[]) {
  4. return twMerge(clsx(inputs))
  5. }
  6. /**
  7. * Normalize a string for fuzzy search matching.
  8. * Treats spaces, underscores, and hyphens as equivalent.
  9. * Example: "clear from out" matches "clear_from_out"
  10. */
  11. export function normalizeForSearch(str: string): string {
  12. return str.toLowerCase().replace(/[\s_-]+/g, ' ')
  13. }
  14. /**
  15. * Check if a search query matches a target string (fuzzy match).
  16. * Spaces, underscores, and hyphens are treated as equivalent.
  17. */
  18. export function fuzzyMatch(target: string, query: string): boolean {
  19. return normalizeForSearch(target).includes(normalizeForSearch(query))
  20. }