aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/pipes/highlight-filter.pipe.ts
diff options
context:
space:
mode:
Diffstat (limited to 'vid-webpack-master/src/app/shared/pipes/highlight-filter.pipe.ts')
-rw-r--r--vid-webpack-master/src/app/shared/pipes/highlight-filter.pipe.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/pipes/highlight-filter.pipe.ts b/vid-webpack-master/src/app/shared/pipes/highlight-filter.pipe.ts
new file mode 100644
index 000000000..93aecbf69
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/pipes/highlight-filter.pipe.ts
@@ -0,0 +1,10 @@
+import {PipeTransform, Pipe} from '@angular/core';
+
+@Pipe({ name: 'highlight' })
+export class HighlightPipe implements PipeTransform {
+ transform(text: string, search: string): string {
+ let pattern = search.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
+ let regex = new RegExp(pattern, 'gi');
+ return search ? text.replace(regex, (match) => `<span class="highlight">${match}</span>`) : text;
+ }
+}