2.0.3 • Published 10 months ago
@beskar-labs/npm-feed v2.0.3
NPM Feed
A handy HTML to JSON parser for NPM.
Installation
yarn add @beskar-labs/npm-feed
Usage
The module exports a single function that takes an NPM username
(without the @
) and optionally, a boolean that determines whether to filter for packages namespaced under the @scope
of the username.
import getNpmFeed from '@beskar-labs/npm-feed';
/* Example of fetching all packages */
const feed1 = await getNpmFeed('haydenbleasel');
/* Example of fetching namespaced packages only */
const feed2 = await getNpmFeed('haydenbleasel', true);
How it works
On NPM profile pages, packages are available in JSON format in the HTML, in fact they're loaded into a window.__context__
variable. After fetching the page we use node-html-parser
to parse the DOM, find the script tag that contains the data we want and return it in JSON.
Contributing
If you have suggestions for how this module could be improved, or want to report a bug, open an issue! I'd love all and any contributions.