Skip to content

Attribute selectors match packages based on values found in their package.json metadata. They work similarly to CSS attribute selectors but operate on package metadata fields instead of HTML attributes.

Syntax

SelectorDescription
[attr]Has the property attr
[attr=value]Property attr exactly equals value
[attr^=value]Property attr starts with value
[attr$=value]Property attr ends with value
[attr~=value]Property attr is a whitespace-separated list containing value
[attr|=value]Property attr equals value or starts with value-
[attr*=value]Property attr contains value
[attr=value i]Case-insensitive comparison
[attr=value s]Case-sensitive comparison (default)

Examples

Match by name

Select a package with an exact name:

Terminal
$ vlt query '[name=react]'

Select all scoped packages:

Terminal
$ vlt query '[name^="@"]'

Select packages in the @vltpkg scope:

Terminal
$ vlt query '[name^="@vltpkg"]'

Match by version

Select packages on a specific version:

Terminal
$ vlt query '[version=1.0.0]'

Select packages with major version 2:

Terminal
$ vlt query '[version^=2]'

Match by any property

Select packages that have a repository field:

Terminal
$ vlt query '[repository]'

Select packages with a specific license:

Terminal
$ vlt query '[license=MIT]'

Select packages whose description mentions “parser”:

Terminal
$ vlt query '[description*=parser]'

Case-insensitive matching

Find packages with “React” in the description regardless of case:

Terminal
$ vlt query '[description*=react i]'

What gets selected

Given a project with these dependencies:

my-app
├── @vltpkg/cli@1.0.0
├── react@18.2.0
├── react-dom@18.2.0
└── typescript@5.3.0

The query [name^=react] selects:

my-app
├── @vltpkg/cli@1.0.0
├── react@18.2.0 ✅ name starts with "react"
├── react-dom@18.2.0 ✅ name starts with "react"
└── typescript@5.3.0

Combining with other selectors

Attribute selectors can be combined with combinators and pseudo-classes:

Terminal
$ vlt query ':root > [license=MIT]'

This selects only direct dependencies with an MIT license.

Nested properties

For nested package.json properties (like engines.node or peerDependenciesMeta), use the :attr() pseudo-class:

Terminal
$ vlt query ':attr(peerDependenciesMeta, foo, [optional=true])'

See also