summaryrefslogtreecommitdiff
path: root/.config/coc/extensions/node_modules/coc-go/lib/utils/versions.js
blob: 1bcd82aff0e160afe26b9d4a183ae1a136cab355 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseVersion = exports.compareVersions = exports.isValidVersion = void 0;
const versionExp = /^v?(\d+)\.(\d+)(\.(\d+))?$/;
function isValidVersion(version) {
    return Boolean(version.trim().match(versionExp));
}
exports.isValidVersion = isValidVersion;
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;
}
exports.compareVersions = compareVersions;
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;
}
exports.parseVersion = parseVersion;
//# sourceMappingURL=versions.js.map