File tree Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -5,19 +5,21 @@ module fng.filters {
5
5
/*@ngInject */
6
6
export function titleCase ( ) {
7
7
return function ( str , stripSpaces ) {
8
- var value = str
9
- . replace ( / ( _ | \. ) / g, ' ' ) // replace underscores and dots with spaces
10
- . replace ( / [ A - Z ] / g, ' $&' ) . trim ( ) // precede replace caps with a space
11
- . replace ( / \w \S * / g, function ( txt ) { // capitalise first letter of word
12
- return txt . charAt ( 0 ) . toUpperCase ( ) + txt . substr ( 1 ) . toLowerCase ( ) ;
13
- } ) ;
14
- if ( stripSpaces ) {
15
- value = value . replace ( / \s / g, '' ) ;
16
- } else {
17
- // lose double spaces
18
- value = value . replace ( / \s { 2 , } / g, ' ' ) ;
8
+ if ( str ) {
9
+ str = str
10
+ . replace ( / ( _ | \. ) / g, ' ' ) // replace underscores and dots with spaces
11
+ . replace ( / [ A - Z ] / g, ' $&' ) . trim ( ) // precede replace caps with a space
12
+ . replace ( / \w \S * / g, function ( txt ) { // capitalise first letter of word
13
+ return txt . charAt ( 0 ) . toUpperCase ( ) + txt . substr ( 1 ) . toLowerCase ( ) ;
14
+ } ) ;
15
+ if ( stripSpaces ) {
16
+ str = str . replace ( / \s / g, '' ) ;
17
+ } else {
18
+ // lose double spaces
19
+ str = str . replace ( / \s { 2 , } / g, ' ' ) ;
20
+ }
19
21
}
20
- return value ;
21
- } ;
22
+ return str ;
23
+ }
22
24
}
23
25
}
You can’t perform that action at this time.
0 commit comments