-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.js
More file actions
22 lines (19 loc) · 638 Bytes
/
Copy pathsearch.js
File metadata and controls
22 lines (19 loc) · 638 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
export const filterItems = (items, searchTerm) => {
if (!searchTerm) {
return items;
}
const lowerCaseSearchTerm = searchTerm.toLowerCase();
const searchWords = lowerCaseSearchTerm.split(' ').filter((w) => w);
return items.filter((item) => {
const targetText = [
item.title?.toLowerCase(),
item.type?.toLowerCase(),
...(item.tags || []).map((tag) => tag.toLowerCase()),
...(item.technologies || []).map((tech) => tech.toLowerCase()),
item.category?.toLowerCase(),
]
.filter(Boolean)
.join(' ');
return searchWords.every((word) => targetText.includes(word));
});
};