File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ function pascalcase(str) {
99 if ( typeof str !== 'string' ) {
1010 throw new TypeError ( 'expected a string.' ) ;
1111 }
12+ str = str . replace ( / ( [ A - Z ] ) / g, ' $1' ) ;
1213 if ( str . length === 1 ) { return str . toUpperCase ( ) ; }
1314 str = str . replace ( / ^ [ \W _ ] + | [ \W _ ] + $ / g, '' ) . toLowerCase ( ) ;
1415 str = str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
Original file line number Diff line number Diff line change @@ -14,6 +14,13 @@ describe('pascalcase', function () {
1414 pascalcase ( 'foo bar baz' ) . should . equal ( 'FooBarBaz' ) ;
1515 } ) ;
1616
17+ it ( 'should not lowercase existing camelcasing:' , function ( ) {
18+ pascalcase ( 'fooBarBaz' ) . should . equal ( 'FooBarBaz' ) ;
19+ pascalcase ( 'FooBarBaz' ) . should . equal ( 'FooBarBaz' ) ;
20+ pascalcase ( ' FooBarBaz' ) . should . equal ( 'FooBarBaz' ) ;
21+ pascalcase ( ' fooBarBaz' ) . should . equal ( 'FooBarBaz' ) ;
22+ } ) ;
23+
1724 it ( 'should work with other non-word-characters:' , function ( ) {
1825 pascalcase ( 'foo_bar-baz' ) . should . equal ( 'FooBarBaz' ) ;
1926 pascalcase ( 'foo.bar.baz' ) . should . equal ( 'FooBarBaz' ) ;
You can’t perform that action at this time.
0 commit comments