Newest first, numerically per segment, so 1.10.0 sorts above 1.9.0.
(a: string, b: string)
| 195 | |
| 196 | /** Newest first, numerically per segment, so 1.10.0 sorts above 1.9.0. */ |
| 197 | function 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 |