File tree Expand file tree Collapse file tree 7 files changed +56
-69
lines changed
Expand file tree Collapse file tree 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
2626
2727# Users Environment Variables
2828.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 66 "type" : " git" ,
77 "url" : " git://github.com/mikeljames/camelcase-keys-recursive.git"
88 },
9- "main" : " index.js" ,
9+ "main" : " src/ index.js" ,
1010 "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"
1217 },
1318 "keywords" : [
1419 " camelcase" ,
2833 "map-obj" : " ^1.0.0"
2934 },
3035 "devDependencies" : {
36+ "babel" : " ^5.x.x" ,
37+ "babel-eslint" : " ^4.1.5" ,
3138 "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" ,
3243 "mocha" : " ^2.2.1" ,
3344 "pre-commit" : " ^1.0.6"
3445 }
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