export function sortObject < T extends Record < string , any > = Record < string , any > > ( obj , compareFn ? ) { return Object . keys ( obj ) . sort ( compareFn ) . reduce ( ( acc , key ) => ( { ... acc , [ key ] : obj [ key ] } ) , { } ) as T ; } export function sortObjWithOrder < T extends Record < string , any > = Record < string , any > > ( obj , order ) { const sorted = sortWithOrder ( Object . keys ( obj ) , order ) ; return sorted . reduce ( ( acc , key ) => ( { ... acc , [ key ] : obj [ key ] } ) , { } ) as T ; } export function sortWithOrder ( obj , order ) { const groupOrder = [ ... new Set ( order . concat ( obj ) ) ] ; const sorted = [ ] ; while ( groupOrder . length ) { const key = groupOrder . shift ( ) ! ; const index = obj . indexOf ( key ) ; if ( index > - 1 ) { const [ item ] = obj . splice ( index , 1 ) ; sorted . push ( item ) ; } } return sorted ; } export const reverseSortString = ( a , b ) => { if ( a < b ) return 1 ; if ( a > b ) return - 1 ; return 0 ; } ;