MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / compareVersionsDesc

Function compareVersionsDesc

telemetry-dashboard/src/api.ts:197–212  ·  view source on GitHub ↗

Newest first, numerically per segment, so 1.10.0 sorts above 1.9.0.

(a: string, b: string)

Source from the content-addressed store, hash-verified

195
196/** Newest first, numerically per segment, so 1.10.0 sorts above 1.9.0. */
197function compareVersionsDesc(a: string, b: string): number {
198 const pa = a.split(/[.-]/);
199 const pb = b.split(/[.-]/);
200 for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
201 const na = Number(pa[i]);
202 const nb = Number(pb[i]);
203 if (Number.isFinite(na) && Number.isFinite(nb)) {
204 if (na !== nb) return nb - na;
205 } else {
206 const sa = pa[i] ?? '';
207 const sb = pb[i] ?? '';
208 if (sa !== sb) return sb.localeCompare(sa);
209 }
210 }
211 return 0;
212}
213
214// ---------------------------------------------------------------------------
215// /api/meta

Callers 1

breakdownFunction · 0.85

Calls 1

NumberInterface · 0.85

Tested by

no test coverage detected