src/app/pipes/template-dictionary-filter.pipe.ts
name | templateDictionaryFilter |
transform |
transform(input: Object, targetRaw: string)
|
Returns :
Object
|
import { Pipe, PipeTransform } from '@angular/core';
import { Template } from '../models';
import { ExtendedArray } from '../extensions/extended-array';
// tslint:disable-next-line:use-pipe-transform-interface
@Pipe({
name: 'templateDictionaryFilter'
})
export class TemplateDictionaryFilterPipe {
transform(input: Object, targetRaw: string): Object {
// tslint:disable-next-line:curly
if (
input === null ||
input === undefined ||
targetRaw === null ||
targetRaw === undefined
)
return input;
const target = targetRaw.toLowerCase();
const keys = Object.keys(input);
let found = new Array();
keys.map(key => {
const matched = input[key].filter((template: Template) => {
return (
template.name.toLowerCase().indexOf(target) > -1 ||
(template.p2PPayToEmailAddress &&
template.p2PPayToEmailAddress.toLowerCase().indexOf(target) > -1) ||
(template.p2PPayToPhoneNumber &&
template.p2PPayToPhoneNumber.toLowerCase().indexOf(target) > -1)
);
});
found = matched.concat(found);
});
const tmp = new ExtendedArray<Template>(found);
return tmp.groupBy('firstCharOfName');
}
}