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