MCPcopy Create free account
hub / github.com/Snapchat/Valdi / validateProjectName

Function validateProjectName

npm_modules/cli/src/utils/stringUtils.ts:67–89  ·  view source on GitHub ↗
(name: string)

Source from the content-addressed store, hash-verified

65 * Validates a project name and returns an error message if invalid, or null if valid.
66 */
67export 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
91export function toPascalCase(str: string): string {
92 const words = str.trim().toLowerCase().split(wordSplitRegex);

Callers 5

getModuleNameFunction · 0.90
valdiNewModuleFunction · 0.90
getProjectNameFunction · 0.90
valdiBootstrapFunction · 0.90

Calls 4

sanitizeProjectNameFunction · 0.85
hasMethod · 0.65
replaceMethod · 0.65
trimMethod · 0.45

Tested by

no test coverage detected