1 | import { fetchDownloadsFromRegistry } from '../utils/fetch-downloads-from-registry.esm.js';
|
2 | import { normalizeRawDownloadPeriod } from '../utils/normalize-download-period.esm.js';
|
3 |
|
4 | /**
|
5 | * `getDailyRegistryDownloads` returns the number of downloads for all registry packages
|
6 | * for each day in a given time period.
|
7 | *
|
8 | * @param period - time period in which downloads happened (default: `last-week`)
|
9 | * @param registryDownloadsAPI - URL of the registry's downloads API (default: npm registry)
|
10 | * @param cached - accept cached responses (default: `true`)
|
11 | *
|
12 | * @example
|
13 | * Get the day by day weekly downloads for the npm registry:
|
14 | *
|
15 | * ```typescript
|
16 | * import { getDailyRegistryDownloads } from 'query-registry';
|
17 | *
|
18 | * (async () => {
|
19 | * const downloads = await getDailyRegistryDownloads();
|
20 | *
|
21 | * // Output: 'number'
|
22 | * console.log(typeof downloads.downloads[0].downloads);
|
23 | * })();
|
24 | * ```
|
25 | *
|
26 | * @example
|
27 | * Get the day by day monthly downloads for the npm registry:
|
28 | *
|
29 | * ```typescript
|
30 | * import { getDailyRegistryDownloads } from 'query-registry';
|
31 | *
|
32 | * (async () => {
|
33 | * const downloads = await getDailyRegistryDownloads({ period: 'last-month' });
|
34 | *
|
35 | * // Output: 'number'
|
36 | * console.log(typeof downloads.downloads[0].downloads);
|
37 | * })();
|
38 | * ```
|
39 | *
|
40 | * @see {@link DailyRegistryDownloads}
|
41 | * @see {@link DownloadPeriod}
|
42 | * @see {@link npmRegistryDownloadsAPI}
|
43 | * @see {@link https://github.com/npm/registry/blob/master/docs/download-counts.md#ranges}
|
44 | */
|
45 |
|
46 | async function getDailyRegistryDownloads({
|
47 | period: rawDownloadPeriod,
|
48 | registryDownloadsAPI,
|
49 | cached
|
50 | } = {}) {
|
51 | const period = normalizeRawDownloadPeriod({
|
52 | rawDownloadPeriod
|
53 | });
|
54 | const endpoint = `/downloads/range/${period}`;
|
55 | return fetchDownloadsFromRegistry({
|
56 | endpoint,
|
57 | registryDownloadsAPI,
|
58 | cached
|
59 | });
|
60 | }
|
61 |
|
62 | export { getDailyRegistryDownloads };
|
63 | //# sourceMappingURL=get-daily-registry-downloads.esm.js.map
|