JSSM, a JavaScript state machine - the FSM for FSL
    Preparing search index...

    Function compareVersions

    • Compares two semantic version strings, including prerelease versions.

      The numeric (major.minor.patch) parts compare numerically, with missing segments treated as zero. Prerelease parts (everything after the first -) follow semver precedence: a version with a prerelease precedes the same version without one; prerelease identifiers compare dot-by-dot, numeric identifiers numerically and below alphanumeric ones, alphanumeric identifiers in ASCII order, and a shorter identifier set precedes a longer one that it prefixes.

      Parameters

      • v1: string

        First version string (e.g., "5.104.2" or "6.0.0-alpha.1")

      • v2: string

        Second version string (e.g., "5.103.1")

      Returns number

      • Negative if v1 < v2, 0 if equal, positive if v1 > v2
      import { compareVersions } from 'jssm';
      compareVersions("5.104.2", "5.103.1"); // => 1
      import { compareVersions } from 'jssm';
      compareVersions("5.104.2", "6.0.0"); // => -1
      import { compareVersions } from 'jssm';
      compareVersions("5.104.2", "5.104.2"); // => 0
      import { compareVersions } from 'jssm';
      compareVersions("6.0.0-alpha.1", "6.0.0"); // => -1
      import { compareVersions } from 'jssm';
      compareVersions("6.0.0-alpha.1", "6.0.0-alpha.2"); // => -1
      import { compareVersions } from 'jssm';
      compareVersions("6.0.0-beta.1", "6.0.0-alpha.1"); // => 1