Skip to content

Commit 230bd4e

Browse files
authored
show the most common available duplicate as duplicate value (#78)
Instead of showing the shortest notation possible of any duplicate color, show the one that's the most common as the duplicate value. It makes more sense to show `#fff` as a duplicate if it appears 100 times as opposed to showing `white` that only appears once.
1 parent 3b35f6c commit 230bd4e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/analyzer/values/colors.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ const addShortestNotation = color => {
6464
...color,
6565
value: [...color.aliases]
6666
.sort((a, b) => {
67-
return a.value.length - b.value.length
67+
if (a.count === b.count) {
68+
return a.value.length - b.value.length
69+
}
70+
71+
return b.count - a.count
6872
})
6973
.shift().value
7074
}

test/analyzer/values/output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@
365365
},
366366
{
367367
"count": 8,
368-
"value": "#000",
368+
"value": "black",
369369
"aliases": [
370370
{
371371
"value": "hsl(0,0,0)",

0 commit comments

Comments
 (0)