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

Commit

Permalink
perf(util): call toLowerCase() only where needed
Browse files Browse the repository at this point in the history
Closes #1468
  • Loading branch information
vicb authored and vsavkin committed Sep 22, 2014
1 parent 26df7c2 commit 2bcd29e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ relaxFnArgs(Function fn) {
capitalize(String s) => s.substring(0, 1).toUpperCase() + s.substring(1);

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

/// Returns whether or not the given identifier is a reserved word in Dart.
Expand Down
4 changes: 4 additions & 0 deletions test/utils_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ main() {
it('should lowercase strings', () {
expect(camelCase('Caps-first')).toEqual('capsFirst');
});

it('should work on empty string', () {
expect(camelCase('')).toEqual('');
});
});
}

0 comments on commit 2bcd29e

Please sign in to comment.