1 | import { fetchFromRegistry } from '../utils/fetch-from-registry.esm.js';
|
2 | import { normalizeRawSearchCriteria } from '../utils/normalize-raw-search-criteria.esm.js';
|
3 |
|
4 | /**
|
5 | * `searchPackages` returns the packages corresponding to a given query.
|
6 | *
|
7 | * @param query - one or more search criteria
|
8 | * @param registry - URL of the registry (default: npm registry)
|
9 | * @param mirrors - URLs of the registry mirrors (default: npm registry mirrors)
|
10 | * @param cached - accept cached responses (default: `true`)
|
11 | *
|
12 | * @example
|
13 | * Get the search results for text query `query-registry` from the npm registry:
|
14 | *
|
15 | * ```typescript
|
16 | * import { searchPackages } from 'query-registry';
|
17 | *
|
18 | * (async () => {
|
19 | * const results = await searchPackages({ query: { text: 'query-registry' } });
|
20 | *
|
21 | * // Output: 'query-registry'
|
22 | * console.log(results.objects[0].package.name);
|
23 | * })();
|
24 | * ```
|
25 | *
|
26 | * @see {@link SearchResults}
|
27 | * @see {@link SearchCriteria}
|
28 | * @see {@link npmRegistry}
|
29 | * @see {@link npmRegistryMirrors}
|
30 | */
|
31 |
|
32 | async function searchPackages({
|
33 | query: rawSearchCriteria,
|
34 | registry,
|
35 | mirrors,
|
36 | cached
|
37 | }) {
|
38 | const endpoint = '/-/v1/search';
|
39 | const query = normalizeRawSearchCriteria({
|
40 | rawSearchCriteria
|
41 | });
|
42 | return fetchFromRegistry({
|
43 | endpoint,
|
44 | query,
|
45 | registry,
|
46 | mirrors,
|
47 | cached
|
48 | });
|
49 | }
|
50 |
|
51 | export { searchPackages };
|
52 | //# sourceMappingURL=search-packages.esm.js.map
|