mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-25 10:02:27 -04:00
* Test * Add pretty formatting * Fix Tests * Fix Tests * Fix Tests * Fix * Add pretty formatting fix * Fix * Test * Fix tests * Clean typeckech * Add prettier check * Fix api tsconfig * Fix api tsconfig * Fix tsconfig * Fix * Fix * Prettier
19 lines
571 B
TypeScript
19 lines
571 B
TypeScript
import {MAX_INT} from 'common/constants'
|
|
|
|
export function getSortedOptions(options: string[], order: string[] | Record<string, string>) {
|
|
let parsedOrder: string[]
|
|
if (Array.isArray(order)) {
|
|
parsedOrder = order
|
|
} else {
|
|
parsedOrder = Object.keys(order)
|
|
}
|
|
return options.slice().sort((a, b) => {
|
|
const ia = parsedOrder.indexOf(a as any)
|
|
const ib = parsedOrder.indexOf(b as any)
|
|
const sa = ia === -1 ? MAX_INT : ia
|
|
const sb = ib === -1 ? MAX_INT : ib
|
|
if (sa !== sb) return sa - sb
|
|
return String(a).localeCompare(String(b))
|
|
})
|
|
}
|