NpmRange
API reference › Foxy › Native › NpmRange
Represents an npm version range evaluated with npm semantics on top of Composer’s constraint engine.
Each || branch is rewritten into a Composer constraint (bare partials become wildcards, ~M.m keeps the minor,
partial > and <= bounds are bumped, hyphen ranges become >= and <= pairs) and a prerelease version matches
a branch only when a comparator of that branch carries a prerelease on the same major.minor.patch tuple.
Wildcard majors with an operator (>=*) and prerelease tags Composer cannot normalize (1.0.0-next.1) are rejected.
See also: https://github.com/npm/node-semver#ranges.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__toString() | Returns the original npm range, trimmed. | NpmRange |
parse() static | Parses an npm range. | NpmRange |
satisfies() | Returns whether a version satisfies the range. | NpmRange |
Method details
Section titled “Method details”__toString()
Section titled “__toString() ”public function __toString(): stringReturns the original npm range, trimmed.
Returns
string
parse()
Section titled “parse() ”public static function parse(string $range, string $package): selfParses an npm range.
Parameters
| Parameter | Type | Description |
|---|---|---|
$range | string | Npm range, such as ^1.2.3, 1.x |, or 1.2 - 2.3. |
$package | string | Package name used in the error message. |
Returns
self
Throws
Foxy\Exception\RuntimeException: if the range is not valid npm syntax or cannot be expressed as a Composer constraint.
satisfies()
Section titled “satisfies() ”public function satisfies(string $version): boolReturns whether a version satisfies the range.
Build metadata is ignored; a version Composer cannot normalize never satisfies the range.
Parameters
| Parameter | Type | Description |
|---|---|---|
$version | string | Version as published in the registry, such as 1.2.3 or 1.0.0-beta.1. |
Returns
bool