Here's a script to display search results from npm along with a preview of the package details and associated links.

Install search-npm

// Menu: NPM Search
// Description: Search NPM for packages
// Author: Jacob A. Swain
// Twitter: @jacobswain
// Email: jacobswain@gmail.com
import "@johnlindquist/kit";
const baseUrl = "https://www.npmjs.com/search/suggestions?q=";
const toData = (res) => res.data;
const term = await arg("Package name:");
let preview = async ({ name, description, version, links }) =>
await md(`
## ${name}
- Description: ${description}
- Version: ${version}
#### Links
${links.npm ? `- [npm](${links.npm})` : ""}
${links.repository ? `- [repository](${links.repository})` : ""}
${links.repository ? `- [homepage](${links.homepage})` : ""}
`);
const results = await get(`${baseUrl}${term}`)
.then(toData)
.then((results) =>
results.map(({ name, description, version, links }) => ({
name,
description,
value: links.npm,
preview: async () => preview({ name, description, version, links }),
}))
);
let url = await arg("Select package:", results);
await $`open ${url}`;

Here's a screenshot:

image