'use strict';

angular.module('fileManager.filters', [])
  .filter('search', function() {
    return function(input, wildcard) {
      function regex_quote(string) {
        return string.replace(/[.\\+*?\[\^\]$(){}=!<>|:-]/g, '\\$&');
      }
      var pattern = new RegExp(regex_quote(wildcard).replace(/\\\*/g, '.*').replace(/\\\?/g, '.'), 'g');

      return input.filter(function(item) {
        return item.name.match(pattern);
      });
    };
  });