First implem global search
[oweals/peertube.git] / client / src / app / shared / angular / highlight.pipe.ts
index e219b3823a3e98b231ee40d688523bff4bfdb51f..50ee5c1bd372d9894baae059900ab334ec609f2d 100644 (file)
@@ -11,26 +11,24 @@ export class HighlightPipe implements PipeTransform {
   /* use this for global search */
   static MULTI_MATCH = 'Multi-Match'
 
-  // tslint:disable-next-line:no-empty
-  constructor () {}
-
   transform (
-      contentString: string = null,
-      stringToHighlight: string = null,
-      option = 'Single-And-StartsWith-Match',
-      caseSensitive = false,
-      highlightStyleName = 'search-highlight'
+    contentString: string = null,
+    stringToHighlight: string = null,
+    option = 'Single-And-StartsWith-Match',
+    caseSensitive = false,
+    highlightStyleName = 'search-highlight'
   ): SafeHtml {
     if (stringToHighlight && contentString && option) {
       let regex: any = ''
       const caseFlag: string = !caseSensitive ? 'i' : ''
+
       switch (option) {
         case 'Single-Match': {
           regex = new RegExp(stringToHighlight, caseFlag)
           break
         }
         case 'Single-And-StartsWith-Match': {
-          regex = new RegExp("^" + stringToHighlight, caseFlag)
+          regex = new RegExp('^' + stringToHighlight, caseFlag)
           break
         }
         case 'Multi-Match': {
@@ -42,10 +40,12 @@ export class HighlightPipe implements PipeTransform {
           regex = new RegExp(stringToHighlight, 'gi')
         }
       }
+
       const replaced = contentString.replace(
-          regex,
-          (match) => `<span class="${highlightStyleName}">${match}</span>`
+        regex,
+        (match) => `<span class="${highlightStyleName}">${match}</span>`
       )
+
       return replaced
     } else {
       return contentString