'use strict';
app.filter('encodeURIComponent', function() {
    return window.encodeURIComponent;
});
'use strict';

app.filter('excludeMaxedRoom',[function(){
  return function(array,expression,comparator){
    return array.filter(function(room){
      return room.devices.length !== 255;
    });
  };
}]);

'use strict';

app.filter('macAddress', function () {
  return function (str) {
    return str.slice(0,10).replace(/(.{2})/g,'$1:') + str.slice(10, 12);
  };
});
'use strict';

app.filter('remoteId', function () {
  return function (str) {
    return str.slice(6,12);
  };
});
'use strict';

app.filter('characters', function () {
  return function (input, chars, breakOnWord) {
    if (isNaN(chars)) { return input; }
    if (chars <= 0) { return ''; }
    if (input && input.length > chars) {
        input = input.substring(0, chars);

        if (!breakOnWord) {
            var lastspace = input.lastIndexOf(' ');
            //get last space
            if (lastspace !== -1) {
                input = input.substr(0, lastspace);
            }
        } else{
            while(input.charAt(input.length-1) === ' '){
                input = input.substr(0, input.length -1);
            }
        }
        return input + '...';
    }
    return input;
  };
});

app.filter('words', function () {
  return function (input, words) {
    if (isNaN(words)) { return input; }
    if (words <= 0) { return ''; }
    if (input) {
        var inputWords = input.split(/\s+/);
        if (inputWords.length > words) {
            input = inputWords.slice(0, words).join(' ') + '...';
        }
    }
    return input;
  };
});