Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,35 @@ var snakeCase = require('snake-case');
var paramCase = require('param-case');

var changeKeys = function changeKeys(transformer, obj) {
if (!obj)
return obj;
if (Array.isArray(obj)) {
var r = [];
for (var i = 0; i < obj.length; i++) {
r.push(changeKeys(transformer, obj[i]));
}
return r;
} else if (typeof obj === 'object') {
}
else if (obj instanceof Date) {
return obj;
}
else if (typeof obj === 'object' && obj) {

var objectKeys = Object.keys(obj);
return objectKeys.map(function keysMap(key) {
return transformer(key);
}).reduce(function keysReducer(object, changedKey, index) {
var objValue = obj[objectKeys[index]];
// console.log(objValue);
var transformedValue = changeKeys(transformer, objValue);
object[changedKey] = transformedValue;
return object;
}, {});
}
else if (typeof obj === 'string') {
return transformer(obj);

}
else {
return obj;
}

};

var changeCaseObject = {};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "change-case-object",
"name": "hm-change-case-object",
"version": "1.0.1",
"description": "Changes the case of all keys of an object",
"main": "index.js",
Expand Down