{"name":"download-stats","description":"Get and calculate npm download stats for npm modules.","version":"0.3.1","homepage":"https://github.com/doowb/download-stats","author":{"name":"Brian Woodward","url":"https://github.com/doowb"},"repository":{"type":"git","url":"git+https://github.com/doowb/download-stats.git"},"bugs":{"url":"https://github.com/doowb/download-stats/issues"},"license":"MIT","files":["index.js","lib"],"main":"index.js","engines":{"node":">=0.10.0"},"scripts":{"test":"mocha"},"dependencies":{"JSONStream":"^1.2.1","lazy-cache":"^2.0.1","moment":"^2.15.1"},"devDependencies":{"gulp-format-md":"^0.1.10","mocha":"^3.0.2"},"keywords":["calculate","calculate-downloads","download","download-stats","downloads","get","get-downloads","stats"],"verb":{"toc":true,"layout":"default","tasks":["readme"],"plugins":["gulp-format-md"],"related":{"list":[{"npm-info":true}]},"reflinks":["verb","verb-generate-readme"]},"gitHead":"b43db9ff32424073623f7fdfcab3814ae65f088c","_id":"download-stats@0.3.1","_shasum":"4a56413d4ca0fef56d8708c114582c629a7f2156","_from":".","_npmVersion":"3.7.5","_nodeVersion":"5.1.1","_npmUser":{"name":"doowb","email":"brian.woodward@gmail.com"},"dist":{"shasum":"4a56413d4ca0fef56d8708c114582c629a7f2156","tarball":"http://registry-npm.ywwl.com/download-stats/download/download-stats-0.3.1.tgz","integrity":"sha512-o/PLCONDUnUBnOyXOAKuCftw06u6j8ZnqcOPjy9dKCcxcM+Om1TrqYEZn5WfsGEhw0CBL4cvtH0jfBrMjlOc0A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBdQa+GjHMwlSOJTjzW9GI5wBkTTnyYjnXdV5upC7suBAiEA9URL8Ug8uM27L5aw5jU7zpLClMCLBYlAAx/42fTiXEE="}],"size":5732,"noattachment":false,"key":"/download-stats/-/download-stats-0.3.1.tgz"},"maintainers":[{"name":"doowb","email":"brian.woodward@gmail.com"},{"name":"jonschlinkert","email":"github@sellside.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/download-stats-0.3.1.tgz_1475863442675_0.18572509661316872"},"directories":{},"readme":"# download-stats [![NPM version](https://img.shields.io/npm/v/download-stats.svg?style=flat)](https://www.npmjs.com/package/download-stats) [![NPM downloads](https://img.shields.io/npm/dm/download-stats.svg?style=flat)](https://npmjs.org/package/download-stats) [![Linux Build Status](https://img.shields.io/travis/doowb/download-stats.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/download-stats)\n\n> Get and calculate npm download stats for npm modules.\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n- [API](#api)\n- [Get downloads](#get-downloads)\n- [Calculate](#calculate)\n- [About](#about)\n  * [Related projects](#related-projects)\n  * [Contributing](#contributing)\n  * [Contributors](#contributors)\n  * [Release history](#release-history)\n  * [Building docs](#building-docs)\n  * [Running tests](#running-tests)\n  * [Author](#author)\n  * [License](#license)\n\n_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save download-stats\n```\n\n## Usage\n\n```js\nvar stats = require('download-stats');\n```\n\n## API\n\n### [.get](index.js#L42)\n\nGet 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 }`.\n\n**Example**\n\n```js\nvar start = new Date('2016-01-09');\nvar end = new Date('2016-01-10');\nstats.get(start, end, 'micromatch')\n  .on('error', console.error)\n  .on('data', function(data) {\n    console.log(data);\n  })\n  .on('end', function() {\n    console.log('done.');\n  });\n// { day: '2016-01-09', downloads: 53331 }\n// { day: '2016-01-10', downloads: 47341 }\n```\n\n**Params**\n\n* `start` **{Date}**: Start date of stream.\n* `end` **{Date}**: End date of stream.\n* `repo` **{String}**: Repository to get downloads for. If `repo` is not passed, then all npm downloads for the day will be returned.\n* `returns` **{Stream}**: Stream of download data.\n\n### [.calc](index.js#L52)\n\nCalculate object containing methods to calculate stats on arrays of download counts.\nSee [calculate][#calculate] api docs for more information.\n\n## Get downloads\n\n### [get](lib/get.js#L31)\n\nGet 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 }`.\n\n**Example**\n\n```js\nvar start = new Date('2016-01-09');\nvar end = new Date('2016-01-10');\nstats.get(start, end, 'micromatch')\n  .on('error', console.error)\n  .on('data', function(data) {\n    console.log(data);\n  })\n  .on('end', function() {\n    console.log('done.');\n  });\n// { day: '2016-01-09', downloads: 53331 }\n// { day: '2016-01-10', downloads: 47341 }\n```\n\n**Params**\n\n* `start` **{Date}**: Start date of stream.\n* `end` **{Date}**: End date of stream.\n* `repo` **{String}**: Repository to get downloads for. If `repo` is not passed, then all npm downloads for the day will be returned.\n* `returns` **{Stream}**: Stream of download data.\n\n### [.point](lib/get.js#L76)\n\nGet a specific point (all-time, last-month, last-week, last-day)\n\n**Example**\n\n```js\nstats.get.period('last-day', 'micromatch', function(err, results) {\n  if (err) return console.error(err);\n  console.log(results);\n});\n// { day: '2016-01-10', downloads: 47341 }\n```\n\n**Params**\n\n* `period` **{String}**: Period to retrieve downloads for.\n* `repo` **{String}**: Repository to retrieve downloads for.\n* `cb` **{Function}**: Callback function to get results\n\n### [.allTime](lib/get.js#L112)\n\nGet the all time total downloads for a repository.\n\n**Example**\n\n```js\nstats.get.allTime('micromatch', function(err, results) {\n  if (err) return console.error(err);\n  console.log(results);\n});\n// { day: '2016-01-10', downloads: 47341 }\n```\n\n**Params**\n\n* `repo` **{String}**: Repository to retrieve downloads for.\n* `cb` **{Function}**: Callback function to get results\n\n### [.lastMonth](lib/get.js#L131)\n\nGet the last month's total downloads for a repository.\n\n**Example**\n\n```js\nstats.get.lastMonth('micromatch', function(err, results) {\n  if (err) return console.error(err);\n  console.log(results);\n});\n// { downloads: 7750788, start: '2016-10-10', end: '2016-11-08', package: 'micromatch' }\n```\n\n**Params**\n\n* `repo` **{String}**: Repository to retrieve downloads for.\n* `cb` **{Function}**: Callback function to get results\n\n### [.lastWeek](lib/get.js#L150)\n\nGet the last week's total downloads for a repository.\n\n**Example**\n\n```js\nstats.get.lastWeek('micromatch', function(err, results) {\n  if (err) return console.error(err);\n  console.log(results);\n});\n// { downloads: 1777065, start: '2016-11-02', end: '2016-11-08', package: 'micromatch' }\n```\n\n**Params**\n\n* `repo` **{String}**: Repository to retrieve downloads for.\n* `cb` **{Function}**: Callback function to get results\n\n### [.lastDay](lib/get.js#L169)\n\nGet the last day's total downloads for a repository.\n\n**Example**\n\n```js\nstats.get.lastDay('micromatch', function(err, results) {\n  if (err) return console.error(err);\n  console.log(results);\n});\n// { downloads: 316004, start: '2016-11-08', end: '2016-11-08', package: 'micromatch' }\n```\n\n**Params**\n\n* `repo` **{String}**: Repository to retrieve downloads for.\n* `cb` **{Function}**: Callback function to get results\n\n## Calculate\n\n### [.group](lib/calculate.js#L24)\n\nGroup array into object where keys are groups and values are arrays. Groups determined by provided `fn`.\n\n**Example**\n\n```js\nvar groups = calculate.group(downloads, function(download) {\n  // day is formatted as '2010-12-25'\n  // add this download to the '2010-12' group\n  return download.day.substr(0, 7);\n});\n```\n\n**Params**\n\n* `arr` **{Array}**: Array of download objects\n* `fn` **{Function}**: Function to determine group the download belongs in.\n* `returns` **{String}**: Key to use for the group\n\n### [.group.total](lib/calculate.js#L52)\n\nCalculate the total for each group (key) in the object.\n\n**Params**\n\n* `groups` **{Object}**: Object created by a `group` function.\n* `returns` **{Object}**: Object with calculated totals\n\n### [.total](lib/calculate.js#L76)\n\nCalculate the total downloads for an array of download objects.\n\n**Params**\n\n* `arr` **{Array}**: Array of download objects (must have a `.downloads` property)\n* `returns` **{Number}**: Total of all downloads in the array.\n\n### [.group.avg](lib/calculate.js#L93)\n\nCalculate the average for each group (key) in the object.\n\n**Params**\n\n* `groups` **{Object}**: Object created by a `group` function.\n* `returns` **{Object}**: Object with calculated average\n\n### [.avg](lib/calculate.js#L112)\n\nCalculate the average downloads for an array of download objects.\n\n**Params**\n\n* `arr` **{Array}**: Array of download objects (must have a `.downloads` property)\n* `returns` **{Number}**: Average of all downloads in the array.\n\n### [.group.before](lib/calculate.js#L136)\n\nCreate an array of downloads before specified day.\n\n**Params**\n\n* `day` **{String}**: Day specifying last day to use in group.\n* `arr` **{Array}**: Array of downloads to check.\n* `returns` **{Array}**: Array of downloads happened before or on specified day.\n\n### [.before](lib/calculate.js#L158)\n\nCalculate the total downloads happening before the specified day.\n\n**Params**\n\n* `day` **{String}**: Day specifying last day to use in group.\n* `arr` **{Array}**: Array of downloads to check.\n* `returns` **{Number}**: Total downloads happening before or on specified day.\n\n### [.group.last](lib/calculate.js#L174)\n\nCreate an array of downloads for the last `X` days.\n\n**Params**\n\n* `days` **{Number}**: Number of days to go back.\n* `arr` **{Array}**: Array of downloads to check.\n* `init` **{String}**: Optional day to use as the last day to include. (Days from `init || today` - `days` to `init || today`)\n* `returns` **{Array}**: Array of downloads for last `X` days.\n\n### [.last](lib/calculate.js#L203)\n\nCalculate total downloads for the last `X` days.\n\n**Params**\n\n* `days` **{Number}**: Number of days to go back.\n* `arr` **{Array}**: Array of downloads to check.\n* `init` **{String}**: Optional day to use as the last day to include. (Days from `init || today` - `days` to `init || today`)\n* `returns` **{Array}**: Array of downloads for last `X` days.\n\n### [.group.prev](lib/calculate.js#L219)\n\nCreate an array of downloads for the previous `X` days.\n\n**Params**\n\n* `days` **{Number}**: Number of days to go back.\n* `arr` **{Array}**: Array of downloads to check.\n* `init` **{String}**: Optional day to use as the prev day to include. (Days from `init || today` - `days` - `days` to `init || today` - `days`)\n* `returns` **{Array}**: Array of downloads for prev `X` days.\n\n### [.prev](lib/calculate.js#L237)\n\nCalculate total downloads for the previous `X` days.\n\n**Params**\n\n* `days` **{Number}**: Number of days to go back.\n* `arr` **{Array}**: Array of downloads to check.\n* `init` **{String}**: Optional day to use as the prev day to include. (Days from `init || today` - `days` - `days` to `init || today` - `days`)\n* `returns` **{Array}**: Array of downloads for prev `X` days.\n\n### [.monthly](lib/calculate.js#L250)\n\nCreate an object of download groups by month.\n\n**Params**\n\n* `arr` **{Array}**: Array of downloads to group and total.\n* `returns` **{Object}**: Groups with arrays of download objects\n\n### [.monthly](lib/calculate.js#L287)\n\nCalculate total downloads grouped by month.\n\n**Params**\n\n* `arr` **{Array}**: Array of downloads to group and total.\n* `returns` **{Object}**: Groups with total downloads calculated\n\n### [.yearly](lib/calculate.js#L300)\n\nCreate an object of download groups by month.\n\n**Params**\n\n* `arr` **{Array}**: Array of downloads to group and total.\n* `returns` **{Object}**: Groups with arrays of download objects\n\n### [.yearly](lib/calculate.js#L313)\n\nCalculate total downloads grouped by year.\n\n**Params**\n\n* `arr` **{Array}**: Array of downloads to group and total.\n* `returns` **{Object}**: Groups with total downloads calculated\n\n## About\n\n### Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n### Building docs\n\n_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_\n\nTo generate the readme and API documentation with [verb](https://github.com/verbose/verb):\n\n```sh\n$ npm install -g verb verb-generate-readme && verb\n```\n\n### Running tests\n\nInstall dev dependencies:\n\n```sh\n$ npm install -d && npm test\n```\n\n### Author\n\n**Brian Woodward**\n\n* [github/doowb](https://github.com/doowb)\n* [twitter/doowb](http://twitter.com/doowb)\n\n### License\n\nCopyright © 2016, [Brian Woodward](https://github.com/doowb).\nReleased under the [MIT license](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on November 09, 2016._","publish_time":1475863444245,"_cnpm_publish_time":1475863444245,"dist-tags":{"latest":"0.3.4"}}