"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidVersion = isValidVersion;
exports.compareVersions = compareVersions;
exports.parseVersion = parseVersion;
const versionExp = /^v?(\d+)\.(\d+)(\.(\d+))?$/;
function isValidVersion(version) {
    return Boolean(version.trim().match(versionExp));
}
function compareVersions(version1, version2) {
    const v1 = parseVersion(version1);
    const v2 = parseVersion(version2);
    for (let i = 0; i < 3; i++) {
        if (v1[i] !== v2[i]) {
            return Math.max(-1, Math.min(1, v1[i] - v2[i]));
        }
    }
    return 0;
}
function parseVersion(v) {
    let ver = [0, 0, 0];
    const match = v.trim().match(versionExp);
    if (match) {
        const [, major, minor, , patch = '0'] = match;
        ver = [parseInt(major), parseInt(minor), parseInt(patch)];
    }
    if (!isValidVersion(v)) {
        throw new Error(`'${v}' is not a valid version`);
    }
    return ver;
}
//# sourceMappingURL=versions.js.map