"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.firstVersionIsNewer = firstVersionIsNewer;
exports.compareVersions = compareVersions;
function firstVersionIsNewer(left, right) {
    if (!left || !right) {
        return false;
    }
    return compareVersions(left, right) > 0;
}
function compareVersions(left, right) {
    const leftParts = parseVersion(left);
    const rightParts = parseVersion(right);
    for (let index = 0; index < Math.max(leftParts.length, rightParts.length); index += 1) {
        const leftPart = leftParts[index] ?? 0;
        const rightPart = rightParts[index] ?? 0;
        if (leftPart !== rightPart) {
            return leftPart > rightPart ? 1 : -1;
        }
    }
    return 0;
}
function parseVersion(value) {
    return value
        .trim()
        .replace(/^[vV]/, '')
        .split('.')
        .map((part) => Number.parseInt(part.split('-')[0] ?? '0', 10))
        .filter((part) => Number.isFinite(part));
}
