How to use natural-compare - 3 common examples

To help you get started, we’ve selected a few natural-compare examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github u-wave / web / src / selectors / userSelectors.js View on Github external
// 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());
  };
}
github u-wave / web / src / components / UserList / RoomUserList.js View on Github external
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());
}
github u-wave / web / src / selectors / playlistSelectors.js View on Github external
const byName = (a, b) => naturalCmp(a.name.toLowerCase(), b.name.toLowerCase());

natural-compare

Compare strings containing a mix of letters and numbers in the way a human being would in sort order.

MIT
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis

Popular natural-compare functions