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