UNPKG

angular-filter

Version:

Bunch of useful filters for angularJS(with no external dependencies!)

27 lines (22 loc) 735 B
/** * @ngdoc filter * @name before-where * @kind function * * @description * get a collection and properties object, and returns all of the items * in the collection before the first that found with the given properties. */ angular.module('a8m.before-where', []) .filter('beforeWhere', function() { return function (collection, object) { collection = isObject(collection) ? toArray(collection) : collection; if(!isArray(collection) || isUndefined(object)) return collection; var index = collection.map( function( elm ) { return objectContains(object, elm); }).indexOf( true ); return collection.slice(0, (index === -1) ? collection.length : ++index); } });