Class Version

A representation of a semver 2 compliant version string

Constructors

  • Construct a Version from specific components.

    If you wish to parse a string into a Version then please use [[fromSemver]].

    Parameters

    • major: number

      The major version component.

    • minor: number

      The minor version component.

    • patch: number

      The patch version component.

    • prIdent: null | string[]

      A list of pre-release identifiers, if any

    • buildIdent: null | string[]

      A list of build identifiers, if any

    Returns Version

Methods

  • Construct a version from a semver 2 compliant string.

    This function is intended for use with semver 2 compliant strings. Malformed strings may still parse correctly, but this result is not guaranteed.

    Parameters

    • versionString: string

      A semver 2.0.0 compliant version string

    Returns Version

    A version object

  • Returns true if a given version is compatible with this one.

    Compatibility is defined as having the same nonzero major version number, or if both major versions are zero, the same nonzero minor version number, or if both minor versions are zero, the same nonzero patch version number.

    This implements the ^ operator in npm's semver package, with the exception of the prerelease exclusion rule.

    Parameters

    • other: Version

      The other version to test against

    Returns boolean

    True if compatible

  • Returns true if this version has precedence over (is newer than) another version.

    Precedence is defined as in the Semver 2 spec. This implements the > operator in npm's semver package, with the exception of the prerelease exclusion rule.

    Parameters

    • other: Version

      The other version to test against

    Returns boolean

    True if this version has precedence over the other one

  • Tests if a given version is equivalent to this one.

    Build and prerelease tags are ignored.

    Parameters

    • other: Version

      The other version to test against

    Returns boolean

    True if the given version is equivalent

  • Tests if a given version is stable or a compatible prerelease for this version.

    This implements the prerelease exclusion rule of NPM semver: a prerelease version can only pass this check if the major/minor/patch components of both versions are the same. Otherwise, the prerelease version always fails.

    Parameters

    • other: Version

      The other version to test against

    Returns boolean

    True if the given version is either stable, or a prerelease in the same series as this one.