Hex Elixir Package Search

I modified Jacob Swain's NPM Search to search for elixir packages on Hex. I'm not sure the proper way to do that attributution so I added OriginalAuthor

// Menu: Hex Elixir Package Search
// Description: Search Hex for Elixir packages
// Author: Joe Martinez
// Twitter: @capitalist
// I based this script on the NPM search done by Jacob Swain
// OriginalAuthor: Jacob A. Swain
// OriginalTwitter: @jacobswain
import "@johnlindquist/kit";
const baseUrl = "https://hex.pm/api/packages?sort=downloads&search=";
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.docs ? `- [Docs](${links.docs})` : ""}
${links.Changelog ? `- [Changelog](${links.Changelog})` : ""}
${links.GitHub ? `- [GitHub](${links.GitHub})` : ""}
`);
const results = await get(`${baseUrl}${term}`)
.then(toData)
.then((results) =>
results.map(({ name, meta, latest_version, html_url, docs_html_url }) => ({
name,
description: meta.description,
value: html_url,
preview: async () =>
preview({
name,
description: meta.description,
version: latest_version,
links: { docs: docs_html_url, ...meta.links },
}),
}))
);
let url = await arg("Select package:", results);
await $`open ${url}`;