version.js 786 Bytes
function toVersion(str = '') {
    const ver = str.split('.').map(i => Number(i));

    if (!ver[0]) {
        ver[0] = 0;
    }

    if (!ver[1]) {
        ver[1] = 0;
    }

    if (!ver[2]) {
        ver[2] = 0;
    }

    return ver;
}

function toNumber(ver) {
    const major = ver[0] * 10000;
    const minor = ver[1] * 100;
    const patch = ver[2] * 1;

    return major + minor + patch;
}

function compare(left, right) {
    if (left > right) {
        return 1;
    } else if (left < right) {
        return -1;
    } else {
        return 0;
    }
}

export default function (left, right) {
    const leftVersion = toNumber(toVersion(left));
    const rightVersion = toNumber(toVersion(right));
    const result = compare(leftVersion, rightVersion);

    return result;
};