File tree 2 files changed +8
-0
lines changed 2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ function pascalcase(str) {
9
9
if ( typeof str !== 'string' ) {
10
10
throw new TypeError ( 'expected a string.' ) ;
11
11
}
12
+ str = str . replace ( / ( [ A - Z ] ) / g, ' $1' ) ;
12
13
if ( str . length === 1 ) { return str . toUpperCase ( ) ; }
13
14
str = str . replace ( / ^ [ \W _ ] + | [ \W _ ] + $ / g, '' ) . toLowerCase ( ) ;
14
15
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 () {
14
14
pascalcase ( 'foo bar baz' ) . should . equal ( 'FooBarBaz' ) ;
15
15
} ) ;
16
16
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
+
17
24
it ( 'should work with other non-word-characters:' , function ( ) {
18
25
pascalcase ( 'foo_bar-baz' ) . should . equal ( 'FooBarBaz' ) ;
19
26
pascalcase ( 'foo.bar.baz' ) . should . equal ( 'FooBarBaz' ) ;
You can’t perform that action at this time.
0 commit comments