feat: add split by separator + order by numeric + no sort

Fix #764 #1279 #1090
Small screen UI Fix
This commit is contained in:
ShareVB 2024-09-21 16:18:05 +02:00
parent 327ff11a59
commit 7bafd4790e
7 changed files with 168 additions and 72 deletions

View file

@ -1,6 +1,29 @@
export { byOrder };
export type SortOrder = 'asc' | 'desc' | 'asc-num' | 'desc-num' | 'asc-bin' | 'desc-bin' | 'asc-upper' | 'desc-upper' | null | undefined;
export function byOrder({ order }: { order: SortOrder }) {
if (order === 'asc-bin' || order === 'desc-bin') {
return (a: string, b: string) => {
const compare = a > b ? 1 : (a < b ? -1 : 0); // NOSONAR
return order === 'asc-bin' ? compare : -compare;
};
}
if (order === 'asc-num' || order === 'desc-num') {
return (a: string, b: string) => {
const compare = a.localeCompare(b, undefined, {
numeric: true,
});
return order === 'asc-num' ? compare : -compare;
};
}
if (order === 'asc-upper' || order === 'desc-upper') {
return (a: string, b: string) => {
const compare = a.localeCompare(b, undefined, {
caseFirst: 'upper',
});
return order === 'asc-upper' ? compare : -compare;
};
}
function byOrder({ order }: { order: 'asc' | 'desc' | null | undefined }) {
return (a: string, b: string) => {
return order === 'asc' ? a.localeCompare(b) : b.localeCompare(a);
};