Skip to content

Commit 600fcc1

Browse files
committed
[Refactor] order: use object.groupby
1 parent be928ae commit 600fcc1

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
"is-glob": "^4.0.3",
115115
"minimatch": "^3.1.2",
116116
"object.fromentries": "^2.0.6",
117+
"object.groupby": "^1.0.0",
117118
"object.values": "^1.1.6",
118119
"resolve": "^1.22.3",
119120
"semver": "^6.3.1",

src/rules/order.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import minimatch from 'minimatch';
44
import includes from 'array-includes';
5+
import groupBy from 'object.groupby';
56

67
import importType from '../core/importType';
78
import isStaticRequire from '../core/staticRequire';
@@ -325,13 +326,7 @@ function getSorter(alphabetizeOptions) {
325326
}
326327

327328
function mutateRanksToAlphabetize(imported, alphabetizeOptions) {
328-
const groupedByRanks = imported.reduce(function (acc, importedItem) {
329-
if (!Array.isArray(acc[importedItem.rank])) {
330-
acc[importedItem.rank] = [];
331-
}
332-
acc[importedItem.rank].push(importedItem);
333-
return acc;
334-
}, {});
329+
const groupedByRanks = groupBy(imported, (item) => item.rank);
335330

336331
const sorterFn = getSorter(alphabetizeOptions);
337332

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy