toPascalCase method
Pascal-cases this string.
wordSeparators is used to separate words if separators
is not given.
'camelCase'.toPascalCase(); // 'CamelCase'
'PascalCase'.toPascalCase(); // 'PascalCase'
'SCREAMING_CASE'.toPascalCase(); // 'ScreamingCase'
'snake_case'.toPascalCase(); // 'SnakeCase'
'kebab-case'.toPascalCase(); // 'KebabCase'
'Title Case'.toPascalCase(); // 'TitleCase'
'Sentence case'.toPascalCase(); // 'SentenceCase'
Implementation
@useResult String toPascalCase([Pattern? separators]) {
final buffer = StringBuffer();
for (final word in split(separators ?? wordSeparators)) {
if (isNotEmpty) {
buffer..write(word[0].toUpperCase())..write(word.substring(1).toLowerCase());
}
}
return buffer.toString();
}