Files
archived-orca/src/shared/file-name-sort.ts
T
Neil a7d9a10e4a feat(files): page a remote server's big folders in the explorer (#35115)
* feat(files): page a remote server's big folders in the explorer

* fix(files): list a remote folder whole unless the host refuses it as too large, then page it

* fix(files): page a remote folder after a cursor entry, not at an offset

* fix(files): release expired folder listings, share one in-flight listing, keep an oversized one alone

* fix(files): cap and time out cached folder listings, bound the cursor name, match id: selectors
2026-10-28 06:51:12 -07:00

30 lines
1.1 KiB
TypeScript

// Hoisting avoids per-comparison ICU construction (~14x cost); numeric collation costs ~5x bare localeCompare.
// Numeric order matches Finder/Explorer (99 before 100); pin en so local/remote processes agree regardless of LANG.
export const fileNameCollator = new Intl.Collator('en', { numeric: true })
export function compareFileNames(a: string, b: string): number {
const primary = fileNameCollator.compare(a, b)
if (primary !== 0) {
return primary
}
// Numeric ties (2 vs 02) need code-unit ordering to avoid readdir-dependent results.
return a < b ? -1 : a > b ? 1 : 0
}
/** Directories-first, then natural name order — the File Explorer listing contract. */
export function compareDirEntries(
a: { name: string; isDirectory: boolean },
b: { name: string; isDirectory: boolean }
): number {
if (a.isDirectory !== b.isDirectory) {
return a.isDirectory ? -1 : 1
}
return compareFileNames(a.name, b.name)
}
export function sortDirEntries<T extends { name: string; isDirectory: boolean }>(
entries: T[]
): T[] {
return entries.sort(compareDirEntries)
}