UNPKG

query-registry

Version:

Query the npm registry for packuments, manifests, packages and download counts

30 lines (27 loc) 1.27 kB
import urlJoin from "url-join"; import * as z from "zod"; import { fetchData } from "./fetch-data.js"; import { npmRegistryDownloadsApiUrl } from "./npm-registry.js"; export const DailyRegistryDownloads = z.object({ /** 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(), /** Download counts for each day. */ downloads: z.array(z.object({ /** Total number of downloads for the day. */ downloads: z.number(), /** Date of the day in the format `YYYY-MM-DD`. */ day: z.string(), })), }); /** `getDailyRegistryDownloads` returns the total number of downloads for each day 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 DailyRegistryDownloads} */ export async function getDailyRegistryDownloads(period, registry = npmRegistryDownloadsApiUrl) { return await fetchData(DailyRegistryDownloads, urlJoin(registry, `/downloads/range/${period}`)); }