utils.tsx 444 B

1234567891011121314151617181920
  1. export function filterItems<I extends object, K extends string>({
  2. filterFns,
  3. filterVals,
  4. items,
  5. }: {
  6. filterFns: Record<K, (item: I, val: any) => boolean>;
  7. filterVals: Record<K, any>;
  8. items: I[];
  9. }) {
  10. return items.filter(item => {
  11. for (const key in filterFns) {
  12. const filter = filterFns[key];
  13. const val = filterVals[key];
  14. if (!filter(item, val)) {
  15. return false;
  16. }
  17. }
  18. return true;
  19. });
  20. }