Function compare

Compares two versions excluding build identifiers (the bit after + in the semantic version string).

compare('1.2.3', '1.2.2') // 1

versionArray.sort(compare) can sort in ascending order for MAJOR.MINOR.PATCH[-PRERELEASE], excluding build identifier ([+BUILD]). This is different from sort(), which also sorts in ascending order but for the whole MAJOR.MINOR.PATCH[-PRERELEASE][+BUILD]

  • Parameters

    • v1: string

      first version string

    • v2: string

      second version string

    • OptionaloptionsOrLoose: boolean | Options

      an options object { loose } (where loose is the only available option) or a boolean indicating whether to enable loose mode. In loose mode, the parser is more forgiving with imperfectly formatted semver strings

    Returns -1 | 0 | 1

    • 0 if v1 == v2
    • 1 if v1 > v2
    • -1 if v1 < v2