Function cmp

Pass in a comparison string, and it'll call the corresponding semver comparison function.

Throws if an invalid comparison string is provided.

cmp('1.2.3', '>', '1.2.2') // true

build identifier ([+BUILD]) is not taken into account in all operations but "===" and "!==" which do simple comparison of the whole strings

  • Parameters

    • v1: string

      first version string

    • operator: Operator

      operator string (could be "===", "!==", "", "=", "==", "!=", ">", ">=", "<", "<=")

    • 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 boolean

    true if the comparison is true, false otherwise