Merge "PombaReqest and ServiceInstance improvements"
[vid.git] / vid-webpack-master / src / app / shared / pipes / highlight / highlight-filter.pipe.ts
1 import {PipeTransform, Pipe} from '@angular/core';
2 import * as _ from 'lodash';
3
4 @Pipe({ name: 'highlight' })
5 export class HighlightPipe implements PipeTransform {
6   transform(text: string, search: string): string {
7     if(_.isNil(text)) return text;
8     let pattern = search.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
9     let regex = new RegExp(pattern, 'gi');
10     return search ? text.replace(regex, (match) => `<span class="highlight">${match}</span>`) : text;
11   }
12 }