npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

yan-scraper

v0.4.0

Published

Just another Node.js scraping module.

Readme

Installaton

npm install yan-scraper

Usage

var Scraper = require('yan-scraper');

var scraper = Scraper.instance;
scraper.addTemplate({
    name: 'IMDB',
    matchesFormat: function(url) {
        return url.toLowerCase().indexOf('imdb.com') !== -1;
    },
    callback: function(url, body, $) {
        // $ is cheerio

        return { body: body, provider: 'IMDB' };
    }
});

scraper.addTemplate({
    name: 'Amazon',
    matchesFormat: function(url) {
        return url.toLowerCase().indexOf('amazon.co.uk') !== -1;
    },
    callback: function(url, body, $) {
        // $ is cheerio

        return { body: body, provider: 'Amazon' };
    }
});

scraper.on('result', function(result) {
  console.log(result);
});

scraper.on('unmatched', function(url) {
  console.log("Oops, there's an URL that couldn't be handled - " + url);
});

scraper.queue('http://www.imdb.com/title/tt0140688/'); // Will be handled by the IMDB template
scraper.queue('http://www.amazon.co.uk/gp/product/B00E0YFOKI/'); // Will be handled by the Amazon template
scraper.start();

Templates

Templates can be added via the scraper.addTemplate() method and need to have name, matchesFormat and callback as fields. You can add as many templates to the scraper as you want. The one that matches a specific pattern in the queue will have its callback applied.

{
    name,          // String, unique identifier for the template
    matchesFormat, // Function with url as a parameter, return true if the url matches the template
    callback,      // Callback function with body and $ as paramters;
                   //    - body is the response retrieved from the link
                   //    - $ is cheerio
    interval       // Number, the amount of miliseconds to wait between requests for the same template

}

Priorities

Queueing URLs for the scraper to process can be done via the scraper.queue(url [, priority=0]) function. Generally, this will mean that it will get processed depending on how many URLs are in the queue and what the interval defined in the template or options is.

However, the queue can be jumped by doing scraper.queue(url, 1). This will result in the URL provided to be added in a separate queue which only keeps track of the priority URLs and will still respect the interval, but will overalap with the regular queue. The amortized average request interval between the regular and priority queues will be equal to the interval.

Example:

var scraper = Scraper.instance;
scraper.setOptions({ interval: 2000 });
scraper.queue('http://www.example.com/1', 0); 
scraper.queue('http://www.example.com/2', 0);
scraper.queue('http://www.example.com/3', 1);
scraper.queue('http://www.example.com/4', 1);
scraper.queue('http://www.example.com/5', 0);
scraper.start();

will result in the links being ran approximately like:

     0ms - http://www.example.com/1, http://www.example.com/3
+ 2000ms - http://www.example.com/2, http://www.example.com/4
+ 4000ms - http://www.example.com/5

Options

Options can be passed by calling the setOptions(options) method on an instance or when doing start(). Currently supported options:

{
    maxInterval,   // Number, the maximum amount of miliseconds to wait between requests for the same template,
                   // will cap any of the intervals defined for individual templates
    interval,      // Number, absolute amount of miliseconds to wait between requests for the same template,
                   // will completely override any interval defined for individual templates
}

Testing

Still needs some work, but the current tests can be ran by doing:

npm test

grunt-cli is a prerequisite.

License

MIT