in src/components/Selection/MultiselectFilter.ts [23:52]
function mildlySmartSort<T>(values: T[], f: (value: T) => string | null) {
if (values.length == 0)
return;
const firstNonNull = Iterator.from(values).map(v => f(v)).find(v => v !== null);
if (!firstNonNull) {
// There must only be one entry, as there should be at most one null result.
return;
}
const sortWithNull = (stringSort: (a: string, b: string) => number) => (a: T, b: T): number => {
const ap = f(a);
const bp = f(b);
if (ap === null) {
return -1;
} else if (bp === null) {
return 1;
} else {
return stringSort(ap, bp);
}
};
if (/^[0-9][0-9.@ab]+$/.test(firstNonNull)) {
const toParts = (v: string) => v.split(/[.@ab]/).map(i => i ? parseInt(i) : 0);
// Sort descending, assuming we're interested in the larger values
values.sort(sortWithNull((a, b) => arrayCompare(toParts(a), toParts(b)))).reverse();
} else {
values.sort(sortWithNull((a, b) => a.localeCompare(b)));
}
}