-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.pipe.ts
More file actions
28 lines (26 loc) · 849 Bytes
/
filter.pipe.ts
File metadata and controls
28 lines (26 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* Pipe for search filter from https://dev.to/idrisrampurawala/creating-a-search-filter-in-angular-562d
*/
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'appFilter' })
export class FilterPipe implements PipeTransform {
/**
* Pipe filters the list of elements based on the search text provided
*
* @param items list of elements to search in
* @param searchText search string
* @returns list of elements filtered by search text or []
*/
transform(items: any[], searchText: string): any[] {
if (!items) {
return [];
}
if (!searchText) {
return items;
}
searchText = searchText.toLocaleLowerCase();
return items.filter(it => {
return it.name.toLocaleLowerCase().includes(searchText);
});
}
}