MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / compareVersions

Function compareVersions

src/workspaces/service.ts:1035–1051  ·  view source on GitHub ↗

* Compare two dotted-version strings (e.g. "1.0.0" vs "1.2.3"). Returns * 1 if a > b, -1 if a < b, 0 if equal. Non-numeric segments fall back to * lexical comparison so a template author who writes `version: 1.0.0-rc1` * still gets sensible ordering. Deliberately not pulling in semver — the * fi

(a: string, b: string)

Source from the content-addressed store, hash-verified

1033 * field is convention, not contract; this is enough to drive a badge.
1034 */
1035function compareVersions(a: string, b: string): number {
1036 const pa = a.split('.');
1037 const pb = b.split('.');
1038 const len = Math.max(pa.length, pb.length);
1039 for (let i = 0; i < len; i++) {
1040 const sa = pa[i] ?? '0';
1041 const sb = pb[i] ?? '0';
1042 const na = Number(sa);
1043 const nb = Number(sb);
1044 if (Number.isFinite(na) && Number.isFinite(nb)) {
1045 if (na !== nb) return na > nb ? 1 : -1;
1046 } else {
1047 if (sa !== sb) return sa > sb ? 1 : -1;
1048 }
1049 }
1050 return 0;
1051}

Callers 1

publicMetaFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected