MCPcopy
hub / github.com/jquery/esprima / orderByFilter

Function orderByFilter

test/3rdparty/angular-1.2.5.js:14613–14662  ·  view source on GitHub ↗
($parse)

Source from the content-addressed store, hash-verified

14611 */
14612orderByFilter.$inject = ['$parse'];
14613function orderByFilter($parse){
14614 return function(array, sortPredicate, reverseOrder) {
14615 if (!isArray(array)) return array;
14616 if (!sortPredicate) return array;
14617 sortPredicate = isArray(sortPredicate) ? sortPredicate: [sortPredicate];
14618 sortPredicate = map(sortPredicate, function(predicate){
14619 var descending = false, get = predicate || identity;
14620 if (isString(predicate)) {
14621 if ((predicate.charAt(0) == '+' || predicate.charAt(0) == '-')) {
14622 descending = predicate.charAt(0) == '-';
14623 predicate = predicate.substring(1);
14624 }
14625 get = $parse(predicate);
14626 }
14627 return reverseComparator(function(a,b){
14628 return compare(get(a),get(b));
14629 }, descending);
14630 });
14631 var arrayCopy = [];
14632 for ( var i = 0; i < array.length; i++) { arrayCopy.push(array[i]); }
14633 return arrayCopy.sort(reverseComparator(comparator, reverseOrder));
14634
14635 function comparator(o1, o2){
14636 for ( var i = 0; i < sortPredicate.length; i++) {
14637 var comp = sortPredicate[i](o1, o2);
14638 if (comp !== 0) return comp;
14639 }
14640 return 0;
14641 }
14642 function reverseComparator(comp, descending) {
14643 return toBoolean(descending)
14644 ? function(a,b){return comp(b,a);}
14645 : comp;
14646 }
14647 function compare(v1, v2){
14648 var t1 = typeof v1;
14649 var t2 = typeof v2;
14650 if (t1 == t2) {
14651 if (t1 == "string") {
14652 v1 = v1.toLowerCase();
14653 v2 = v2.toLowerCase();
14654 }
14655 if (v1 === v2) return 0;
14656 return v1 < v2 ? -1 : 1;
14657 } else {
14658 return t1 < t2 ? -1 : 1;
14659 }
14660 }
14661 };
14662}
14663
14664function ngDirective(directive) {
14665 if (isFunction(directive)) {

Callers

nothing calls this directly

Calls 7

isArrayFunction · 0.85
isStringFunction · 0.85
reverseComparatorFunction · 0.85
pushMethod · 0.80
mapFunction · 0.70
compareFunction · 0.70
getFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…