项目文件夹

文件
wehub-resource-sync 98e40dac97
CLI Smoke Test / smoke-test-linux (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-linux (24) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (24) (push) Has been cancelled
Expo App TypeScript typecheck / typecheck (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:40:49 +08:00

41 行
1.4 KiB
TypeScript

/**
* Convert a string to camelCase
* Examples:
* - "Hello World" -> "helloWorld"
* - "create user authentication" -> "createUserAuthentication"
* - "API-endpoint-handler" -> "apiEndpointHandler"
*/
export function toCamelCase(str: string): string {
// Remove special characters and split by spaces, hyphens, underscores
const words = str
.replace(/[^\w\s-]/g, '') // Remove special chars except spaces and hyphens
.split(/[\s-_]+/) // Split by spaces, hyphens, underscores
.filter(word => word.length > 0);
if (words.length === 0) return '';
// First word lowercase, rest capitalize first letter
return words
.map((word, index) => {
const lowercased = word.toLowerCase();
if (index === 0) {
return lowercased;
}
return lowercased.charAt(0).toUpperCase() + lowercased.slice(1);
})
.join('');
}
/**
* Create a safe filename from a string
* Removes/replaces characters that might cause issues in filenames
*/
export function toSafeFileName(str: string): string {
return str
.replace(/[<>:"/\\|?*]/g, '') // Remove unsafe chars for filenames
.replace(/\s+/g, '-') // Replace spaces with hyphens
.replace(/-+/g, '-') // Replace multiple hyphens with single
.replace(/^-+|-+$/g, '') // Remove leading/trailing hyphens
.toLowerCase()
.substring(0, 100); // Limit length to 100 chars
}