synapse-react-client
Version:
[](https://travis-ci.com/Sage-Bionetworks/Synapse-React-Client) [](https://badge.fury.io/js/synaps
29 lines • 927 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeUndefined = void 0;
/**
* Removes fields with value 'undefined' from an object (not recursive).
*
* Use the `inPlace` parameter to modify the object (using `delete`), rather than creating a new object.
*
* See https://stackoverflow.com/questions/25421233
*/
function removeUndefined(obj, inPlace) {
if (inPlace === void 0) { inPlace = false; }
if (inPlace) {
Object.keys(obj).forEach(function (key) {
return obj[key] === undefined ? delete obj[key] : {};
});
return obj;
}
else {
return Object.keys(obj).reduce(function (acc, key) {
var _acc = acc;
if (obj[key] !== undefined)
_acc[key] = obj[key];
return _acc;
}, {});
}
}
exports.removeUndefined = removeUndefined;
//# sourceMappingURL=ObjectUtils.js.map