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

Function compareVersionsDesc

telemetry-dashboard/src/api.ts:187–202  ·  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

185
186/** Newest first, numerically per segment, so 1.10.0 sorts above 1.9.0. */
187function compareVersionsDesc(a: string, b: string): number {
188 const pa = a.split(/[.-]/);
189 const pb = b.split(/[.-]/);
190 for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
191 const na = Number(pa[i]);
192 const nb = Number(pb[i]);
193 if (Number.isFinite(na) && Number.isFinite(nb)) {
194 if (na !== nb) return nb - na;
195 } else {
196 const sa = pa[i] ?? '';
197 const sb = pb[i] ?? '';
198 if (sa !== sb) return sb.localeCompare(sa);
199 }
200 }
201 return 0;
202}
203
204// ---------------------------------------------------------------------------
205// /api/meta

Callers 1

breakdownFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected