Created
July 16, 2020 17:19
-
-
Save Richienb/13919fb41a163f6bbe3fdc707520bd4c to your computer and use it in GitHub Desktop.
Get total month NPM download count for user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { search } = require("npms-api") | |
const got = require("got") | |
const totalled = require("totalled") | |
const pMap = require("p-map") | |
const npmUsername = "richienb" | |
const downloadCount = async packageName => { | |
try { | |
const {body} = await got(packageName, { | |
prefixUrl: "https://api.npmjs.org/downloads/point/last-month/", | |
responseType: "json" | |
}) | |
return body.downloads | |
} catch (_) { | |
return 0 | |
} | |
} | |
const {results: packages} = await search(`maintainer:${npmUsername}`, {results: Infinity}) | |
const packageNames = packages.map(({package}) => package.name) | |
console.log(totalled(await pMap(packageNames, downloadCount, {concurrency: 2}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment