@@ -221,27 +221,30 @@ angular.module('ui.indeterminate',[]).directive('uiIndeterminate', [
221221 * {{ 'Here Is my_phoneNumber' | inflector:'variable' }} => hereIsMyPhoneNumber
222222 */
223223angular . 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 ( ' ' ) ;
228228 }
229229
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 ) ) ;
233234 } ) ;
235+ return result ;
234236 }
235237
236238 var inflectors = {
237239 humanize : function ( value ) {
238- return ucwords ( breakup ( value , ' ' ) . split ( '_' ) . join ( ' ' ) ) ;
240+ return capitalizeTokens ( tokenize ( value ) ) . join ( ' ' ) ;
239241 } ,
240242 underscore : function ( value ) {
241- return value . substr ( 0 , 1 ) . toLowerCase ( ) + breakup ( value . substr ( 1 ) , '_' ) . toLowerCase ( ) . split ( ' ' ) . join ( '_' ) ;
243+ return tokenize ( value ) . join ( '_' ) ;
242244 } ,
243245 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 ( '' ) ;
245248 return value ;
246249 }
247250 } ;
0 commit comments