query-registry
Version:
Query the npm registry for packuments, manifests, packages and download counts
25 lines (22 loc) • 1.04 kB
JavaScript
import urlJoin from "url-join";
import * as z from "zod";
import { fetchData } from "./fetch-data.js";
import { npmRegistryDownloadsApiUrl } from "./npm-registry.js";
export const RegistryDownloads = z.object({
/** Total number of downloads. */
downloads: z.number(),
/** Date of the first day (inclusive) in the format `YYYY-MM-DD`. */
start: z.string(),
/** Date of the last day (inclusive) in the format `YYYY-MM-DD`. */
end: z.string(),
});
/**
`getRegistryDownloads` returns the total number of downloads
for all packages in the registry in the given time period.
@param period - {@link DownloadPeriod | time period} in which downloads happened; the npm registry limits data to the last 18 months
@param registry - URL of the registry downloads API (default: npm registry downloads API)
@see {@link RegistryDownloads}
*/
export async function getRegistryDownloads(period, registry = npmRegistryDownloadsApiUrl) {
return await fetchData(RegistryDownloads, urlJoin(registry, `/downloads/point/${period}`));
}