Skip to content

satisfiesRange

Checks if a version satisfies a range, according to the given scheme (simple implementation — see each scheme’s own doc for exactly which operators are supported).

'semver' (default) — >=, >, <=, <, ^ (caret, patch+minor updates within the same major), ~ (tilde, patch updates within the same major.minor), or an exact match.

'gentoo' — >=, >, <=, <, or an exact match, compared per Gentoo/Portage ordering (see compare). ^/~ throw: Portage’s own atom syntax gives those characters different, unrelated meanings, so silently reusing SemVer’s semantics for them would be actively misleading rather than merely unsupported.

Available since v1.9.0

import { satisfiesRange } from '@helpers4/version';
// or, from the all-in-one package (same code, one install):
import { satisfiesRange } from 'helpers4/version';
satisfiesRange(version: string, range: string, scheme: VersionScheme): boolean
ParameterTypeDescription
versionstringVersion to check
rangestringRange pattern (e.g., ”>=1.0.0”, “~1.2.0”, “^1.0.0”)
schemeVersionSchemeWhich version scheme to interpret `version`/`range` as. Defaults to `‘semver’`.

boolean — True if version satisfies the range

Caret (^) allows patch and minor updates within the same major.

satisfiesRange('1.2.3', '^1.0.0')
// => true

The >= operator checks if the version is at least the specified value.

satisfiesRange('2.0.0', '>=1.5.0')
// => true

Returns false when the version does not satisfy the range.

satisfiesRange('0.9.0', '>=1.0.0')
// => false

Supports >=, >, <=, <, and exact match — ^ and ~ throw, since Portage gives those characters different, unrelated meanings.

satisfiesRange('1.2.3', '>=1.2.0', 'gentoo')
// => true

Identifies which version scheme parse/compare should use to interpret a version string. Defaults to 'semver' everywhere it’s accepted.

type VersionScheme = 'semver' | 'gentoo'

View source on GitHub