(name: string)
| 65 | * Validates a project name and returns an error message if invalid, or null if valid. |
| 66 | */ |
| 67 | export function validateProjectName(name: string): string | null { |
| 68 | if (!name || name.trim().length === 0) { |
| 69 | return 'Project name cannot be empty.'; |
| 70 | } |
| 71 | |
| 72 | const sanitized = sanitizeProjectName(name); |
| 73 | |
| 74 | if (sanitized.length === 0) { |
| 75 | return 'Project name must contain at least one alphanumeric character.'; |
| 76 | } |
| 77 | |
| 78 | // Check if the sanitized name (case-insensitive) is a reserved word |
| 79 | if (RESERVED_PROJECT_NAMES.has(sanitized.toLowerCase())) { |
| 80 | return `Project name "${name}" (sanitized to "${sanitized}") is a reserved word and cannot be used. Please choose a different name.`; |
| 81 | } |
| 82 | |
| 83 | // Warn if the name was significantly changed during sanitization |
| 84 | if (sanitized !== name.replace(/-/g, '_')) { |
| 85 | return `Project name "${name}" contains invalid characters. It will be sanitized to "${sanitized}". Please use only letters, numbers, underscores, and dashes.`; |
| 86 | } |
| 87 | |
| 88 | return null; |
| 89 | } |
| 90 | |
| 91 | export function toPascalCase(str: string): string { |
| 92 | const words = str.trim().toLowerCase().split(wordSplitRegex); |
no test coverage detected