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 | 2x 2x 2x 2x 2x 2x 2x 2x 3x 3x 3x 60x 2x 2x 2x 2x 2x 2x | // 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
}
|