common filtering method

This commit is contained in:
mbecker20
2024-06-04 05:50:36 -07:00
parent 17da4bd2fa
commit 676fb3c732
30 changed files with 192 additions and 169 deletions

View File

@@ -156,4 +156,20 @@ export const getUpdateQuery = (
"target.id": target.id,
};
}
};
};
export const filterBySplit = <T>(
items: T[] | undefined,
search: string,
extract: (item: T) => string
) => {
const split = search.toLowerCase().split(" ");
return (
(split.length
? items?.filter((item) => {
const target = extract(item);
return split.every((term) => target.includes(term));
})
: items) ?? []
);
};