* 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)
| 1033 | * field is convention, not contract; this is enough to drive a badge. |
| 1034 | */ |
| 1035 | function 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 | } |