mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
search pipe
This commit is contained in:
parent
a600c4a539
commit
4aebc4ab3d
30
src/angular/pipes/search.pipe.ts
Normal file
30
src/angular/pipes/search.pipe.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import {
|
||||
Pipe,
|
||||
PipeTransform,
|
||||
} from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'search',
|
||||
})
|
||||
export class SearchPipe implements PipeTransform {
|
||||
transform(items: any[], searchText: string, prop1?: string, prop2?: string): any[] {
|
||||
if (items == null || items.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (searchText == null || searchText.length < 2) {
|
||||
return items;
|
||||
}
|
||||
|
||||
searchText = searchText.toLowerCase();
|
||||
return items.filter((i) => {
|
||||
if (prop1 != null && i[prop1] != null && i[prop1].toString().toLowerCase().indexOf(searchText) > -1) {
|
||||
return true;
|
||||
}
|
||||
if (prop2 != null && i[prop2] != null && i[prop2].toString().toLowerCase().indexOf(searchText) > -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user