bitwarden-estensione-browser/src/angular/pipes/search.pipe.ts

31 lines
868 B
TypeScript
Raw Normal View History

2018-07-06 18:40:08 +02:00
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;
}
2018-07-06 20:11:47 +02:00
searchText = searchText.trim().toLowerCase();
2018-07-06 18:40:08 +02:00
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;
});
}
}