Skip to main content

semverUtils

Index

Type Aliases

Comparator

Comparator: { gt: [> | >=, semver.SemVer] | null; lt: [< | <=, semver.SemVer] | null }

Type declaration

  • gt: [> | >=, semver.SemVer] | null
  • lt: [< | <=, semver.SemVer] | null

Functions

clean

  • clean(potentialVersion: string): string | null
  • Cleans the potential version by removing leading/trailing whitespace and ‘=v’ prefix


    Parameters

    • potentialVersion: string

    Returns string | null

    A valid SemVer string, otherwise null

getComparator

  • getComparator(comparators: Comparator): Comparator
  • Parameters

    • comparators: Comparator

    Returns Comparator

mergeComparators

  • mergeComparators(comparators: Comparator[]): null | { gt: null | [> | >=, SemVer]; lt: null | [< | <=, SemVer] }
  • Parameters

    Returns null | { gt: null | [> | >=, SemVer]; lt: null | [< | <=, SemVer] }

satisfiesWithPrereleases

  • satisfiesWithPrereleases(version: null | string, range: string, loose?: boolean): boolean
  • Returns whether the given semver version satisfies the given range. Notably this supports prerelease versions so that “2.0.0-rc.0” satisfies the range “&gt;=1.0.0”, for example.

    This function exists because the semver.satisfies method does not include pre releases. This means ranges such as * would not satisfy 1.0.0-rc. The includePrerelease flag has a weird behavior and cannot be used (if you want to try it out, just run the semverUtils testsuite using this flag instead of our own implementation, and you’ll see the failing cases).

    See https://github.com/yarnpkg/berry/issues/575 for more context.


    Parameters

    • version: null | string
    • range: string
    • loose: boolean = false

    Returns boolean

simplifyRanges

  • simplifyRanges(ranges: string[]): null | string
  • Parameters

    • ranges: string[]

    Returns null | string

stringifyComparator

  • stringifyComparator(comparator: Comparator): string

validRange

  • validRange(potentialRange: string): semver.Range | null
  • A cached version of new semver.Range(potentialRange) that returns null on invalid ranges


    Parameters

    • potentialRange: string

    Returns semver.Range | null