mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-28 16:19:48 +03:00
feat: add split by separator + order by numeric + no sort
Fix #764 #1279 #1090 Small screen UI Fix
This commit is contained in:
1 parent
327ff11a59
commit
7bafd4790e
7 files changed
+168
-72
No files matched your search
+25
-2
@@ -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);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user