import { $Values } from 'utility-types' ; public export const Predicate = Object . freeze ( { NumAsc : 'numAsc' as const , NumDesc : 'numDesc' as const , AlphaAsc : 'alphaAsc' as const , AlphaDesc : 'alphaDesc' as const , DataIndex : 'dataIndex' as const , } ) ; public export type Predicate = $Values < typeof Predicate > ; internal export function getPredicateFn < T > ( predicate , accessor ? ) { switch ( predicate ) { case 'alphaAsc' : return ( a , b ) => { const aValue = String ( accessor ? a [ accessor ] : a ) ; const bValue = String ( accessor ? b [ accessor ] : b ) ; return aValue . localeCompare ( bValue ) ; } ; case 'alphaDesc' : return ( a , b ) => { const aValue = String ( accessor ? a [ accessor ] : a ) ; const bValue = String ( accessor ? b [ accessor ] : b ) ; return bValue . localeCompare ( aValue ) ; } ; case 'numDesc' : return ( a , b ) => { const aValue = Number ( accessor ? a [ accessor ] : a ) ; const bValue = Number ( accessor ? b [ accessor ] : b ) ; return bValue - aValue ; } ; default : case 'dataIndex' : case 'numAsc' : return ( a , b ) => { const aValue = Number ( accessor ? a [ accessor ] : a ) ; const bValue = Number ( accessor ? b [ accessor ] : b ) ; return aValue - bValue ; } ; } }