DevTools Logo

SemVer Range Intersection

SemVer Range Intersection

Find the versions shared by npm dependency ranges, using node-semver rules.

Runs in your browser
Try an example

Dependency ranges

2 ranges

Use ^, ~, comparators, x-ranges, hyphens, || for alternatives and spaces for AND.

Intersection

lowest 1.5.0
Pre-release versions (1.2.3-beta.1) are excluded unless a range names a pre-release of the same major.minor.patch. Turn on Include pre-releases to count them.
Overlapping versions found. Lowest match: 1.5.0

Combined range (AND of one branch from each range)

>=1.2.0 <2.0.0 >=1.5.0 <2.0.0

Ranges as node-semver reads them

  • ^1.2.0 → >=1.2.0 <2.0.0
  • >=1.5.0 <2.0.0 → >=1.5.0 <2.0.0
1.6.0 satisfies all ranges
  • ^1.2.0: matches
  • >=1.5.0 <2.0.0: matches

    Examples

    Overlapping caret and bounded range

    Input
    ["^1.2.0", ">=1.5.0 <2.0.0"]
    Output
    empty: false, lower: >= 1.5.0, upper: < 2.0.0

    The bounded range tightens the caret lower bound from 1.2.0 to 1.5.0 while the <2.0.0 ceiling survives.

    Disjoint majors are empty

    Input
    ["^1.0.0", "^2.0.0"]
    Output
    empty: true, reason: Ranges do not overlap

    No version satisfies both >=1.0.0 <2.0.0 and >=2.0.0 <3.0.0, so the tightest bounds invert and the result is empty.

    About this tool

    SemVer Range Intersection parses npm-style ranges with parseRange and tests versions with satisfies. parseVersion accepts an optional v/= prefix and partial core components, rejects wildcards and unsafe integers (so 1.2.03 is null), and validates prerelease identifiers including the no-leading-zero numeric rule. Supported range syntax includes comparators (<, <=, >, >=, =), caret (^ with 0-major pinning: ^0.2.3 admits 0.2.9 but not 0.3.0, and ^0.0.3 admits only 0.0.3), tilde (~ pinned below the next minor), x/* wildcards (1.2.x means >=1.2.0 <1.3.0), inclusive hyphen ranges (1.2.3 - 2.0.0 admits both endpoints), space-separated AND, and || OR branches parsed into separate RangeSets.

    Prerelease versions are isolated the npm way: satisfies returns false for a prerelease unless at least one comparator in the matched set carries a prerelease with the same major.minor.patch (so 1.2.3-beta.1 fails >=1.0.0 <2.0.0 but passes >=1.2.3-beta.0 <1.2.3, and 1.2.3-beta.1 passes its exact pin). Comparison follows semver precedence with numeric identifiers ordered numerically, numeric below alphanumeric, and a missing prerelease ranking above any prerelease. Invalid range text throws (Range is empty, Invalid range, Invalid range token), and satisfies treats unparseable input as false rather than throwing.

    intersectRanges requires at least two range strings, expands every || combination across inputs, and intersects each combination by keeping the tightest lower bound (>, >=, =) and upper bound (<, <=, =). Equal bounds with any exclusive side, inverted bounds, or prerelease-only contact produce empty: true with a reason such as Ranges do not overlap. A successful result reports empty: false with the winning lower/upper bounds — for example ^1.2.0 with >=1.5.0 <2.0.0 yields lower 1.5.0 — while solveIntersection accepts either an array or newline-separated text and funnels it into the same engine.

    How to use this tool

    1. Enter two or more ranges

      Provide one range per line or array entry using ^, ~, x-ranges, hyphen, comparators, spaces for AND, and || for OR. A single range throws: at least two are required.

    2. Read the intersection verdict

      A non-empty result names the tightest inclusive/exclusive lower and upper bounds; an empty result carries a reason such as Ranges do not overlap or an invalid-token message.

    3. Spot-check versions with satisfies

      Test candidate versions against each range, remembering that prereleases only match prerelease-aware comparators on the same triple.

    4. Resolve OR branches

      When a range contains ||, check which alternative overlaps: ^1.0 || ^3.0 intersected with ^3.2.0 succeeds through the ^3.0 branch while ^2.0.0 alone stays empty.

    Use cases

    Reconciling dependency constraints

    Check whether two peer or engine ranges admit any common version before merging branches or publishing.

    Auditing caret and tilde upgrades

    Confirm that ^0.0.3 pins to a single patch while ^1.2.0 floats, so lockfile churn matches expectations.

    Gating prerelease channels

    Verify that a beta tag is excluded from plain ranges and only admitted by a prerelease-pinned comparator.

    Common mistakes

    Mistake:Assuming ^0.0.3 behaves like ^1.2.3.

    Fix:Zero-major carets pin harder: ^0.0.3 means >=0.0.3 <0.0.4, so 0.0.4 already falls outside. Read the zero-major rule before widening the range.

    Mistake:Expecting a prerelease to satisfy a plain range.

    Fix:Prereleases are excluded unless a comparator names a prerelease on the same triple. Pin or widen the comparator (e.g. >=1.2.3-beta.0 <1.2.3) when prereleases must match.

    Mistake:Passing a single range or empty text to the intersector.

    Fix:Supply at least two non-empty ranges; one input throws and empty text fails parsing. Use satisfies for single-range membership tests.

    Frequently asked questions

    What does this tool do?

    It intersects two or more npm-style semver ranges (^, ~, x/*, hyphen, comparators, space AND, || OR) and reports either the tightest surviving lower/upper bounds or empty: true with a reason; it also tests individual versions with satisfies.

    Why doesn't my prerelease match, and how do zero-major carets behave?

    Prereleases are isolated: 1.2.3-beta.1 fails >=1.0.0 <2.0.0 but passes a prerelease-aware comparator on the same triple such as >=1.2.3-beta.0 <1.2.3. Zero-major carets pin harder than ^1.x — ^0.2.3 admits 0.2.9 but not 0.3.0, and ^0.0.3 admits only 0.0.3 — and hyphen bounds are inclusive on both ends.

    Is my range data uploaded or stored?

    No. Parsing, precedence comparison, and bound intersection are pure client-side computation — ranges and versions never leave your browser.

    How do I reconcile two dependency constraints?

    Enter one range per line: ^1.2.0 with >=1.5.0 <2.0.0 reports non-empty with lower 1.5.0, while ^1.0.0 with ^2.0.0 reports empty (Ranges do not overlap). For || ranges the engine tries every branch combination and keeps the first overlapping one.

    References & standards