forked from github-starred/komodo
common filtering method
This commit is contained in:
@@ -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) ?? []
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user