export function cleanArray ( obj ) { obj = obj . map ( ( i ) => cleanObject ( i ) ) . filter ( ( i ) => i != null ) ; if ( ! obj . length ) return undefined ; return obj ; } /**
 * Remove undefined, empty objects, empty arrays from an object.
 *
 */ export function cleanObject ( obj ) { if ( obj == null ) return undefined ; if ( Array . isArray ( obj ) ) return cleanArray ( obj ) ; if ( typeof obj !== 'object' ) return obj ; for ( const key of Object . keys ( obj ) ) { if ( obj [ key ] == null ) { delete obj [ key ] ; } else if ( typeof obj [ key ] === 'object' ) { obj [ key ] = cleanObject ( obj [ key ] ) ; if ( obj [ key ] == null ) delete obj [ key ] ; } else if ( Array . isArray ( obj [ key ] ) ) { obj [ key ] = cleanArray ( obj [ key ] ) ; if ( obj [ key ] == null ) delete obj [ key ] ; } } if ( ! Object . keys ( obj ) . length ) return undefined ; return obj ; }