Objeto JavaScript sem valores indefinidos

const buildAnObjectFromAQuery = query => (
  {  
   ...query.foo && { foo: query.foo },  
   ...query.bar && { bar: query.bar },
  }
);
Confused Caiman