File tree Expand file tree Collapse file tree 3 files changed +77
-0
lines changed
Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ ### Simple usage:
3+
4+ ``` var camelGotHumps = camelCaseRecursive({'test-1':123, 'test-2':{'test-3:':{'test-four':132}}});
5+
6+ //{ test1: 123, test2: { 'test3:': { testFour: 132 } } }
7+ console.log(camelGotHumps);```
8+
9+ ### Works with Arrays too:
10+
11+ ```
12+ var anotherCamelWithTheHump = camelCaseRecursive({
13+ 'test-1': 123,
14+ 'test-Two': [ {
15+ 'test-three': {
16+ 'test-FOUR': [ {'test-five':[ {testSix:{'test-seven':8}}] }]
17+ }
18+ }]
19+ });
20+
21+ {"test1":123,"testTwo":[ {"testThree":{"testFour":[ {"testFive":[ {"testSix":{"testSeven":8}}] }] }}] }console.log(JSON.stringify(anotherCamelWithTheHump));```
22+
23+ ### More information on internal modules
24+ Please refer to (camelcase)[ https://www.npmjs.com/package/camelcase ] , (map-obj)[ https://www.npmjs.com/package/map-obj ] and (isarray)[ https://www.npmjs.com/package/isarray ] npm modules
Original file line number Diff line number Diff line change 1+ var mapObj = require ( 'map-obj' ) ;
2+ var camelCase = require ( 'camelcase' ) ;
3+ var isArray = require ( 'isarray' ) ;
4+
5+ function camelCaseRecursive ( obj ) {
6+ return mapObj ( obj , function ( key , val ) {
7+ var newArray = [ ] ;
8+
9+ if ( isArray ( val ) ) {
10+
11+ val . forEach ( function ( value ) {
12+ newArray . push ( camelCaseRecursive ( value ) ) ;
13+ } ) ;
14+
15+ return [ camelCase ( key ) , newArray ] ;
16+
17+ } else if ( typeof ( val ) === 'object' ) {
18+
19+ return [ camelCase ( key ) , camelCaseRecursive ( val ) ] ;
20+
21+ } else {
22+
23+ return [ camelCase ( key ) , val ] ;
24+
25+ }
26+ } ) ;
27+ }
28+
29+ module . exports = camelCaseRecursive ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " camelcase-keys-recursive" ,
3+ "version" : " 0.0.1" ,
4+ "description" : " Adaptation of camelcase-keys but recursive. " ,
5+ "main" : " index.js" ,
6+ "scripts" : {
7+ "test" : " echo \" Error: no test specified\" && exit 1"
8+ },
9+ "keywords" : [
10+ " camelcase" ,
11+ " keys" ,
12+ " object" ,
13+ " recursive" ,
14+ " camelcase-keys" ,
15+ " snake-case"
16+ ],
17+ "author" : " mike james" ,
18+ "license" : " ISC" ,
19+ "dependencies" : {
20+ "camelcase" : " ^1.0.2" ,
21+ "isarray" : " 0.0.1" ,
22+ "map-obj" : " ^1.0.0"
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments