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 🙏

© 2024 – Pkg Stats / Ryan Hefner

download-stats

v0.3.4

Published

Get and calculate npm download stats for npm modules.

Downloads

1,286,290

Readme

download-stats NPM version NPM downloads Linux Build Status

Get and calculate npm download stats for npm modules.

Table of Contents

(TOC generated by verb using markdown-toc)

Install

Install with npm:

$ npm install --save download-stats

Usage

var stats = require('download-stats');

API

.get

Get a range of download counts for the specified repository. This method returns a stream of raw data in the form of { day: '2016-01-10', downloads: 123456 }.

Example

var start = new Date('2016-01-09');
var end = new Date('2016-01-10');
stats.get(start, end, 'micromatch')
  .on('error', console.error)
  .on('data', function(data) {
    console.log(data);
  })
  .on('end', function() {
    console.log('done.');
  });
// { day: '2016-01-09', downloads: 53331 }
// { day: '2016-01-10', downloads: 47341 }

Params

  • start {Date}: Start date of stream.
  • end {Date}: End date of stream.
  • repo {String}: Repository to get downloads for. If repo is not passed, then all npm downloads for the day will be returned.
  • returns {Stream}: Stream of download data.

.calc

Calculate object containing methods to calculate stats on arrays of download counts. See [calculate][#calculate] api docs for more information.

Get downloads

get

Get a range of download counts for the specified repository. This method returns a stream of raw data in the form of { day: '2016-01-10', downloads: 123456 }.

Example

var start = new Date('2016-01-09');
var end = new Date('2016-01-10');
stats.get(start, end, 'micromatch')
  .on('error', console.error)
  .on('data', function(data) {
    console.log(data);
  })
  .on('end', function() {
    console.log('done.');
  });
// { day: '2016-01-09', downloads: 53331 }
// { day: '2016-01-10', downloads: 47341 }

Params

  • start {Date}: Start date of stream.
  • end {Date}: End date of stream.
  • repo {String}: Repository to get downloads for. If repo is not passed, then all npm downloads for the day will be returned.
  • returns {Stream}: Stream of download data.

.point

Get a specific point (all-time, last-month, last-week, last-day)

Example

stats.get.period('last-day', 'micromatch', function(err, results) {
  if (err) return console.error(err);
  console.log(results);
});
// { day: '2016-01-10', downloads: 47341 }

Params

  • period {String}: Period to retrieve downloads for.
  • repo {String}: Repository to retrieve downloads for.
  • cb {Function}: Callback function to get results

.allTime

Get the all time total downloads for a repository.

Example

stats.get.allTime('micromatch', function(err, results) {
  if (err) return console.error(err);
  console.log(results);
});
// { day: '2016-01-10', downloads: 47341 }

Params

  • repo {String}: Repository to retrieve downloads for.
  • cb {Function}: Callback function to get results

.lastMonth

Get the last month's total downloads for a repository.

Example

stats.get.lastMonth('micromatch', function(err, results) {
  if (err) return console.error(err);
  console.log(results);
});
// { downloads: 7750788, start: '2016-10-10', end: '2016-11-08', package: 'micromatch' }

Params

  • repo {String}: Repository to retrieve downloads for.
  • cb {Function}: Callback function to get results

.lastWeek

Get the last week's total downloads for a repository.

Example

stats.get.lastWeek('micromatch', function(err, results) {
  if (err) return console.error(err);
  console.log(results);
});
// { downloads: 1777065, start: '2016-11-02', end: '2016-11-08', package: 'micromatch' }

Params

  • repo {String}: Repository to retrieve downloads for.
  • cb {Function}: Callback function to get results

.lastDay

Get the last day's total downloads for a repository.

Example

stats.get.lastDay('micromatch', function(err, results) {
  if (err) return console.error(err);
  console.log(results);
});
// { downloads: 316004, start: '2016-11-08', end: '2016-11-08', package: 'micromatch' }

Params

  • repo {String}: Repository to retrieve downloads for.
  • cb {Function}: Callback function to get results

Calculate

.group

Group array into object where keys are groups and values are arrays. Groups determined by provided fn.

Example

var groups = calculate.group(downloads, function(download) {
  // day is formatted as '2010-12-25'
  // add this download to the '2010-12' group
  return download.day.substr(0, 7);
});

Params

  • arr {Array}: Array of download objects
  • fn {Function}: Function to determine group the download belongs in.
  • returns {String}: Key to use for the group

.group.total

Calculate the total for each group (key) in the object.

Params

  • groups {Object}: Object created by a group function.
  • returns {Object}: Object with calculated totals

.total

Calculate the total downloads for an array of download objects.

Params

  • arr {Array}: Array of download objects (must have a .downloads property)
  • returns {Number}: Total of all downloads in the array.

.group.avg

Calculate the average for each group (key) in the object.

Params

  • groups {Object}: Object created by a group function.
  • returns {Object}: Object with calculated average

.avg

Calculate the average downloads for an array of download objects.

Params

  • arr {Array}: Array of download objects (must have a .downloads property)
  • returns {Number}: Average of all downloads in the array.

.group.before

Create an array of downloads before specified day.

Params

  • day {String}: Day specifying last day to use in group.
  • arr {Array}: Array of downloads to check.
  • returns {Array}: Array of downloads happened before or on specified day.

.before

Calculate the total downloads happening before the specified day.

Params

  • day {String}: Day specifying last day to use in group.
  • arr {Array}: Array of downloads to check.
  • returns {Number}: Total downloads happening before or on specified day.

.group.last

Create an array of downloads for the last X days.

Params

  • days {Number}: Number of days to go back.
  • arr {Array}: Array of downloads to check.
  • init {String}: Optional day to use as the last day to include. (Days from init || today - days to init || today)
  • returns {Array}: Array of downloads for last X days.

.last

Calculate total downloads for the last X days.

Params

  • days {Number}: Number of days to go back.
  • arr {Array}: Array of downloads to check.
  • init {String}: Optional day to use as the last day to include. (Days from init || today - days to init || today)
  • returns {Array}: Array of downloads for last X days.

.group.prev

Create an array of downloads for the previous X days.

Params

  • days {Number}: Number of days to go back.
  • arr {Array}: Array of downloads to check.
  • init {String}: Optional day to use as the prev day to include. (Days from init || today - days - days to init || today - days)
  • returns {Array}: Array of downloads for prev X days.

.prev

Calculate total downloads for the previous X days.

Params

  • days {Number}: Number of days to go back.
  • arr {Array}: Array of downloads to check.
  • init {String}: Optional day to use as the prev day to include. (Days from init || today - days - days to init || today - days)
  • returns {Array}: Array of downloads for prev X days.

.monthly

Create an object of download groups by month.

Params

  • arr {Array}: Array of downloads to group and total.
  • returns {Object}: Groups with arrays of download objects

.monthly

Calculate total downloads grouped by month.

Params

  • arr {Array}: Array of downloads to group and total.
  • returns {Object}: Groups with total downloads calculated

.yearly

Create an object of download groups by month.

Params

  • arr {Array}: Array of downloads to group and total.
  • returns {Object}: Groups with arrays of download objects

.yearly

Calculate total downloads grouped by year.

Params

  • arr {Array}: Array of downloads to group and total.
  • returns {Object}: Groups with total downloads calculated

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Brian Woodward

License

Copyright © 2016, Brian Woodward. Released under the MIT license.


This file was generated by verb-generate-readme, v0.2.0, on November 09, 2016.