Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions docs/lib/content/commands/npm-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,56 @@ To show the `connect` package version history, you can do this:
npm view connect versions
```

### Field Access Patterns

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.

#### Nested Object Fields

Use dot notation to access nested object fields:

```bash
# Access nested properties
npm view npm repository.url
npm view express bugs.url
```

#### Array Element Access

For arrays, use numeric indices in square brackets to access specific elements:

```bash
# Get the first contributor's email
npm view express contributors[0].email

# Get the second maintainer's name
npm view express maintainers[1].name
```

#### Object Property Access

For object properties (like accessing specific versions in the `time` field), use bracket notation with the property name in quotes:

```bash
# Get publish time for a specific version
npm view express "time[4.17.1]"

# Get dist-tags
npm view express "dist-tags.latest"
```

#### Extracting Fields from Arrays

Request a non-numeric field on an array to get all values from objects in the list:

```bash
# Get all contributor emails
npm view express contributors.email

# Get all contributor names
npm view express contributors.name
```

### Configuration

<!-- AUTOGENERATED CONFIG DESCRIPTIONS -->
Expand Down
Loading