util-helpers
Version:
25 lines (22 loc) • 846 B
JavaScript
import { isPlainObject, forEach, isArray } from 'ut2';
var transformObjectValue = function (data, fn, deep) {
if (deep === void 0) { deep = true; }
if (isPlainObject(data)) {
var result_1 = {};
forEach(data, function (value, key) {
var newValue = deep && (isPlainObject(value) || isArray(value)) ? transformObjectValue(value, fn) : fn(value, key);
result_1[key] = newValue;
});
return result_1;
}
else if (isArray(data)) {
var result_2 = [];
forEach(data, function (value, index) {
var newValue = deep && (isPlainObject(value) || isArray(value)) ? transformObjectValue(value, fn) : fn(value, index);
result_2.push(newValue);
});
return result_2;
}
return data;
};
export { transformObjectValue as default };