1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-04 13:44:00 +01:00
bitwarden-browser/src/angular/pipes/search-ciphers.pipe.ts

48 lines
1.3 KiB
TypeScript
Raw Normal View History

import {
Pipe,
PipeTransform,
} from '@angular/core';
import { CipherView } from '../../models/view/cipherView';
2018-04-12 21:42:22 +02:00
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
@Pipe({
name: 'searchCiphers',
})
export class SearchCiphersPipe implements PipeTransform {
2018-04-12 21:42:22 +02:00
private onlySearchName = false;
constructor(private platformUtilsService: PlatformUtilsService) {
this.onlySearchName = platformUtilsService.isEdge();
}
transform(ciphers: CipherView[], searchText: string): CipherView[] {
if (ciphers == null || ciphers.length === 0) {
return [];
}
if (searchText == null || searchText.length < 2) {
return ciphers;
}
2018-07-06 20:11:47 +02:00
searchText = searchText.trim().toLowerCase();
return ciphers.filter((c) => {
if (c.name != null && c.name.toLowerCase().indexOf(searchText) > -1) {
return true;
}
2018-04-12 21:42:22 +02:00
if (this.onlySearchName) {
return false;
}
if (c.subTitle != null && c.subTitle.toLowerCase().indexOf(searchText) > -1) {
return true;
}
if (c.login && c.login.uri != null && c.login.uri.toLowerCase().indexOf(searchText) > -1) {
return true;
}
return false;
});
}
}