305
306
export function compareAnything(one: string, other: string, lookFor: string): number {
308
>
const elementBName = other.toLowerCase();
309
>
310
>
// Sort prefix matches over non prefix matches
311
>
const prefixCompare = compareByPrefix(one, other, lookFor);
312
>
if (prefixCompare) {
313
return prefixCompare;
314
}
316
>
// Sort suffix matches over non suffix matches
317
>
const elementASuffixMatch = elementAName.endsWith(lookFor);
318
>
const elementBSuffixMatch = elementBName.endsWith(lookFor);
319
>
if (elementASuffixMatch !== elementBSuffixMatch) {
320
return elementASuffixMatch ? -1 : 1;
321
}
323
>
// Understand file names
324
>
const r = compareFileNames(elementAName, elementBName);
325
>
if (r !== 0) {
326
>
return r;
327
>
}
328
329
// Compare by name