UNPKG

1.73 kBPlain TextView Raw
1import { AbbreviatedPackument } from '../types/abbreviated-packument';
2import { normalizeRawAbbreviatedPackument } from '../utils/normalize-raw-abbreviated-packument';
3import { getRawAbbreviatedPackument } from './get-raw-abbreviated-packument';
4
5/**
6 * `getAbbreviatedPackument` returns the abbreviated packument (package document)
7 * containing only the metadata necessary to install a package present on the registry.
8 *
9 * @remarks
10 * To get all the metadata (full packument) about a package see {@link getPackument}.
11 *
12 * @param name - package name
13 * @param registry - URL of the registry (default: npm registry)
14 * @param mirrors - URLs of the registry mirrors (default: npm registry mirrors)
15 * @param cached - accept cached responses (default: `true`)
16 *
17 * @example
18 * Get the abbreviated packument for package `query-registry` from the npm registry:
19 *
20 * ```typescript
21 * import { getAbbreviatedPackument } from 'query-registry';
22 *
23 * (async () => {
24 * const packument = await getAbbreviatedPackument({ name: 'query-registry' });
25 *
26 * // Output: 'query-registry'
27 * console.log(packument.name);
28 * })();
29 * ```
30 *
31 * @see {@link AbbreviatedPackument}
32 * @see {@link RawAbbreviatedPackument}
33 * @see {@link npmRegistry}
34 * @see {@link npmRegistryMirrors}
35 */
36export async function getAbbreviatedPackument({
37 name,
38 registry,
39 mirrors,
40 cached,
41}: {
42 name: string;
43 registry?: string;
44 mirrors?: string[];
45 cached?: boolean;
46}): Promise<AbbreviatedPackument> {
47 const rawAbbreviatedPackument = await getRawAbbreviatedPackument({
48 name,
49 registry,
50 mirrors,
51 cached,
52 });
53 return normalizeRawAbbreviatedPackument({ rawAbbreviatedPackument });
54}