UNPKG

4.54 kBMarkdownView Raw
1# query-registry
2
3[![Build status](https://img.shields.io/github/actions/workflow/status/velut/query-registry/main.yml?branch=main)](https://github.com/velut/query-registry/actions?query=workflow%3ACI)
4[![Coverage](https://img.shields.io/codecov/c/gh/velut/query-registry)](https://codecov.io/gh/velut/query-registry)
5[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/query-registry)
6![Language](https://img.shields.io/github/languages/top/velut/query-registry)
7[![npm](https://img.shields.io/npm/v/query-registry)](https://www.npmjs.com/package/query-registry)
8[![License](https://img.shields.io/github/license/velut/query-registry)](https://github.com/velut/query-registry/blob/main/LICENSE)
9
10`query-registry` is an API wrapper for the [npm registry API](https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md).
11
12## Features
13
14- Provides functions to:
15 - Get registry metadata.
16 - Get registry public keys.
17 - Get packuments (package documents) with full package metadata.
18 - Get abbreviated packuments with installation data only.
19 - Get package manifests for each version of a package.
20 - Get download counts for the registry and for packages.
21 - Search packages by name and other specific criteria.
22- Works in the browser.
23- Validates registry responses with [zod](https://www.npmjs.com/package/zod).
24- Automatically caches registry responses for a short time.
25- Supports third-party npm-compatible registries.
26
27## Useful resources
28
29- [**Explore the API on jsDocs.io**](https://www.jsdocs.io/package/query-registry)
30- View package contents on [**unpkg**](https://unpkg.com/query-registry/)
31- View repository on [**GitHub**](https://github.com/velut/query-registry)
32- Read the changelog on [**GitHub**](https://github.com/velut/query-registry/blob/main/CHANGELOG.md)
33
34## Install
35
36Using `npm`:
37
38```
39npm add query-registry
40```
41
42Using `yarn`:
43
44```
45yarn add query-registry
46```
47
48Using `pnpm`:
49
50```
51pnpm add query-registry
52```
53
54Using `bun`:
55
56```
57bun add query-registry
58```
59
60## Usage examples
61
62### Registry
63
64Get the metadata about the npm registry itself, if available:
65
66```typescript
67import { getRegistryMetadata } from "query-registry";
68
69const metadata = await getRegistryMetadata();
70```
71
72Get the public signing keys for the npm registry:
73
74```typescript
75import { getRegistrySigningKeys } from "query-registry";
76
77const { keys } = await getRegistrySigningKeys();
78```
79
80### Packuments (Package documents)
81
82Get the abbreviated packument containing only the necessary data to install the `react` package:
83
84```typescript
85import { getAbbreviatedPackument } from "query-registry";
86
87const abbrPackument = await getAbbreviatedPackument("react");
88```
89
90Get the full packument containing all the data available about the `react` package:
91
92```typescript
93import { getPackument } from "query-registry";
94
95const packument = await getPackument("react");
96```
97
98### Package manifests
99
100Get the manifest containing the original `package.json` data plus additional registry metadata for the `latest` version of the `react` package:
101
102```typescript
103import { getPackageManifest } from "query-registry";
104
105const manifest = await getPackageManifest("react");
106```
107
108Get the manifest for `react@18.2.0` (semver version):
109
110```typescript
111import { getPackageManifest } from "query-registry";
112
113const manifest = await getPackageManifest("react", "18.2.0");
114```
115
116Get the manifest for `react@next` (distribution tag):
117
118```typescript
119import { getPackageManifest } from "query-registry";
120
121const manifest = await getPackageManifest("react", "next");
122```
123
124### Search packages
125
126Search packages related to `react` (e.g., `react`, `react-dom`, ...):
127
128```typescript
129import { searchPackages } from "query-registry";
130
131const results = await searchPackages({ text: "react" });
132```
133
134### Download counts
135
136Get the total number of downloads for package `react` for the last month:
137
138```typescript
139import { getPackageDownloads } from "query-registry";
140
141const { downloads } = await getPackageDownloads("react", "last-month");
142```
143
144There are also these other download counts functions available: `getBulkDailyPackageDownloads`, `getBulkPackageDownloads`, `getDailyPackageDownloads`, `getDailyRegistryDownloads` and `getPackageVersionsDownloads`.
145
146### Cache
147
148Clear the internal cache.
149
150```typescript
151import { cache } from "query-registry";
152
153cache.clear();
154```
155
156See the [quick-lru](https://www.npmjs.com/package/quick-lru) package for the cache API.
157
158## License
159
160```
161MIT
162```
163
164Copyright (c) 2024 Edoardo Scibona
165
166See [LICENSE](./LICENSE) file.