get-user-packages.js
This file contains 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 request = require('simple-get') | |
const getNpmUserPackages = name => | |
new Promise(resolve => { | |
let packages = [] | |
function req(page, cb) { | |
let url = `https://www.npmjs.com/profile/${name}/packages?offset=${page}` | |
request.concat(url, (e, _, data) => { | |
if (e) return reject(e) | |
const json = JSON.parse(data.toString()) | |
packages = packages.concat(json.objects) | |
if (json.hasMore) { | |
req(page + 1, cb) | |
} else { | |
cb(packages) | |
} | |
}) | |
} | |
req(0, resolve) | |
}) | |
getNpmUserPackages('jbucaran') | |
.then(packages => { | |
return packages.map(pkg => pkg.name).sort() | |
}) | |
.then(res => JSON.stringify(res, 0, 2)) | |
.then(console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example