-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
executable file
·46 lines (40 loc) · 1.04 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
exports.diffUpdate = function (oldNodes, newNodes) {
// write new data
newNodes.forEach(newNode => {
var oldNode = oldNodes.find(oldNode => oldNode.url === newNode.url)
if (oldNode) {
oldNode.copyDataFrom(newNode)
} else {
oldNodes.push(newNode)
}
})
// remove old data
oldNodes = oldNodes.filter(oldNode => {
var newNode = newNodes.find(newNode => newNode.url === oldNode.url)
return !!newNode
})
return oldNodes
}
exports.sortCompare = function (nodeA, nodeB, column, dir) {
var res
switch (column) {
case 'updated':
res = nodeA.mtime < nodeB.mtime ? 1 : -1
break
case 'size':
if (nodeA.type !== 'folder' && nodeB.type !== 'folder') { // folders dont have sizes
res = nodeA.size < nodeB.size ? 1 : -1
}
break
case 'type':
res = nodeA.type.localeCompare(nodeB.type)
break
}
// fallback to alphabetical
if (!res) {
res = nodeA.name.localeCompare(nodeB.name)
}
// apply direction
if (dir === 'asc') res *= -1
return res
}