@@ -31,23 +31,25 @@ export class OrderByPipe implements PipeTransform {
31
31
32
32
if ( config . length === 1 ) {
33
33
switch ( sign ) {
34
- case '+' : return out . sort ( ) ;
35
- case '-' : return out . sort ( ) . reverse ( ) ;
34
+ case '+' : return out . sort ( OrderByPipe . simpleSort . bind ( this ) ) ;
35
+ case '-' : return out . sort ( OrderByPipe . simpleSort . bind ( this ) ) . reverse ( ) ;
36
36
}
37
37
}
38
38
39
39
return out . sort ( OrderByPipe . orderCompare . bind ( this , prop , asc ) ) ;
40
40
}
41
41
42
42
// default sort by value
43
- return out . sort ( ( a , b ) => {
44
- return isString ( a ) && isString ( b )
45
- ? a . toLowerCase ( ) . localeCompare ( b . toLowerCase ( ) )
46
- : a - b ;
47
- } ) ;
43
+ return out . sort ( OrderByPipe . simpleSort . bind ( this ) ) ;
48
44
}
49
45
50
- static orderCompare ( prop : string , asc : boolean , a : any , b : any ) {
46
+ private static simpleSort ( a : any , b : any ) {
47
+ return isString ( a ) && isString ( b )
48
+ ? a . toLowerCase ( ) . localeCompare ( b . toLowerCase ( ) )
49
+ : a - b ;
50
+ }
51
+
52
+ private static orderCompare ( prop : string , asc : boolean , a : any , b : any ) {
51
53
const first = extractDeepPropertyByMapKey ( a , prop ) ,
52
54
second = extractDeepPropertyByMapKey ( b , prop ) ;
53
55
@@ -65,7 +67,7 @@ export class OrderByPipe implements PipeTransform {
65
67
: second - first ;
66
68
}
67
69
68
- static extractFromConfig ( config : any ) {
70
+ private static extractFromConfig ( config : any ) {
69
71
const sign = config . substr ( 0 , 1 ) ;
70
72
const prop = config . replace ( / ^ [ - + ] / , '' ) ;
71
73
const asc = sign !== '-' ;
0 commit comments