MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / compareVersions

Function compareVersions

src/utils/updateCheck.ts:46–59  ·  view source on GitHub ↗
(a: string, b: string)

Source from the content-addressed store, hash-verified

44 * to lexicographic compare so "0.1.4-beta" sorts before "0.1.4".
45 */
46export function compareVersions(a: string, b: string): -1 | 0 | 1 {
47 const [aMain, aPre] = splitVersion(a);
48 const [bMain, bPre] = splitVersion(b);
49 for (let i = 0; i < 3; i++) {
50 const ai = aMain[i] ?? 0;
51 const bi = bMain[i] ?? 0;
52 if (ai !== bi) return ai < bi ? -1 : 1;
53 }
54 // A version with no pre-release is greater than one with one.
55 if (aPre === bPre) return 0;
56 if (aPre === "") return 1;
57 if (bPre === "") return -1;
58 return aPre < bPre ? -1 : 1;
59}
60
61function splitVersion(v: string): [number[], string] {
62 const [main, pre = ""] = v.split("-", 2);

Callers 2

runUpdateFunction · 0.85
makeResultFunction · 0.85

Calls 1

splitVersionFunction · 0.85

Tested by

no test coverage detected