(name: string)
| 47 | * - Preserves original case (Bazel target names are case-sensitive) |
| 48 | */ |
| 49 | export function sanitizeProjectName(name: string): string { |
| 50 | // Replace dashes with underscores |
| 51 | let sanitized = name.replace(/-/g, '_'); |
| 52 | |
| 53 | // Remove any characters that are not alphanumeric or underscore |
| 54 | sanitized = sanitized.replace(/[^a-zA-Z0-9_]/g, ''); |
| 55 | |
| 56 | // Ensure it starts with a letter or underscore |
| 57 | if (sanitized.length > 0 && /^[0-9]/.test(sanitized)) { |
| 58 | sanitized = '_' + sanitized; |
| 59 | } |
| 60 | |
| 61 | return sanitized; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Validates a project name and returns an error message if invalid, or null if valid. |
no test coverage detected