Skip to content

Commit 0d94d6c

Browse files
committed
fix logic in rearrange helper when using negated entry
1 parent eb3930a commit 0d94d6c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/helpers/rearrange.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
'use strict'
22

33
module.exports = (collection, property, orderSpec) => {
4-
if (!orderSpec || orderSpec === '*') return Object.values(collection)
5-
const order = orderSpec.split(',').map((it) => it.trim())
4+
if (orderSpec == null || orderSpec === '*') return Object.values(collection)
65
const sourceCollection = Object.values(collection).reduce((accum, it) => accum.set(it[property], it), new Map())
6+
const order = orderSpec.split(',').map((it) => it.trim()).filter((it) => {
7+
if (it.charAt() !== '!') return true
8+
sourceCollection.delete(it.substr(1))
9+
})
710
const restIdx = order.indexOf('*')
811
if (~restIdx) order.splice(restIdx, 1)
912
const targetCollection = order.reduce((accum, key) => {
10-
if (key.startsWith('!')) {
11-
sourceCollection.delete(key.substr(1))
12-
} else if (sourceCollection.has(key)) {
13+
if (sourceCollection.has(key)) {
1314
accum.push(sourceCollection.get(key))
1415
sourceCollection.delete(key)
1516
}

0 commit comments

Comments
 (0)