File tree Expand file tree Collapse file tree 2 files changed +7
-11
lines changed
Expand file tree Collapse file tree 2 files changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ describe('toCamel', () => {
55 expect ( toCamel ( 'to-camel' ) ) . toBe ( 'toCamel' )
66 expect ( toCamel ( 'to/camel' ) ) . toBe ( 'toCamel' )
77 expect ( toCamel ( 'toCamel' ) ) . toBe ( 'toCamel' )
8+ expect ( toCamel ( 'to/toCamel' ) ) . toBe ( 'toToCamel' )
9+ expect ( toCamel ( 'to-came/toCamel/ToCamel' ) ) . toBe ( 'toCameToCamelToCamel' )
810 expect ( toCamel ( 'TO_CAMEL' ) ) . toBe ( 'toCamel' )
911 expect ( toCamel ( 'TO-CAMEL' ) ) . toBe ( 'toCamel' )
1012 expect ( toCamel ( 'ToCamel' ) ) . toBe ( 'toCamel' )
Original file line number Diff line number Diff line change 11export function toCamel ( str : string ) : string {
2- if ( / [ - _ / ] / g. test ( str ) ) {
3- return str
4- . split ( / [ - _ / ] / )
5- . map ( ( word , index ) => {
6- if ( index === 0 ) return word . toLowerCase ( )
7- return word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) . toLowerCase ( )
8- } )
9- . join ( '' )
10- }
112 return str
12- . split ( / ( [ A - Z ] [ a - z ] + ) / )
13- . filter ( Boolean )
3+ . split ( / ( [ A - Z ] [ a - z ] + | [ - _ / ] ) / )
4+ . filter ( ( e ) => {
5+ if ( ! e || e === '-' || e === '_' || e === '/' || e === ' ' ) return false
6+ return true
7+ } )
148 . map ( ( word , index ) => {
159 if ( index === 0 ) return word . toLowerCase ( )
1610 return word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) . toLowerCase ( )
You can’t perform that action at this time.
0 commit comments