@wordpress/block-library
Version:
Block library for the WordPress editor.
25 lines (20 loc) • 633 B
JavaScript
/**
* External dependencies
*/
import { isEmpty, mapValues, pickBy } from 'lodash';
const identity = x => x;
/**
* Removed empty nodes from nested objects.
*
* @param {Object} object
* @return {Object} Object cleaned from empty nodes.
*/
const cleanEmptyObject = object => {
if (object === null || typeof object !== 'object' || Array.isArray(object)) {
return object;
}
const cleanedNestedObjects = pickBy(mapValues(object, cleanEmptyObject), identity);
return isEmpty(cleanedNestedObjects) ? undefined : cleanedNestedObjects;
};
export default cleanEmptyObject;
//# sourceMappingURL=clean-empty-object.js.map