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

Function sanitizeProjectName

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

Source from the content-addressed store, hash-verified

47 * - Preserves original case (Bazel target names are case-sensitive)
48 */
49export 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.

Callers 6

getModuleNameFunction · 0.90
valdiNewModuleFunction · 0.90
getProjectNameFunction · 0.90
valdiBootstrapFunction · 0.90
validateProjectNameFunction · 0.85

Calls 2

replaceMethod · 0.65
testMethod · 0.45

Tested by

no test coverage detected