Attribute Selectors
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
| Selector | Description |
|---|---|
[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:
$ vlt query '[name=react]'Select all scoped packages:
$ vlt query '[name^="@"]'Select packages in the @vltpkg scope:
$ vlt query '[name^="@vltpkg"]'Match by version
Select packages on a specific version:
$ vlt query '[version=1.0.0]'Select packages with major version 2:
$ vlt query '[version^=2]'Match by any property
Select packages that have a repository field:
$ vlt query '[repository]'Select packages with a specific license:
$ vlt query '[license=MIT]'Select packages whose description mentions “parser”:
$ vlt query '[description*=parser]'Case-insensitive matching
Find packages with “React” in the description regardless of case:
$ 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.0The 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.0Combining with other selectors
Attribute selectors can be combined with combinators and pseudo-classes:
$ 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:
$ vlt query ':attr(peerDependenciesMeta, foo, [optional=true])'See also
:attr()pseudo-class — match nestedpackage.jsonproperties- ID Selectors — shorthand for
[name=value]