Jonny Borges
Committed by GitHub

Merge pull request #980 from eduardoflorence/improve-capitalize

Utils: capitalize cannot convert space to null
... ... @@ -518,17 +518,16 @@ class GetUtils {
/// Capitalize each word inside string
/// Example: your name => Your Name, your name => Your name
static String capitalize(String value) {
if (isNullOrBlank(value)) return null;
if (isNull(value)) return null;
if (isBlank(value)) return value;
return value.split(' ').map(capitalizeFirst).join(' ');
}
/// Uppercase first letter inside string and let the others lowercase
/// Example: your name => Your name
static String capitalizeFirst(String s) {
if (isNullOrBlank(s)) {
return null;
}
if (isNull(s)) return null;
if (isBlank(s)) return s;
return s[0].toUpperCase() + s.substring(1).toLowerCase();
}
... ...
... ... @@ -679,14 +679,17 @@ void main() {
expect('foo bar'.capitalize, 'Foo Bar');
expect('FoO bAr'.capitalize, 'Foo Bar');
expect('FOO BAR'.capitalize, 'Foo Bar');
expect(''.capitalize, null);
expect(null.capitalize, null);
expect(''.capitalize, '');
expect('foo bar '.capitalize, 'Foo Bar ');
});
test('var.capitalizeFirst', () {
expect('foo bar'.capitalizeFirst, 'Foo bar');
expect('FoO bAr'.capitalizeFirst, 'Foo bar');
expect('FOO BAR'.capitalizeFirst, 'Foo bar');
expect(''.capitalizeFirst, null);
expect(null.capitalizeFirst, null);
expect(''.capitalizeFirst, '');
});
test('var.removeAllWhitespace', () {
... ...