You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/lib/content/commands/npm-view.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,6 +98,56 @@ To show the `connect` package version history, you can do this:
98
98
npm view connect versions
99
99
```
100
100
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:
0 commit comments