File tree 7 files changed +56
-69
lines changed
7 files changed +56
-69
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "extends": "airbnb"
3
+ }
Original file line number Diff line number Diff line change @@ -26,3 +26,9 @@ node_modules
26
26
27
27
# Users Environment Variables
28
28
.lock-wscript
29
+
30
+ fixtures /
31
+ coverage /
32
+ * .tpm
33
+ .idea /
34
+ lib /
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 6
6
"type" : " git" ,
7
7
"url" : " git://github.com/mikeljames/camelcase-keys-recursive.git"
8
8
},
9
- "main" : " index.js" ,
9
+ "main" : " src/ index.js" ,
10
10
"scripts" : {
11
- "test" : " ./node_modules/mocha/bin/mocha"
11
+ "compile" : " babel --source-maps --out-dir lib/ src/" ,
12
+ "lint" : " eslint --ext .js --ext .jsx ./ && echo No linting errors." ,
13
+ "test" : " node_modules/.bin/mocha test/ --recursive --compilers js:babel/register" ,
14
+ "test:watch" : " npm run test -- --watch" ,
15
+ "coverage" : " node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha -- --compilers js:babel/register --colors --reporter dot test/" ,
16
+ "prepublish" : " npm run compile"
12
17
},
13
18
"keywords" : [
14
19
" camelcase" ,
28
33
"map-obj" : " ^1.0.0"
29
34
},
30
35
"devDependencies" : {
36
+ "babel" : " ^5.x.x" ,
37
+ "babel-eslint" : " ^4.1.5" ,
31
38
"chai" : " ^2.1.1" ,
39
+ "eslint" : " ^1.9.0" ,
40
+ "eslint-config-airbnb" : " ^1.0.0" ,
41
+ "eslint-plugin-react" : " ^3.8.0" ,
42
+ "istanbul" : " ^0.4.0" ,
32
43
"mocha" : " ^2.2.1" ,
33
44
"pre-commit" : " ^1.0.6"
34
45
}
Original file line number Diff line number Diff line change
1
+ import mapObj from 'map-obj' ;
2
+
3
+ const isObject = ( v ) => typeof ( v ) === 'object' ;
4
+
5
+ const camelCase = ( str ) => str . replace ( / [ _ . - ] ( \w | $ ) / g, ( _ , x ) => x . toUpperCase ( ) ) ;
6
+
7
+
8
+ function camelCaseRecursive ( obj ) {
9
+ return mapObj ( obj , ( key , val ) => {
10
+ const newArray = [ ] ;
11
+
12
+ if ( Array . isArray ( val ) ) {
13
+ val . forEach ( ( value ) => {
14
+ if ( isObject ( value ) && ! Array . isArray ( value ) ) {
15
+ newArray . push ( camelCaseRecursive ( value ) ) ;
16
+ } else {
17
+ newArray . push ( value ) ;
18
+ }
19
+ } ) ;
20
+
21
+ return [ camelCase ( key ) , newArray ] ;
22
+ } else if ( ! val ) {
23
+ return [ camelCase ( key ) , val ] ;
24
+ } else if ( val instanceof Date ) {
25
+ return [ camelCase ( key ) , val ] ;
26
+ } else if ( isObject ( val ) ) {
27
+ return [ camelCase ( key ) , camelCaseRecursive ( val ) ] ;
28
+ }
29
+
30
+ return [ camelCase ( key ) , val ] ;
31
+ } ) ;
32
+ }
33
+
34
+ export default camelCaseRecursive ;
You can’t perform that action at this time.
0 commit comments