Case Naming Conventions Across Programming Ecosystems
- • Different programming languages and runtime frameworks adhere to strict identifier casing conventions:
- • camelCase: JavaScript/TypeScript variables, functions, and object properties (e.g., userProfileData).
- • PascalCase: React/Vue components, C# classes, and TypeScript type names (e.g., UserProfileCard).
- • snake_case: Python variables, PostgreSQL column names, and Rust identifiers (e.g., user_profile_data).
- • kebab-case: CSS class names, HTML attributes, and REST URL slugs (e.g., user-profile-data).
- • CONSTANT_CASE: Environment variables and global constants (e.g., MAX_RETRY_COUNT).
// Universal Casing Transformation Functions in TypeScript
export function toCamelCase(str: string): string {
return str.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (_, chr) => chr.toUpperCase());
}
export function toSnakeCase(str: string): string {
return str.replace(/([a-z])([A-Z])/g, '$1_$2').replace(/[^a-zA-Z0-9]+/g, '_').toLowerCase();
}
export function toKebabCase(str: string): string {
return str.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/[^a-zA-Z0-9]+/g, '-').toLowerCase();
}