operador de espalhamento JSON condicional

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