mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-09-17 21:52:21 +02:00
Squash Odysseus development history
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// Shared alphabetical sorting for model pickers and dropdowns.
|
||||
|
||||
function _sortText(value) {
|
||||
return String(value || '').split('/').pop().trim() || String(value || '');
|
||||
}
|
||||
|
||||
function _compareText(a, b) {
|
||||
return _sortText(a).localeCompare(_sortText(b), undefined, {
|
||||
numeric: true,
|
||||
sensitivity: 'base',
|
||||
}) || String(a || '').localeCompare(String(b || ''), undefined, {
|
||||
numeric: true,
|
||||
sensitivity: 'base',
|
||||
});
|
||||
}
|
||||
|
||||
function _arrayOrEmpty(models) {
|
||||
return Array.isArray(models) ? models : [];
|
||||
}
|
||||
|
||||
export function sortModelIds(models) {
|
||||
return _arrayOrEmpty(models).slice().sort(_compareText);
|
||||
}
|
||||
|
||||
export function compareModelObjects(a, b) {
|
||||
const aLabel = a && (a.display || a.displayName || a.name || a.mid || a.id || a.model);
|
||||
const bLabel = b && (b.display || b.displayName || b.name || b.mid || b.id || b.model);
|
||||
return _compareText(aLabel, bLabel);
|
||||
}
|
||||
|
||||
export function sortModelObjects(models) {
|
||||
return _arrayOrEmpty(models).slice().sort(compareModelObjects);
|
||||
}
|
||||
Reference in New Issue
Block a user