# All files / utils/src ngui-highlight.pipe.ts

100% Statements 12/12
100% Branches 2/2
100% Functions 3/3
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    154x

    4x
    4x
    2x
    2x
    1x
    1x

    2x

    4x
     import { Pipe, PipeTransform } from '@angular/core';

    @Pipe({ name: 'nguiHighlight' })
    export class NguiHighlightPipe implements PipeTransform {
      transform(text: string, search: string): string {
        let ret = text;
        if (search) {
          const re  = new RegExp(search, 'ig');
          ret = text.replace(re, match => `<span class="ngui-highlight">${match}</span>`);
        }

        return ret;
      }
    }