Combining multiple filters defined using Filter

I have two filters f1 and f2 defined using Filter as follows:

f1 = Filter.ge('start', prevMonth)
f2 = Filter.lt('start', endDate)

How can I combine f1 and f2 to get the equivalent of f1 AND f2:

Filter.ge('start', prevMonth).and.lt('start', endDate)

One way to do this is:

`f1.toString() + " && " + f2.toString()`

But I was wondering if there is a more elegant way (i.e. using Filter methods).

You could use the Filter#lit method (“lit” as in “literal”) and pass a Filter object:

f1 = Filter.ge('start', prevMonth);
f2 = Filter.lt('start', endDate);

// v7.9 and later
f1.and().lit(f2);

// v7.8 and below
f1.and.lit(f2); // Beware: mutates f1
Filter.lit(f1).and.lit(f2); // does not mutate either f1 or f2
3 Likes