Skip to content

Commit 2fc689d

Browse files
Max Blackowlstronaut
authored andcommitted
docs: add field access patterns to npm view
1 parent 4850639 commit 2fc689d

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/lib/content/commands/npm-view.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,56 @@ To show the `connect` package version history, you can do this:
9898
npm view connect versions
9999
```
100100

101+
### Field Access Patterns
102+
103+
The `npm view` command supports different ways to access nested fields and array elements in package metadata. Understanding these patterns makes it easier to extract specific information.
104+
105+
#### Nested Object Fields
106+
107+
Use dot notation to access nested object fields:
108+
109+
```bash
110+
# Access nested properties
111+
npm view npm repository.url
112+
npm view express bugs.url
113+
```
114+
115+
#### Array Element Access
116+
117+
For arrays, use numeric indices in square brackets to access specific elements:
118+
119+
```bash
120+
# Get the first contributor's email
121+
npm view express contributors[0].email
122+
123+
# Get the second maintainer's name
124+
npm view express maintainers[1].name
125+
```
126+
127+
#### Object Property Access
128+
129+
For object properties (like accessing specific versions in the `time` field), use bracket notation with the property name in quotes:
130+
131+
```bash
132+
# Get publish time for a specific version
133+
npm view express "time[4.17.1]"
134+
135+
# Get dist-tags
136+
npm view express "dist-tags.latest"
137+
```
138+
139+
#### Extracting Fields from Arrays
140+
141+
Request a non-numeric field on an array to get all values from objects in the list:
142+
143+
```bash
144+
# Get all contributor emails
145+
npm view express contributors.email
146+
147+
# Get all contributor names
148+
npm view express contributors.name
149+
```
150+
101151
### Configuration
102152

103153
<!-- AUTOGENERATED CONFIG DESCRIPTIONS -->

0 commit comments

Comments
 (0)