compare.ts — tailwindcss Source File
Architecture documentation for compare.ts, a typescript file in the tailwindcss codebase. 0 imports, 3 dependents.
Entity Profile
Dependency Diagram
graph LR 52a5447b_9c77_0591_7ea4_271cf99d1fa6["compare.ts"] eea0ec96_6369_abc2_64b3_490868392e31["compile.ts"] eea0ec96_6369_abc2_64b3_490868392e31 --> 52a5447b_9c77_0591_7ea4_271cf99d1fa6 aed99406_85bd_0230_7820_e5b6fa3efe70["intellisense.ts"] aed99406_85bd_0230_7820_e5b6fa3efe70 --> 52a5447b_9c77_0591_7ea4_271cf99d1fa6 c59b98ca_59cc_38c6_702f_b2d24c906464["compare.test.ts"] c59b98ca_59cc_38c6_702f_b2d24c906464 --> 52a5447b_9c77_0591_7ea4_271cf99d1fa6 style 52a5447b_9c77_0591_7ea4_271cf99d1fa6 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
const ZERO = 48
const NINE = 57
/**
* Compare two strings alphanumerically, where numbers are compared as numbers
* instead of strings.
*/
export function compare(a: string, z: string) {
let aLen = a.length
let zLen = z.length
let minLen = aLen < zLen ? aLen : zLen
for (let i = 0; i < minLen; i++) {
let aCode = a.charCodeAt(i)
let zCode = z.charCodeAt(i)
// If both are numbers, compare them as numbers instead of strings.
if (aCode >= ZERO && aCode <= NINE && zCode >= ZERO && zCode <= NINE) {
let aStart = i
let aEnd = i + 1
let zStart = i
let zEnd = i + 1
// Consume the number
aCode = a.charCodeAt(aEnd)
while (aCode >= ZERO && aCode <= NINE) aCode = a.charCodeAt(++aEnd)
// Consume the number
zCode = z.charCodeAt(zEnd)
while (zCode >= ZERO && zCode <= NINE) zCode = z.charCodeAt(++zEnd)
let aNumber = a.slice(aStart, aEnd)
let zNumber = z.slice(zStart, zEnd)
let diff = Number(aNumber) - Number(zNumber)
if (diff) return diff
// Fallback case if numbers are the same but the string representation
// is not. Fallback to string sorting. E.g.: `0123` vs `123`
if (aNumber < zNumber) return -1
if (aNumber > zNumber) return 1
// Continue with the next character otherwise short strings will appear
// after long ones when containing numbers. E.g.:
// - bg-red-500/70
// - bg-red-500
continue
}
// Continue if the characters are the same
if (aCode === zCode) continue
// Otherwise, compare them as strings
return aCode - zCode
}
// If we got this far, the strings are equal up to the length of the shortest
// string. The shortest string should come first.
return a.length - z.length
}
Domain
Subdomains
Functions
Imported By
Source
Frequently Asked Questions
What does compare.ts do?
compare.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the Oxide domain, PreProcessors subdomain.
What functions are defined in compare.ts?
compare.ts defines 1 function(s): compare.
What files import compare.ts?
compare.ts is imported by 3 file(s): compare.test.ts, compile.ts, intellisense.ts.
Where is compare.ts in the architecture?
compare.ts is located at packages/tailwindcss/src/utils/compare.ts (domain: Oxide, subdomain: PreProcessors, directory: packages/tailwindcss/src/utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free