{"id":15654552,"url":"https://github.com/doowb/download-stats","last_synced_at":"2025-07-18T05:08:08.658Z","repository":{"id":57215714,"uuid":"49468702","full_name":"doowb/download-stats","owner":"doowb","description":"Get and calculate npm download stats for npm modules.","archived":false,"fork":false,"pushed_at":"2018-03-28T16:04:45.000Z","size":35,"stargazers_count":28,"open_issues_count":4,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-29T06:18:39.532Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/doowb.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-12T02:18:58.000Z","updated_at":"2024-12-24T11:48:38.000Z","dependencies_parsed_at":"2022-08-26T13:31:29.946Z","dependency_job_id":null,"html_url":"https://github.com/doowb/download-stats","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/doowb/download-stats","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fdownload-stats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fdownload-stats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fdownload-stats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fdownload-stats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doowb","download_url":"https://codeload.github.com/doowb/download-stats/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fdownload-stats/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265703590,"owners_count":23814034,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T12:52:25.043Z","updated_at":"2025-07-18T05:08:08.634Z","avatar_url":"https://github.com/doowb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"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\u0026label=Travis)](https://travis-ci.org/doowb/download-stats)\n\n\u003e 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.point('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 \u0026\u0026 verb\n```\n\n### Running tests\n\nInstall dev dependencies:\n\n```sh\n$ npm install -d \u0026\u0026 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._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fdownload-stats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoowb%2Fdownload-stats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fdownload-stats/lists"}