File tree Expand file tree Collapse file tree 1 file changed +20
-16
lines changed Expand file tree Collapse file tree 1 file changed +20
-16
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
- let returnString = ''
9
8
if ( str . includes ( '-' ) ) {
10
- returnString = str . split ( '-' ) . map ( ( word , idx ) => {
11
- if ( idx > 0 ) {
12
- return `${ word . charAt ( 0 ) . toUpperCase ( ) } ${ word . slice ( 1 ) } `
13
- }
14
- return word
15
- } )
16
- return returnString . join ( '' )
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 ( '' )
17
18
} else if ( str . includes ( '_' ) ) {
18
- returnString = str . split ( '_' ) . map ( ( word , idx ) => {
19
- if ( idx > 0 ) {
20
- return `${ word . charAt ( 0 ) . toUpperCase ( ) } ${ word . slice ( 1 ) } `
21
- }
22
- return word
23
- } )
24
- return returnString . join ( '' )
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 ( '' )
25
28
}
26
29
}
27
30
@@ -31,4 +34,5 @@ function toCamelCase(str) {
31
34
// return string
32
35
console . log ( toCamelCase ( 'the-stealth-warrior' ) , 'theStealthWarrior' )
33
36
console . log ( toCamelCase ( 'The_Templar_warrior' ) , 'TheTemplarWarrior' )
34
- console . log ( toCamelCase ( 'The-Templar-warrior' ) , 'TheTemplarWarrior' )
37
+ console . log ( toCamelCase ( 'A_Pippi_isEvil' ) , 'APippiIsEvil' )
38
+ console . log ( toCamelCase ( 'a_pippiIsPippi' ) , 'aPippiIsPippi' )
You can’t perform that action at this time.
0 commit comments