-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Hello, would you be willing to support recursion on objects/arrays?
I've implemented it in my project using the following (ES6) - I would have sent you a PR, but coffee script is not my thing.
// Apply a morph function recursively
function morphObjectProps (obj, fn) {
if (!obj) {
return obj;
}
if (Array.isArray(obj)) {
return obj.map((item) => {
return morphObjectProps(item, fn);
});
}
return Object.keys(obj).reduce((memo, key) => {
let value = obj[key];
if (typeof val === 'object') {
memo[fn(key)] = morphObjectProps(value);
}
else {
memo[fn(key)] = value;
}
return memo;
}, {});
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels