vlt / docs

  • PricingBenchmarks (opens in new window)Community (opens in new window)Feedback
  • Overview
  • Attribute Selectors
  • Combinators
  • ID Selectors
  • Security Insights
    • Overview
    • :attr()
    • :has()
    • :dist()
    • :host()
    • :is()
    • :not()
    • :outdated()
    • :published()
    • :semver()
    • :spec()
    • :path()
    • :type()
    • :diff()
    • :hostname()
    • :registry()
  • Syntax
  • Parameters
  • Comparison functions
  • Examples
  • Basic range matching
  • Exact version matching
  • Version comparison
  • Range-vs-range comparison
  • Custom property comparison
  • What gets selected
  • Combining with other selectors
  • See also
  1. Client
  2. /
  3. Selectors
  4. /
  5. Pseudo-classes
  6. /
  7. :semver()

:semver()

The :semver() pseudo-class matches packages based on semver comparisons. By default it compares against the package version field, but it can be configured to compare any semver-like value. It also supports range-vs-range functions (subset, intersects) that operate on edges by comparing dependency specifier ranges.

Syntax

Text
:semver(<range>)
:semver(<range>, <function>)
:semver(<range>, <function>, <custom-attribute-selector>)

Parameters

ParameterDescriptionDefault
rangeThe semver range to compare against(required)
functionComparison functionsatisfies
custom-attribute-selectorA different property to compareversion

Comparison functions

FunctionDescriptionOperates on
satisfiesVersion satisfies the range (default)nodes
eqVersion exactly equals the rangenodes
neqVersion does not equal the rangenodes
gtVersion is greater than the rangenodes
gteVersion is greater than or equal to the rangenodes
ltVersion is less than the rangenodes
lteVersion is less than or equal to the rangenodes
intersectsEdge's range intersects with the provided rangeedges
subsetEdge's range is a subset of the provided rangeedges

Examples

Basic range matching

Find packages satisfying ^1.0.0:

Terminal
$ vlt query ':semver(^1.0.0)'

Exact version matching

Find packages at exactly version 2.0.0:

Terminal
$ vlt query ':semver(2.0.0, eq)'

Version comparison

Find packages greater than version 5:

Terminal
$ vlt query ':semver(5.0.0, gt)'

Range-vs-range comparison

The intersects and subset functions compare two ranges rather than a version against a range. By default they operate on edges using the dependency specifier (bareSpec), making it possible to query which declared dependency ranges relate to a given range.

Find edges whose declared range is a subset of >=2:

Terminal
$ vlt query ':semver(>=2, subset)'

Find edges whose declared range intersects ^3:

Terminal
$ vlt query ':semver(^3, intersects)'

When a custom attribute is provided, intersects and subset compare against that manifest property value as a range:

Terminal
$ vlt query ':semver(>=20, subset, :attr(engines, [node]))'

Custom property comparison

Match packages whose engines.node field satisfies ^22:

Terminal
$ vlt query ':semver(^22, satisfies, :attr(engines, [node]))'

What gets selected

Given:

Text
my-app
├── react@18.2.0
├── react-dom@18.2.0
├── typescript@5.3.0
└── lodash@4.17.21
QuerySelected
:semver(^18.0.0)react, react-dom
:semver(5.0.0, gte)typescript
:semver(^4.0.0)lodash

Combining with other selectors

Find direct dependencies with version >= 18:

Terminal
$ vlt query ':root > :semver(18.0.0, gte)'

See also

  • :outdated() — find packages with newer versions available
  • Attribute Selectors — match the version field directly

Previous:published()Next:spec()

On this page

  • Syntax
  • Parameters
  • Comparison functions
  • Examples
  • Basic range matching
  • Exact version matching
  • Version comparison
  • Range-vs-range comparison
  • Custom property comparison
  • What gets selected
  • Combining with other selectors
  • See also
Edit this page

Deploy your package on vlt.io

Publish scoped and private packages, manage organizations and access, and give every developer and CI environment a consistent source for public and private JavaScript dependencies.

Publish now