# all files / -private/ regex-implementation.js

100% Statements 6/6
100% Branches 2/2
100% Functions 1/1
100% Lines 6/6

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29

    1×
    19×

    19×
    10×

    19×
    19×

     'use strict';

    import Ember from 'ember';

    /**
     * RegEx Implementation
     *
     * Highlight `value` input String with String.replace(RegExp) implementation that can be more performant on many
     * large texts than the indices implementation.
     *
     * @param {String} value The template string to highlight matches if any
     * @param {String} query The string to search in `value`
     * @param {Object} options
     * @param {Boolean} options.caseSensitive
     *
     * @returns {Ember.String.htmlSafe}
     */
    export default function (value, query, options) {
      let regexFlags = 'gm'; // g=global, m=multi-line

      if (!options.caseSensitive) {
        regexFlags += 'i';
      }

      let regexp = new RegExp(query, regexFlags);
      return new Ember.String.htmlSafe(value.replace(regexp, '<span class="mark">$&</span>'));
    }