ice.fo.utils
Version:
24 lines (19 loc) • 565 B
JavaScript
import _isEmpty from 'lodash/isEmpty';
import _isPlainObject from 'lodash/isPlainObject';
export default function cleanEmptyPropValues(target) {
const result = {};
for (const k in target) {
if (typeof target[k] != 'number' && typeof target[k] != 'boolean' && _isEmpty(target[k])) {
continue;
}
if (_isPlainObject(target[k])) {
const value = cleanEmptyPropValues(target[k]);
if (value != null) {
result[k] = value;
}
} else {
result[k] = target[k];
}
}
return _isEmpty(result) ? null : result;
}