Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

download-stats

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

download-stats

Get and calculate npm download stats for npm modules.

  • 0.2.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
341K
increased by1.83%
Maintainers
2
Weekly downloads
 
Created
Source

download-stats NPM version Build Status

Get and calculate npm download stats for npm modules.

TOC

(TOC generated by verb using markdown-toc)

Install

Install with npm:

$ npm install download-stats --save

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 }.

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.

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 }

.calc

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

Calculate

.group

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

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

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);
});

.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

Contributing

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

Building docs

Generate readme and API documentation with [verb][]:

$ npm install verb && npm run docs

Or, if [verb][] is installed globally:

$ 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, v0.9.0, on February 29, 2016.

FAQs

Package last updated on 22 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc