File tree 1 file changed +28
-20
lines changed
1 file changed +28
-20
lines changed Original file line number Diff line number Diff line change 5
5
6
6
function toCamelCase ( str ) {
7
7
// Determine if string includes - or underscore
8
- if ( str . includes ( '-' ) ) {
9
- return str
10
- . split ( '-' )
11
- . map ( ( word , idx ) => {
12
- if ( idx > 0 ) {
13
- return `${ word . charAt ( 0 ) . toUpperCase ( ) } ${ word . slice ( 1 ) } `
14
- }
15
- return word
16
- } )
17
- . join ( '' )
18
- } else if ( str . includes ( '_' ) ) {
19
- return str
20
- . split ( '_' )
21
- . map ( ( word , idx ) => {
22
- if ( idx > 0 ) {
23
- return `${ word . charAt ( 0 ) . toUpperCase ( ) } ${ word . slice ( 1 ) } `
24
- }
25
- return word
26
- } )
27
- . join ( '' )
8
+ // if (str.includes('-')) {
9
+ // return str
10
+ // .split('-')
11
+ // .map((word, idx) => {
12
+ // if (idx > 0) {
13
+ // return `${word.charAt(0).toUpperCase()}${word.slice(1)}`
14
+ // }
15
+ // return word
16
+ // })
17
+ // .join('')
18
+ // } else if (str.includes('_')) {
19
+ // return str
20
+ // .split('_')
21
+ // .map((word, idx) => {
22
+ // if (idx > 0) {
23
+ // return `${word.charAt(0).toUpperCase()}${word.slice(1)}`
24
+ // }
25
+ // return word
26
+ // })
27
+ // .join('')
28
+ // }
29
+
30
+ const words = str . split ( '-' ) . join ( '_' ) . split ( '_' )
31
+
32
+ for ( let i = 1 ; i < words . length ; i ++ ) {
33
+ words [ i ] = words [ i ] [ 0 ] . toUpperCase ( ) + words [ i ] . slice ( 1 )
28
34
}
35
+
36
+ return words . join ( '' )
29
37
}
30
38
31
39
// Split on dash or underscore
You can’t perform that action at this time.
0 commit comments