index.js
function (str, highlight) {
      highlight = highlight || false;
      var self = this;

      var highlightColor = this.highlightColor;
      var replace = function (str, pattern) {
        if (!highlight) {
          return str.replace(pattern, function (match) {
            self.currentMatch.matches.push(match);
            return self.replacementString;
          });
        }

        return str.replace(pattern, function (match) {
          self.currentMatch.matches.push(match);
          return '<span style="background: #' + highlightColor + ';">' + match + '</span>';
        });
      }.bind(this);

      if (typeof str !== 'string') {
        throw 'Invalid "str" type supplied in filterString. Expected string.';
      }

      for (var p in this.patterns) {
        if (!this.patterns[p].enabled) {
          continue;
        }

        if (this.patterns[p].pattern instanceof RegExp) {
          str = replace(str, this.patterns[p].pattern);

          continue;
        }

        if (!this.isArray(this.patterns[p].pattern)) {
          throw 'Invalid pattern type supplied. Expected Array.';
        }

        for (var i = 0; i < this.patterns[p].pattern.length; i++) {
          if (!this.patterns[p].pattern[i] instanceof RegExp) {
            throw 'Expected valid RegExp.';
          }

          str = replace(str, this.patterns[p].pattern[i]);
        }
      }

      return str;
    }
function (str, highlight) {
      highlight = highlight || false;
      var self = this;

      var highlightColor = this.highlightColor;
      var replace = function (str, pattern) {
        if (!highlight) {
          return str.replace(pattern, function (match) {
            self.currentMatch.matches.push(match);
            return self.replacementString;
          });
        }

        return str.replace(pattern, function (match) {
          self.currentMatch.matches.push(match);
          return '<span style="background: #' + highlightColor + ';">' + match + '</span>';
        });
      }.bind(this);

      if (typeof str !== 'string') {
        throw 'Invalid "str" type supplied in filterString. Expected string.';
      }

      for (var p in this.patterns) {
        if (!this.patterns[p].enabled) {
          continue;
        }

        if (this.patterns[p].pattern instanceof RegExp) {
          str = replace(str, this.patterns[p].pattern);

          continue;
        }

        if (!this.isArray(this.patterns[p].pattern)) {
          throw 'Invalid pattern type supplied. Expected Array.';
        }

        for (var i = 0; i < this.patterns[p].pattern.length; i++) {
          if (!this.patterns[p].pattern[i] instanceof RegExp) {
            throw 'Expected valid RegExp.';
          }

          str = replace(str, this.patterns[p].pattern[i]);
        }
      }

      return str;
    }
function ( str , highlight ) { highlight = highlight || false ; var self = this ; var highlightColor = this . highlightColor ; var replace = function ( str , pattern ) { if ( ! highlight ) { return str . replace ( pattern , function ( match ) { self . currentMatch . matches . push ( match ) ; return self . replacementString ; } ) ; } return str . replace ( pattern , function ( match ) { self . currentMatch . matches . push ( match ) ; return '<span style="background: #' + highlightColor + ';">' + match + '</span>' ; } ) ; } . bind ( this ) ; if ( typeof str !== 'string' ) { throw 'Invalid "str" type supplied in filterString. Expected string.' ; } for ( var p in this . patterns ) { if ( ! this . patterns [ p ] . enabled ) { continue ; } if ( this . patterns [ p ] . pattern instanceof RegExp ) { str = replace ( str , this . patterns [ p ] . pattern ) ; continue ; } if ( ! this . isArray ( this . patterns [ p ] . pattern ) ) { throw 'Invalid pattern type supplied. Expected Array.' ; } for ( var i = 0 ; i < this . patterns [ p ] . pattern . length ; i ++ ) { if ( ! this . patterns [ p ] . pattern [ i ] instanceof RegExp ) { throw 'Expected valid RegExp.' ; } str = replace ( str , this . patterns [ p ] . pattern [ i ] ) ; } } return str ; }
Filter the string.

@param   {String}    str
@param   {Boolean}   highlight
@returns {String}}
Filter the string .