import { DateHelper } from "./DateHelper" ; export class Sorting { param property returns public static alphabetically = ( property ) => { return ( a , b ) => { if ( a [ property ] < b [ property ] ) { return - 1 ; } if ( a [ property ] > b [ property ] ) { return 1 ; } return 0 ; } ; } ; param property returns public static date = ( property ) => { return ( a , b ) => { const dateA = DateHelper . tryParse ( a [ property ] ) ; const dateB = DateHelper . tryParse ( b [ property ] ) ; return ( dateA || new Date ( 0 ) ) . getTime ( ) - ( dateB || new Date ( 0 ) ) . getTime ( ) ; } ; } ; param property returns public static dateWithFallback = ( property , fallback ) => { return ( a , b ) => { const dateA = DateHelper . tryParse ( a [ property ] ) ; const dateB = DateHelper . tryParse ( b [ property ] ) ; var dCount = ( dateA || new Date ( 0 ) ) . getTime ( ) - ( dateB || new Date ( 0 ) ) . getTime ( ) ; if ( dCount ) return dCount ; if ( a [ fallback ] < b [ fallback ] ) { return - 1 ; } if ( a [ fallback ] > b [ fallback ] ) { return 1 ; } return 0 ; } ; } ; param property returns public static number = ( property ) => { return ( a , b ) => { return a [ property ] - b [ property ] ; } ; } ; }