astur / check-npm-dependents

Checks how many dependents has npm package.
MIT License
0 stars 0 forks source link

Expose a method that only does parsing #2

Closed sholladay closed 6 years ago

sholladay commented 6 years ago

There are two closely related, but separate steps that this package currently performs all in one go:

  1. Fetches a page on npm https://github.com/astur/check-npm-dependents/blob/126eeca401247275dab94a98377886d1d9ce8157/index.js#L5-L6
  2. Parses the fetched page to return a number https://github.com/astur/check-npm-dependents/blob/126eeca401247275dab94a98377886d1d9ce8157/index.js#L7-L10

The latter is what I am most interested in having an abstraction for. HTTP requests, on the other hand, are unfortunately a very leaky abstraction. I would prefer to have control over retries, caching semantics, etc. BYOC (Bring Your Own Client), if you will.

I imagine this being implemented as a .parse(html) method or similar.

astur commented 6 years ago

Do you mean something like this:

const check = require('check-npm-dependents');
const request = require('got');
request('https://www.npmjs.com/package/lodash')
    .then(check.parse)
    .then(console.log);
// for ex. 68195

Right?

sholladay commented 6 years ago

Yep, exactly. Currently, the HTTP client used to fetch the page is a blackbox that I cannot control, customize, or replace. Having a .parse() method that only does the parsing would allow me to compose the important part of this package with my own HTTP client.