Warunkowy operator spreadu JSON

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