snakeToPascalCase function
Converts a snake_case string to PascalCase.
Takes a string with underscores and converts it to PascalCase by:
- Splitting on underscores
- Capitalizing the first letter of each word
- Making the rest of each word lowercase
- Joining all words together
Examples:
snakeToPascalCase('user_profile') // Returns 'UserProfile'
snakeToPascalCase('first_name') // Returns 'FirstName'
snakeToPascalCase('id') // Returns 'Id'
snakeToPascalCase('') // Returns ''
text
The snake_case string to convert
Returns the converted PascalCase string
Implementation
String snakeToPascalCase(String text) {
if (text.isEmpty) return text;
return text
.split('_')
.map((word) => word[0].toUpperCase() + word.substring(1).toLowerCase())
.join();
}