Skip to content

Commit 2a613ca

Browse files
committed
update color-sorter to v3.0.0
1 parent efa06fa commit 2a613ca

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"homepage": "https://github.com/bartveneman/css-analyzer-diff#readme",
2727
"dependencies": {
28-
"color-sorter": "^2.2.1",
28+
"color-sorter": "^3.0.0",
2929
"css-unit-sort": "^1.1.1",
3030
"string-natural-compare": "^2.0.3"
3131
},

src/diff-lists.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@ const METRICS_SORTED_BY_COLOR = [
1212

1313
function getSortingFnByKey(key) {
1414
if (METRICS_SORTED_BY_CSS_UNIT.includes(key)) {
15-
return cssUnitSort.sortFn
15+
return (a, b) => cssUnitSort.sortFn(a, b) * -1
1616
}
1717

18-
return (a, b) => {
19-
return caseInsensitiveCompare(b, a)
18+
if (METRICS_SORTED_BY_COLOR.includes(key)) {
19+
return cssColorSort.sortFn
2020
}
21+
22+
return (a, b) => caseInsensitiveCompare(a, b)
2123
}
2224

2325
function mergeLists(listA, listB, key) {
2426
// Create a single list out of both lists that will take their
2527
// unique values
26-
const merged = listA
27-
.concat(listB)
28-
// Remove duplicate items
29-
.filter((value, index, self) => {
30-
return self.lastIndexOf(value) === index
31-
})
32-
// Re-sort the items
33-
.sort(getSortingFnByKey(key))
34-
.reverse()
35-
36-
// Until color-sorter supports a sortFn, we must sort the list at this place
37-
return METRICS_SORTED_BY_COLOR.includes(key) ? cssColorSort(merged) : merged
28+
return (
29+
listA
30+
.concat(listB)
31+
// Remove duplicate items
32+
.filter((value, index, self) => {
33+
return self.lastIndexOf(value) === index
34+
})
35+
// Re-sort the items
36+
.sort(getSortingFnByKey(key))
37+
)
3838
}
3939

4040
function diffLists(listA, listB, key) {

0 commit comments

Comments
 (0)