From f87e6b855c831c96ab867ebecf6921a1873aaf81 Mon Sep 17 00:00:00 2001 From: Nathan Hunzaker Date: Tue, 12 Jun 2018 08:26:41 -0400 Subject: [PATCH] Add back support for boolean sortObjectKeys 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. --- src/getCollectionEntries.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/getCollectionEntries.js b/src/getCollectionEntries.js index 5ed8775..b34a5a6 100644 --- a/src/getCollectionEntries.js +++ b/src/getCollectionEntries.js @@ -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);