Giter Club home page Giter Club logo

check-npm-dependents's Introduction

check-npm-dependents

Checks how many dependents has npm package.

Build Status NPM version

Install

npm i check-npm-dependents

Usage

const check = require('check-npm-dependents');
check('lodash').then(console.log) // for ex. 68195
check('_ABC').then(console.log) // Error: Unable to determine dependents for package: "_ABC"
check('').then(console.log) // Error: Bad name : ""

License

MIT

check-npm-dependents's People

Contributors

astur avatar

Watchers

 avatar  avatar

check-npm-dependents's Issues

Bad name on inconsistent packages

I'm using this to sort through hundreds of thousands of NPM packages, and it will give a bad name error for a package in one run but resolve properly in another. Any ideas why this might be happening?

It got through 40k packages before starting to do this.

Throw errors instead of returning -1

When things go wrong, this package currently returns -1.

if(response.statusCode !== 200) return -1;

if(depLink.length !== 1) return -1;

Since these represent unrecoverable errors, I would like an error to be thrown instead. Otherwise, I will have to write something like this around every invocation to avoid running the business logic when the data is unavailable:

if (dependents === -1) {
    throw new Error(`Unable to determine dependents for package: "${name}"`);
}
// ... business logic

Expose a method that only does parsing

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

  1. Fetches a page on npm
    const response = await scra(`https://www.npmjs.com/package/${name}`);
    if(response.statusCode !== 200) return -1;
  2. Parses the fetched page to return a number
    const $ = load(response.body);
    const depLink = $('a[href="?activeTab=dependents"]');
    if(depLink.length !== 1) return -1;
    return +depLink.text().replace(/[^0-9]/g, '');

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.