(s: string)
| 95 | /// which ensures that sorting works correctly. |
| 96 | /// E.g. "43.alpha" will be parsed to [43,-3] |
| 97 | export function parseVersion(s: string): number[] { |
| 98 | const components = s.split('.').map((x) => { |
| 99 | if (x === 'alpha') return -3; |
| 100 | if (x === 'beta') return -2; |
| 101 | if (x === 'rc') return -1; |
| 102 | return Number(x); |
| 103 | }); |
| 104 | if (!components.every((x) => isFinite(x))) { |
| 105 | throw new Error(`Could not parse version number: ${s}`); |
| 106 | } |
| 107 | return components; |
| 108 | } |
| 109 | |
| 110 | /// Compares to versions, returns -1 if lhs < rhs, 1 if lhs > rhs and 0 if lhs == rhs |
| 111 | /// Lhs and rhs may be of different lengths, missing components will be assumed to be zero. |
no test coverage detected