util-helpers
Version:
27 lines (23 loc) • 859 B
JavaScript
;
var ut2 = require('ut2');
var transformObjectValue = function (data, fn, deep) {
if (deep === void 0) { deep = true; }
if (ut2.isPlainObject(data)) {
var result_1 = {};
ut2.forEach(data, function (value, key) {
var newValue = deep && (ut2.isPlainObject(value) || ut2.isArray(value)) ? transformObjectValue(value, fn) : fn(value, key);
result_1[key] = newValue;
});
return result_1;
}
else if (ut2.isArray(data)) {
var result_2 = [];
ut2.forEach(data, function (value, index) {
var newValue = deep && (ut2.isPlainObject(value) || ut2.isArray(value)) ? transformObjectValue(value, fn) : fn(value, index);
result_2.push(newValue);
});
return result_2;
}
return data;
};
module.exports = transformObjectValue;