import { Pipe, PipeTransform } from '@angular/core';
import { radio } from '../classes/radio';
@Pipe({ name: 'searchRadio' })
export class SearchRadioPipe implements PipeTransform {
transform(allRadios: radio[] , name :string , location:string) {
let result ;
let final ;
let respat = RegExp(".","g"); // match any thing
if(name.length != 0){
respat = RegExp("^.*"+name+".*$","gi");
result = allRadios.filter(radio => radio.name.search(respat)!=-1);
}
else{
result = allRadios;
}
// location search from result and not from arg
if(location.length != 0){
let locreg = RegExp("^.*"+location+".*$","gi");
final = result.filter(radio => radio.location.search(locreg)!=-1);
}
else{
final = result ;
}
return final;
}
}