@@ -221,27 +221,30 @@ angular.module('ui.indeterminate',[]).directive('uiIndeterminate', [
221
221
* {{ 'Here Is my_phoneNumber' | inflector:'variable' }} => hereIsMyPhoneNumber
222
222
*/
223
223
angular . module ( 'ui.inflector' , [ ] ) . filter ( 'inflector' , function ( ) {
224
- function ucwords ( text ) {
225
- return text . replace ( / ^ ( [ a - z ] ) | \s + ( [ a - z ] ) / g , function ( $1 ) {
226
- return $1 . toUpperCase ( ) ;
227
- } ) ;
224
+
225
+ function tokenize ( text ) {
226
+ text = text . replace ( / ( [ A - Z ] ) | ( [ \- | \_ ] ) / g , function ( _ , $1 ) { return ' ' + ( $1 || '' ) ; } ) ;
227
+ return text . replace ( / \s \s + / g , ' ' ) . trim ( ) . toLowerCase ( ) . split ( ' ' ) ;
228
228
}
229
229
230
- function breakup ( text , separator ) {
231
- return text . replace ( / [ A - Z ] / g, function ( match ) {
232
- return separator + match ;
230
+ function capitalizeTokens ( tokens ) {
231
+ var result = [ ] ;
232
+ angular . forEach ( tokens , function ( token ) {
233
+ result . push ( token . charAt ( 0 ) . toUpperCase ( ) + token . substr ( 1 ) ) ;
233
234
} ) ;
235
+ return result ;
234
236
}
235
237
236
238
var inflectors = {
237
239
humanize : function ( value ) {
238
- return ucwords ( breakup ( value , ' ' ) . split ( '_' ) . join ( ' ' ) ) ;
240
+ return capitalizeTokens ( tokenize ( value ) ) . join ( ' ' ) ;
239
241
} ,
240
242
underscore : function ( value ) {
241
- return value . substr ( 0 , 1 ) . toLowerCase ( ) + breakup ( value . substr ( 1 ) , '_' ) . toLowerCase ( ) . split ( ' ' ) . join ( '_' ) ;
243
+ return tokenize ( value ) . join ( '_' ) ;
242
244
} ,
243
245
variable : function ( value ) {
244
- value = value . substr ( 0 , 1 ) . toLowerCase ( ) + ucwords ( value . split ( '_' ) . join ( ' ' ) ) . substr ( 1 ) . split ( ' ' ) . join ( '' ) ;
246
+ value = tokenize ( value ) ;
247
+ value = value [ 0 ] + capitalizeTokens ( value . slice ( 1 ) ) . join ( '' ) ;
245
248
return value ;
246
249
}
247
250
} ;
0 commit comments