Skip to content

Commit 98efb92

Browse files
committed
Initial version.
1 parent 583efbf commit 98efb92

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

lib/capitalize.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
/**
4+
* Capitalize Filter
5+
* Capitalizes all the words of a given sentence.
6+
* Specially adapted for team names.
7+
* i.e. CLUB DEPORTIVO LOGROÑÉS => Club Deportivo Logroñés
8+
* i.e. sd logroñés => SD Logroñés
9+
*/
10+
11+
angular.module('webApp')
12+
.filter('capitalize', function () {
13+
return function (input) {
14+
if (typeof input !== 'undefined') {
15+
var words = input.split(' ');
16+
var result = [];
17+
words.forEach(function(word) {
18+
if (word.length === 2) {
19+
// For team abbreviations like FC, CD, SD
20+
result.push(word.toUpperCase());
21+
} else {
22+
result.push(word.charAt(0).toUpperCase() + word.slice(1).toLowerCase());
23+
}
24+
});
25+
return result.join(' ');
26+
}
27+
};
28+
});

test/capitalize.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
describe('Filter: capitalize', function () {
4+
5+
// load the filter's module
6+
beforeEach(module('webApp'));
7+
8+
// initialize a new instance of the filter before each test
9+
var capitalize;
10+
beforeEach(inject(function ($filter) {
11+
capitalize = $filter('capitalize');
12+
}));
13+
14+
it('should return the uppercase input with all the words capitalized', function () {
15+
var text = 'CLUB DEPORTIVO LOGROÑÉS';
16+
expect(capitalize(text)).toBe('Club Deportivo Logroñés');
17+
});
18+
19+
it('should return the lowercase input with all the words capitalized', function () {
20+
var text = 'sd logroñés';
21+
expect(capitalize(text)).toBe('SD Logroñés');
22+
});
23+
24+
});

0 commit comments

Comments
 (0)