Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/src/string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ extension StringCapitalizeExtension on String {
}
}

extension StringWordCapitalize on String {
String wordFormatCapitalize() {
final result = split(' ');
final buffer = StringBuffer();
buffer.write(result.map((e) => e.capitalize()).join(' '));
return buffer.toString();
}
}

extension StringDecapitalizeExtension on String {
/// Returns a copy of this string having its first letter lowercased, or the
/// original string, if it's empty or already starts with a lower case letter.
Expand Down
8 changes: 8 additions & 0 deletions test/string_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ void main() {
expect('Test'.capitalize(), 'Test');
});

test('Word Capitalize', () {
expect('lorem ipsum'.wordFormatCapitalize(), 'Lorem Ipsum');
expect('lorem'.wordFormatCapitalize(), 'Lorem');
expect('123'.wordFormatCapitalize(), '123');
expect(''.wordFormatCapitalize(), '');
expect('123 123 a123'.wordFormatCapitalize(), '123 123 A123');
});

test('.decapitalize()', () {
expect(''.decapitalize(), '');
expect('123'.decapitalize(), '123');
Expand Down