MCPcopy Create free account
hub / github.com/anus-dev/ANUS / sortFileEntries

Function sortFileEntries

packages/core/src/tools/glob.ts:33–56  ·  view source on GitHub ↗
(
  entries: GlobPath[],
  nowTimestamp: number,
  recencyThresholdMs: number,
)

Source from the content-addressed store, hash-verified

31 * Older files are listed after recent ones, sorted alphabetically by path.
32 */
33export function sortFileEntries(
34 entries: GlobPath[],
35 nowTimestamp: number,
36 recencyThresholdMs: number,
37): GlobPath[] {
38 const sortedEntries = [...entries];
39 sortedEntries.sort((a, b) => {
40 const mtimeA = a.mtimeMs ?? 0;
41 const mtimeB = b.mtimeMs ?? 0;
42 const aIsRecent = nowTimestamp - mtimeA < recencyThresholdMs;
43 const bIsRecent = nowTimestamp - mtimeB < recencyThresholdMs;
44
45 if (aIsRecent && bIsRecent) {
46 return mtimeB - mtimeA;
47 } else if (aIsRecent) {
48 return -1;
49 } else if (bIsRecent) {
50 return 1;
51 } else {
52 return a.fullpath().localeCompare(b.fullpath());
53 }
54 });
55 return sortedEntries;
56}
57
58/**
59 * Parameters for the GlobTool

Callers 2

glob.test.tsFile · 0.85
executeMethod · 0.85

Calls 1

fullpathMethod · 0.80

Tested by

no test coverage detected