Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 2bcd29e

Browse files
vicbvsavkin
authored andcommitted
perf(util): call toLowerCase() only where needed
Closes #1468
1 parent 26df7c2 commit 2bcd29e

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/utils.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ relaxFnArgs(Function fn) {
8282
capitalize(String s) => s.substring(0, 1).toUpperCase() + s.substring(1);
8383

8484
String camelCase(String s) {
85-
var part = s.split('-').map((s) => s.toLowerCase());
86-
if (part.length <= 1) return part.join();
87-
return part.first + part.skip(1).map(capitalize).join();
85+
var parts = s.split('-');
86+
return parts.first.toLowerCase() + parts.skip(1).map(capitalize).join();
8887
}
8988

9089
/// Returns whether or not the given identifier is a reserved word in Dart.

test/utils_spec.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ main() {
4444
it('should lowercase strings', () {
4545
expect(camelCase('Caps-first')).toEqual('capsFirst');
4646
});
47+
48+
it('should work on empty string', () {
49+
expect(camelCase('')).toEqual('');
50+
});
4751
});
4852
}
4953

0 commit comments

Comments
 (0)