Function compareVersion

  • Version number size comparison, tag version: rc > beta > alpha > other

    Parameters

    • input: string

      input version

    • compare: string

      compare version

    Returns -1 | 0 | 1

    1/0/-1

    compareVersion('1.11.0', '1.9.9')
    // => 1: 1=Version 1.11.0 is newer than 1.9.9

    compareVersion('1.11.0', '1.11.0')
    // => 0: 0=Versions 1.11.0 and 1.11.0 are the same

    compareVersion('1.11.0', '1.99.0')
    // => -1: -1=Version 1.11.0 is older than 1.99.0

    compareVersion('1.0.0.0.0.10', '1.0')
    // => -1

    // compare tag version: rc > beta > alpha > other
    compareVersion('1.11.0', '1.11.0-beta.1')
    // => -1

    compareVersion('1.11.0-beta.1', '1.11.0')
    // => -1

    compareVersion('1.11.0-beta.10', '1.11.0-beta.10')
    // => 0

    compareVersion('1.11.0-alpha.10', '1.11.0-beta.1')
    // => -1

    compareVersion('1.11.0-alpha.10', '1.11.0-rc.1')
    // => -1

    compareVersion('1.11.0-tag.10', '1.11.0-alpha.1')
    // => -1

    compareVersion('1.11.0-tag.10', '1.11.0-tag.1')
    // => 1

    compareVersion('1.11.0-release.10', '1.11.0-tag.1')
    // => 1

    4.7.0