MCPcopy Index your code
hub / github.com/tailwindlabs/prettier-plugin-tailwindcss / sortClassList

Function sortClassList

src/sorting.ts:95–143  ·  view source on GitHub ↗
({
  classList,
  api,
  removeDuplicates,
}: {
  classList: string[]
  api: UnifiedApi
  removeDuplicates: boolean
})

Source from the content-addressed store, hash-verified

93}
94
95export function sortClassList({
96 classList,
97 api,
98 removeDuplicates,
99}: {
100 classList: string[]
101 api: UnifiedApi
102 removeDuplicates: boolean
103}) {
104 // Re-order classes based on the Tailwind CSS configuration
105 let orderedClasses = api.getClassOrder(classList)
106
107 orderedClasses.sort(([nameA, a], [nameZ, z]) => {
108 // Move `...` to the end of the list
109 if (nameA === '...' || nameA === '…') return 1
110 if (nameZ === '...' || nameZ === '…') return -1
111
112 if (a === z) return 0
113 if (a === null) return -1
114 if (z === null) return 1
115 return bigSign(a - z)
116 })
117
118 // Remove duplicate Tailwind classes
119 let removedIndices = new Set<number>()
120
121 if (removeDuplicates) {
122 let seenClasses = new Set<string>()
123
124 orderedClasses = orderedClasses.filter(([cls, order], index) => {
125 if (seenClasses.has(cls)) {
126 removedIndices.add(index)
127 return false
128 }
129
130 // Only consider known classes when removing duplicates
131 if (order !== null) {
132 seenClasses.add(cls)
133 }
134
135 return true
136 })
137 }
138
139 return {
140 classList: orderedClasses.map(([className]) => className),
141 removedIndices,
142 }
143}

Callers 3

transformPugFunction · 0.85
sortClassesFunction · 0.85
sortClassListsFunction · 0.85

Calls 2

bigSignFunction · 0.90
getClassOrderMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…