@@ -53,17 +53,18 @@ function extractColorsFromDeclaration(declaration) {
5353const addCount = color => {
5454 return {
5555 ...color ,
56- count : color . aliases . reduce ( ( acc , curr ) => {
57- return acc + curr . count
56+ count : color . notations . reduce ( ( total , { count } ) => {
57+ return total + count
5858 } , 0 )
5959 }
6060}
6161
62- const addShortestNotation = color => {
62+ const addMostCommonNotation = color => {
6363 return {
6464 ...color ,
65- value : [ ...color . aliases ]
65+ value : [ ...color . notations ]
6666 . sort ( ( a , b ) => {
67+ // If counts are the same, get the shortest notation
6768 if ( a . count === b . count ) {
6869 return a . value . length - b . value . length
6970 }
@@ -74,23 +75,23 @@ const addShortestNotation = color => {
7475 }
7576}
7677
77- const addAliases = ( acc , curr ) => {
78+ const addNotations = ( acc , curr ) => {
7879 if ( ! acc [ curr . normalized ] ) {
7980 acc [ curr . normalized ] = {
80- aliases : [ ]
81+ notations : [ ]
8182 }
8283 }
8384
8485 acc [ curr . normalized ] = {
85- aliases : [ ...acc [ curr . normalized ] . aliases , curr ]
86+ notations : [ ...acc [ curr . normalized ] . notations , curr ]
8687 }
8788
8889 return acc
8990}
9091
9192const filterDuplicateColors = color => {
9293 // Filter out the actual duplicate colors
93- return color . aliases . length > 1
94+ return color . notations . length > 1
9495}
9596
9697const validateColor = color => {
@@ -101,7 +102,7 @@ const normalizeColors = color => {
101102 // Add a normalized value
102103
103104 // Avoid using TinyColor's toHslString() because it rounds
104- // the numbers and incorrectly reports aliases
105+ // the numbers and incorrectly reports duplicates
105106 const { h, s, l, a} = tinycolor ( color . value ) . toHsl ( )
106107 const normalized = a === 0 ? 0 : `h${ h } s${ s } l${ l } a${ a } `
107108
@@ -115,23 +116,23 @@ const rmTmpProps = color => {
115116 // Remove temporary props that were needed for analysis
116117 return {
117118 ...color ,
118- aliases : color . aliases . map ( alias => {
119- const { normalized, ...restAlias } = alias
120- return restAlias
119+ notations : color . notations . map ( notation => {
120+ const { normalized, ...colorProps } = notation
121+ return colorProps
121122 } )
122123 }
123124}
124125
125- const withAliases = colors =>
126+ const withDuplicateNotations = colors =>
126127 Object . values (
127128 colors
128129 . filter ( validateColor )
129130 . map ( normalizeColors )
130- . reduce ( addAliases , { } )
131+ . reduce ( addNotations , { } )
131132 )
132133 . filter ( filterDuplicateColors )
133134 . map ( addCount )
134- . map ( addShortestNotation ) // @TODO : use most often appearing color here
135+ . map ( addMostCommonNotation )
135136 . map ( rmTmpProps )
136137
137138module . exports = declarations => {
@@ -148,6 +149,6 @@ module.exports = declarations => {
148149 total : all . length ,
149150 unique,
150151 totalUnique,
151- duplicates : withAliases ( unique )
152+ duplicates : withDuplicateNotations ( unique )
152153 }
153154}
0 commit comments