Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Commit

Permalink
Add back support for boolean sortObjectKeys (#108)
Browse files Browse the repository at this point in the history
Documentation suggests that passing a boolean to the sortObjectKeys
prop should provide a default sorting method. This commit adds a type
check to support both boolean and comparator functions.
  • Loading branch information
nhunzaker authored and zalmoxisus committed Dec 21, 2018
1 parent 778907f commit 8025cb4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/getCollectionEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ function getEntries(type, collection, sortObjectKeys, from = 0, to = Infinity) {
if (type === 'Object') {
let keys = Object.getOwnPropertyNames(collection);

if (typeof sortObjectKeys !== 'undefined') {
keys.sort(sortObjectKeys);
switch (typeof sortObjectKeys) {
case 'boolean':
keys.sort();
break;
case 'function':
keys.sort(sortObjectKeys);
break;
default:
// Do nothing
}

keys = keys.slice(from, to + 1);
Expand Down

0 comments on commit 8025cb4

Please sign in to comment.