File tree Expand file tree Collapse file tree 1 file changed +18
-21
lines changed
packages/tailwindcss/src/utils Expand file tree Collapse file tree 1 file changed +18
-21
lines changed Original file line number Diff line number Diff line change @@ -16,27 +16,24 @@ export function compare(a: string, z: string) {
16
16
17
17
// If both are numbers, compare them as numbers instead of strings.
18
18
if ( aCode >= ZERO && aCode <= NINE && zCode >= ZERO && zCode <= NINE ) {
19
- let aValue = 0
20
- let zValue = 0
21
- let aEnd = i
22
- let zEnd = i
23
-
24
- do {
25
- aValue *= 10
26
- aValue += a . charCodeAt ( aEnd ) - ZERO
27
- aCode = a . charCodeAt ( ++ aEnd )
28
- } while ( aCode >= ZERO && aCode <= NINE )
29
-
30
- do {
31
- zValue *= 10
32
- zValue += z . charCodeAt ( zEnd ) - ZERO
33
- zCode = z . charCodeAt ( ++ zEnd )
34
- } while ( zCode >= ZERO && zCode <= NINE )
35
-
36
- if ( aValue - zValue ) return aValue - zValue
37
-
38
- let aNumber = a . slice ( i , aEnd )
39
- let zNumber = z . slice ( i , zEnd )
19
+ let aStart = i
20
+ let aEnd = i + 1
21
+ let zStart = i
22
+ let zEnd = i + 1
23
+
24
+ // Consume the number
25
+ aCode = a . charCodeAt ( aEnd )
26
+ while ( aCode >= ZERO && aCode <= NINE ) aCode = a . charCodeAt ( ++ aEnd )
27
+
28
+ // Consume the number
29
+ zCode = z . charCodeAt ( zEnd )
30
+ while ( zCode >= ZERO && zCode <= NINE ) zCode = z . charCodeAt ( ++ zEnd )
31
+
32
+ let aNumber = a . slice ( aStart , aEnd )
33
+ let zNumber = z . slice ( zStart , zEnd )
34
+
35
+ let diff = Number ( aNumber ) - Number ( zNumber )
36
+ if ( diff ) return diff
40
37
41
38
// Fallback case if numbers are the same but the string representation
42
39
// is not. Fallback to string sorting. E.g.: `0123` vs `123`
You can’t perform that action at this time.
0 commit comments