OR (||) Union Ranges — Combining Multiple Ranges

Combine multiple semver ranges with the || operator. A version satisfies the range if it matches any of the alternatives.

Union Ranges

Detailed Explanation

OR (Union) Ranges with ||

The || operator lets you combine multiple ranges into a single expression. A version satisfies the combined range if it matches any of the individual ranges.

Syntax

range1 || range2 || range3

Examples

OR Range Meaning
^1.0.0 || ^2.0.0 Any 1.x or any 2.x
>=1.0.0 <1.5.0 || >=2.0.0 1.0-1.4 or 2.0+
~1.2.0 || ~1.4.0 || ~2.0.0 Specific minor lines

Real-World Use Cases

1. Supporting Multiple Major Versions

Library authors often support multiple major versions of a peer dependency:

{
  "peerDependencies": {
    "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
  }
}

This means "works with React 16.8+, 17.x, or 18.x."

2. Skipping a Broken Version Range

If versions 1.3.0 through 1.3.5 had a critical bug:

>=1.2.0 <1.3.0 || >=1.3.6 <2.0.0

3. Engine Compatibility

{
  "engines": {
    "node": "^18.0.0 || ^20.0.0 || ^22.0.0"
  }
}

Supporting only LTS Node.js versions.

Order Does Not Matter

^1.0.0 || ^2.0.0 and ^2.0.0 || ^1.0.0 are equivalent. The OR operator is commutative — a version is tested against each alternative until one matches.

Combining with AND

Within each OR branch, space-separated comparators act as AND:

>=1.0.0 <1.5.0 || >=2.0.0 <3.0.0

This reads as: "(>=1.0.0 AND <1.5.0) OR (>=2.0.0 AND <3.0.0)."

Use Case

Library authors specifying peer dependencies that span multiple major versions, or excluding known-broken version ranges from a dependency specification.

Try It — Semver Calculator

Open full tool