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