Skip to content

Commit d21de21

Browse files
committed
moved to es15 added build step for babel compile
1 parent ea86e91 commit d21de21

File tree

7 files changed

+56
-69
lines changed

7 files changed

+56
-69
lines changed

.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "airbnb"
3+
}

.gitignore

+6
Original file line numberDiff line numberDiff 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/

.jshintrc

-22
This file was deleted.

index.js

-45
This file was deleted.

lib/.gitkeep

Whitespace-only changes.

package.json

+13-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
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",
@@ -28,7 +33,13 @@
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
}

src/index.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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;

0 commit comments

Comments
 (0)