Skip to content

Instantly share code, notes, and snippets.

@johnwargo
Created January 3, 2025 18:06
Show Gist options
  • Save johnwargo/6890b6adc8aa4b242052c0e19fc28755 to your computer and use it in GitHub Desktop.
Save johnwargo/6890b6adc8aa4b242052c0e19fc28755 to your computer and use it in GitHub Desktop.
/**********************************************************
* Fetches all packages from the npm registry for a
* given author.
**********************************************************/
// https://github.com/npm/registry/blob/main/docs/REGISTRY-API.md
function _compareFunction(a, b) {
if (a.package.name < b.package.name) return -1;
if (a.package.name > b.package.name) return 1;
return 0;
}
module.exports = async function () {
const author = 'johnwargo';
var response = await fetch(`https://registry.npmjs.com/-/v1/search?text=author:${author}`);
var data = await response.json();
var packages = data.objects;
packages.sort(_compareFunction);
return packages;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment