Skip to content

Commit ee0ff13

Browse files
committed
init
0 parents  commit ee0ff13

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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

index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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;

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

0 commit comments

Comments
 (0)