UNPKG

query-registry

Version:

Query the npm registry for packuments, manifests, packages and download counts

53 lines (49 loc) 1.42 kB
import { fetchFromRegistry } from '../utils/fetch-from-registry.esm.js'; import { normalizeRawSearchCriteria } from '../utils/normalize-raw-search-criteria.esm.js'; /** * `searchPackages` returns the packages corresponding to a given query. * * @param query - one or more search criteria * @param registry - URL of the registry (default: npm registry) * @param mirrors - URLs of the registry mirrors (default: npm registry mirrors) * @param cached - accept cached responses (default: `true`) * * @example * Get the search results for text query `query-registry` from the npm registry: * * ```typescript * import { searchPackages } from 'query-registry'; * * (async () => { * const results = await searchPackages({ query: { text: 'query-registry' } }); * * // Output: 'query-registry' * console.log(results.objects[0].package.name); * })(); * ``` * * @see {@link SearchResults} * @see {@link SearchCriteria} * @see {@link npmRegistry} * @see {@link npmRegistryMirrors} */ async function searchPackages({ query: rawSearchCriteria, registry, mirrors, cached }) { const endpoint = '/-/v1/search'; const query = normalizeRawSearchCriteria({ rawSearchCriteria }); return fetchFromRegistry({ endpoint, query, registry, mirrors, cached }); } export { searchPackages }; //# sourceMappingURL=search-packages.esm.js.map