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