Skip to content

Commit

Permalink
feat : add ID to search filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Juknum committed Aug 18, 2024
1 parent 83e4c70 commit 1896776
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ export function sortByName<T extends { name: string, id?: string | number }>(a:
return a.name.localeCompare(b.name) || `${a.id}`.localeCompare(`${b.id}` ?? '') || 0;
}

export function searchFilter<T extends { name: string, aliases?: string[] }>(search: string) {
export function searchFilter<T extends { id: string | number; name: string, aliases?: string[] }>(search: string) {
return (item: T) => {
const searchLower = search.toLowerCase();
const name = item.name.toLowerCase();
const id = `${item.id}`.toLowerCase();
const aliases = item.aliases?.map((alias) => alias.toLowerCase()) ?? [];

return name.includes(searchLower) || aliases.some((alias) => alias.includes(searchLower));
return id === searchLower || name.includes(searchLower) || aliases.some((alias) => alias.includes(searchLower));
};
}

Expand Down

0 comments on commit 1896776

Please sign in to comment.