Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Sort superusers to the top,
if (aRoles.includes(superuser)) {
return -1;
}
if (bRoles.includes(superuser)) {
return 1;
}
// other users by the amount of permissions they have,
if (aRoles.length > bRoles.length) {
return -1;
}
if (aRoles.length < bRoles.length) {
return 1;
}
// and sort by username if the roles are equal.
return naturalCmp(a.username.toLowerCase(), b.username.toLowerCase());
};
}
function compareUsers(a, b) {
if (a.role > b.role) {
return -1;
}
if (a.role < b.role) {
return 1;
}
return naturalCmp(a.username.toLowerCase(), b.username.toLowerCase());
}
const byName = (a, b) => naturalCmp(a.name.toLowerCase(), b.name.toLowerCase());