UNPKG

@gechiui/block-editor

Version:
22 lines (20 loc) 530 B
/** * External dependencies */ import { pickBy, isEmpty, isObject, identity, mapValues } from 'lodash'; /** * Removed falsy values from nested object. * * @param {*} object * @return {*} Object cleaned from falsy values */ export const cleanEmptyObject = ( object ) => { if ( ! isObject( object ) || Array.isArray( object ) ) { return object; } const cleanedNestedObjects = pickBy( mapValues( object, cleanEmptyObject ), identity ); return isEmpty( cleanedNestedObjects ) ? undefined : cleanedNestedObjects; };