File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments