UNPKG

3.97 kBMarkdownView Raw
1# query-registry
2
3[![Build status](https://img.shields.io/github/workflow/status/velut/node-query-registry/CI)](https://github.com/velut/node-query-registry/actions?query=workflow%3ACI)
4[![Coverage](https://img.shields.io/codecov/c/gh/velut/node-query-registry)](https://codecov.io/gh/velut/node-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/node-query-registry)
7[![npm bundle size](https://img.shields.io/bundlephobia/min/query-registry)](https://bundlephobia.com/result?p=query-registry)
8[![npm](https://img.shields.io/npm/v/query-registry)](https://www.npmjs.com/package/query-registry)
9[![License](https://img.shields.io/github/license/velut/node-query-registry)](https://github.com/velut/node-query-registry/blob/main/LICENSE)
10
11This package exports several functions to query the [npm registry](https://www.npmjs.com) (or one of its mirrors) through one of its [endpoints](https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md).
12
13## Features
14
15- Provides functions to:
16 - Get registry metadata
17 - Get packuments (package documents) and their abbreviated form
18 - Get package manifests
19 - Get download counts (packages and registry)
20 - Search packages
21- Usable in the browser
22- Fully typed API and response data
23- Supports mirrors of the npm registry
24- Supports caching network requests
25- Well documented and tested
26
27## API & Package Info
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/node-query-registry)
32- Read the changelog on [**GitHub**](https://github.com/velut/node-query-registry/blob/main/CHANGELOG.md)
33
34## Install
35
36Using `npm`:
37
38```
39npm i query-registry
40```
41
42Using `yarn`:
43
44```
45yarn add query-registry
46```
47
48## Usage Examples
49
50Get the metadata for the npm registry:
51
52```typescript
53import { getRegistryMetadata } from 'query-registry';
54
55(async () => {
56 const metadata = await getRegistryMetadata();
57
58 // Output: 'registry'
59 console.log(metadata.db_name);
60})();
61```
62
63Get the latest manifest for package `query-registry` from the npm registry:
64
65```typescript
66import { getPackageManifest } from 'query-registry';
67
68(async () => {
69 const manifest = await getPackageManifest({ name: 'query-registry' });
70
71 // Output: 'query-registry'
72 console.log(manifest.name);
73})();
74```
75
76Get the abbreviated packument for package `query-registry` from the npm registry:
77
78```typescript
79import { getAbbreviatedPackument } from 'query-registry';
80
81(async () => {
82 const packument = await getAbbreviatedPackument({ name: 'query-registry' });
83
84 // Output: 'query-registry'
85 console.log(packument.name);
86})();
87```
88
89Get the weekly downloads for package `query-registry` from the npm registry:
90
91```typescript
92import { getPackageDownloads } from 'query-registry';
93
94(async () => {
95 const downloads = await getPackageDownloads({ name: 'query-registry' });
96
97 // Output: 'query-registry'
98 console.log(downloads.package);
99
100 // Output: 'number'
101 console.log(typeof downloads.downloads);
102})();
103```
104
105Get the search results for text query `query-registry` from the npm registry:
106
107```typescript
108import { searchPackages } from 'query-registry';
109
110(async () => {
111 const results = await searchPackages({
112 query: { text: 'query-registry' },
113 });
114
115 // Output: 'query-registry'
116 console.log(results.objects[0].package.name);
117})();
118```
119
120## Debug
121
122Debug messages are available in non production environments when the `DEBUG` environment variable is set to `query-registry`:
123
124```bash
125DEBUG="query-registry"
126```
127
128For more information, see the [debug package](https://www.npmjs.com/package/debug).
129
130## License
131
132MIT License
133
134Copyright (c) 2021 Edoardo Scibona
135
136See LICENSE file.