From 6ee87c394a84d9bcd1398162fa3deef5bf2786dd Mon Sep 17 00:00:00 2001 From: Max Black Date: Sat, 29 Nov 2025 15:44:24 -0800 Subject: [PATCH] docs: add field access patterns to npm view --- docs/lib/content/commands/npm-view.md | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/docs/lib/content/commands/npm-view.md b/docs/lib/content/commands/npm-view.md index a882cb757e53a..4893d1a70d5a0 100644 --- a/docs/lib/content/commands/npm-view.md +++ b/docs/lib/content/commands/npm-view.md @@ -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