Skip to content

Commit

Permalink
feat(npm): format versions to object array (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
marianfoo authored Apr 30, 2022
1 parent a2d8557 commit e0ea1f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/npm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IPackage, NPMDownloads, NPMDownloadsHistory, NPMDownloadsHistoryDownloads, PackageDownloadsHistory } from "./types";
import { IPackage, NPMDownloads, NPMDownloadsHistory, NPMDownloadsHistoryDownloads, NPMVersions, PackageDownloadsHistory } from "./types";
// import { getPackageManifest, searchPackages } from "query-registry";
import axios from "axios";
import { type } from "os";
// import removeMarkdown from "markdown-to-text";

function sleep(ms: number) {
Expand Down Expand Up @@ -155,7 +154,7 @@ export default class NpmProvider {
const metaData = await getMetaData(source.name);
source.createdAt = metaData?.data?.time?.created;
source.updatedAt = metaData?.data?.time?.modified;
source.versions = metaData?.data?.time;
source.versions = this.formatVersionToArray(metaData?.data?.time);
source.npmlink = `https://www.npmjs.com/package/${source.name}`;
} catch (error) {
console.error(`Error fetching npm metadata for ${source.name}`);
Expand Down Expand Up @@ -212,4 +211,15 @@ export default class NpmProvider {
}
return groupedByYearMonth;
}

static formatVersionToArray(version: any): NPMVersions[] {
let versions: NPMVersions[] = [];
for (const [key, value] of Object.entries(version)) {
versions.push({
version: key,
date: value as string,
});
}
return versions;
}
}
5 changes: 5 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,8 @@ export interface NPMDownloadsHistoryDownloads {
downloads: number;
day: string;
}

export interface NPMVersions {
date: string;
version: string;
}

0 comments on commit e0ea1f1

Please sign in to comment.