1 | import { Packument } from '../types/packument';
|
2 | import { RawPackument } from '../types/raw-packument';
|
3 | import { normalizeRawLicense } from './normalize-raw-license';
|
4 | import { normalizeRawRepository } from './normalize-raw-repository';
|
5 |
|
6 | export function normalizeRawPackument({
|
7 | rawPackument,
|
8 | }: {
|
9 | rawPackument: RawPackument;
|
10 | }): Packument {
|
11 | const {
|
12 | _id: id,
|
13 | 'dist-tags': distTags,
|
14 | time,
|
15 | license: rawLicense,
|
16 | repository: rawRepository,
|
17 | } = rawPackument;
|
18 | const license = normalizeRawLicense({ rawLicense });
|
19 | const gitRepository = normalizeRawRepository({ rawRepository });
|
20 | const versionsToTimestamps = Object.fromEntries(
|
21 | Object.entries(time).filter(([key]) => {
|
22 | return !['created', 'modified'].includes(key);
|
23 | })
|
24 | );
|
25 |
|
26 | return {
|
27 | ...rawPackument,
|
28 | id,
|
29 | distTags,
|
30 | versionsToTimestamps,
|
31 | license,
|
32 | gitRepository,
|
33 | };
|
34 | }
|