Files
renovate/lib/modules/versioning/pvp/util.ts
renovate[bot] c2aa761c1e chore(deps): update linters (main) (#41417)
* chore(deps): update linters

| datasource | package              | from   | to     |
| ---------- | -------------------- | ------ | ------ |
| npm        | @eslint/js           | 9.39.2 | 9.39.3 |
| npm        | eslint               | 9.39.2 | 9.39.3 |
| npm        | eslint-plugin-oxlint | 1.46.0 | 1.49.0 |
| npm        | oxlint               | 1.47.0 | 1.49.0 |
| npm        | typescript-eslint    | 8.55.0 | 8.56.0 |

* chore(deps): update linters

| datasource | package              | from   | to     |
| ---------- | -------------------- | ------ | ------ |
| npm        | @eslint/js           | 9.39.2 | 9.39.3 |
| npm        | eslint               | 9.39.2 | 9.39.3 |
| npm        | eslint-plugin-oxlint | 1.46.0 | 1.49.0 |
| npm        | oxlint               | 1.47.0 | 1.49.0 |
| npm        | typescript-eslint    | 8.55.0 | 8.56.0 |

* Radix rule has been deprecated

* fixup! Radix rule has been deprecated

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: secustor <sebastian@poxhofer.at>
2026-02-28 11:23:25 +00:00

55 lines
1.2 KiB
TypeScript

import type { Parts } from './types.ts';
export function extractAllParts(version: string): number[] | null {
const parts = version.split('.').map((x) => parseInt(x, 10));
const ret: number[] = [];
for (const l of parts) {
if (l < 0 || !isFinite(l)) {
return null;
}
ret.push(l);
}
return ret;
}
export function getParts(splitOne: string): Parts | null {
const c = extractAllParts(splitOne);
if (c === null) {
return null;
}
return {
major: c.slice(0, 2),
minor: c.slice(2, 3),
patch: c.slice(3),
};
}
export function plusOne(majorOne: number[]): string {
return `${majorOne[0]}.${majorOne[1] + 1}`;
}
export function compareIntArray(
versionPartsInt: number[],
otherPartsInt: number[],
): 'lt' | 'eq' | 'gt' {
for (
let i = 0;
i < Math.min(versionPartsInt.length, otherPartsInt.length);
i++
) {
if (versionPartsInt[i] > otherPartsInt[i]) {
return 'gt';
}
if (versionPartsInt[i] < otherPartsInt[i]) {
return 'lt';
}
}
if (versionPartsInt.length === otherPartsInt.length) {
return 'eq';
}
if (versionPartsInt.length > otherPartsInt.length) {
return 'gt';
}
return 'lt';
}