snakeToPascalCase function

String snakeToPascalCase(
  1. String text
)

Converts a snake_case string to PascalCase.

Takes a string with underscores and converts it to PascalCase by:

  1. Splitting on underscores
  2. Capitalizing the first letter of each word
  3. Making the rest of each word lowercase
  4. 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();
}