// src/utils/stringUtils.ts

/**
 * Sanitizes a string to be used as a safe filename.
 * Replaces spaces and multiple hyphens with a single hyphen,
 * removes characters that are problematic in URLs and file systems,
 * and preserves casing (matching the test suite requirements).
 * @param filename The string to sanitize.
 * @returns A sanitized string suitable for use as a filename.
 */
export function sanitizeFilename(filename: string): string {
  return filename
    .trim() // Remove leading/trailing whitespace
    .replace(/\s+/g, '-') // Replace internal spaces with a single hyphen
    .replace(/[^a-zA-Z0-9-._]/g, '') // Remove non-alphanumeric (except hyphens, underscores, dots)
    .replace(/-+/g, '-') // Replace multiple hyphens with a single one
    .replace(/^-+|-+$/g, ''); // Remove leading and trailing hyphens
}
