An open API service indexing awesome lists of open source software.

https://github.com/doowb/downloads

Retrieve npm download stats for the specified repository or maintainer.
https://github.com/doowb/downloads

Last synced: about 2 months ago
JSON representation

Retrieve npm download stats for the specified repository or maintainer.

Awesome Lists containing this project

README

        

# downloads [![NPM version](https://img.shields.io/npm/v/downloads.svg?style=flat)](https://www.npmjs.com/package/downloads) [![NPM downloads](https://img.shields.io/npm/dm/downloads.svg?style=flat)](https://npmjs.org/package/downloads) [![Linux Build Status](https://img.shields.io/travis/doowb/downloads.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/downloads)

> Retrieve npm download stats for the specified repository or maintainer.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save downloads
```

## Usage

```js
var downloads = require('downloads');
```

## API

### [.repo](index.js#L38)

Retieve the download stats for the specified repository. The results are an array of download object that contain the `day` and `downloads` count for that day: `[{day: '2016-11-12', downloads: 12345}]`. This method will also emit a `repo` event on the `downloads` object when the downloads are available.

**Example**

```js
downloads.repo('micromatch', function(err, results) {
if (err) return console.error(err);
console.log(results);
});
//=> [
//=> { day: '2016-11-12', downloads: 94699 },
//=> { day: '2016-11-11', downloads: 264382 },
//=> { day: '2016-11-10', downloads: 309356 },
//=> { day: '2016-11-09', downloads: 290557 },
//=> { day: '2016-11-08', downloads: 316004 },
//=> ...
//=> ]
```

**Params**

* `name` **{String}**: Name of the repository to get download counts for.
* `options` **{Object}**: Additional options.
* `cb` **{Function}**: Optional callback function to get the results. If not provided, a promise is returned.
* `returns` **{Promise}**: If no callback function is provided, a promise is returned that will yield the results array.

**Events**

* `emits`: `repo` Emits `repo` event when downloads are available. Emits the repo name and download count array.

### [.maintainer](index.js#L102)

Retrieve the download stats for all of the repositories maintained by the specified maintainer. The results are an object where the key is the repository name and the value is an array of download counts. This is the same array returned by the [repo](#repo) method. This method will also emit a `repos` event when the `repos` have been retrieved for the maintainer and a `maintainer` event when all of the downloads have been retrieved and the final results object is available.

**Example**

```js
downloads.maintainer('doowb', function(err, results) {
if (err) return console.error(err);
console.log(results);
});
//=> {
//=> "add-collaborator": [...],
//=> "accountdown-token": [...],
//=> "add-banner": [...],
//=> "align-text": [...],
//=> "JSONStream": [...],
//=> "anchors": [...],
//=> "announcement": [...],
//=> ...
//=> }
```

**Params**

* `name` **{String}**: Name of the maintainer to retrieve download counts for.
* `options` **{Object}**: Additional options to control how the downloads are gathered.
* `options.limit` **{Number}**: Specify how many repositories can be processed concurrently. Defaults to 1.
* `cb` **{Function}**: Optional callback function to get the results. If not provied, a promise is returned.
* `returns` **{Promise}**: If no callback function is provied, a promise is returned that with yield the results object.

**Events**

* `emits`: `repos` Emits `repos` event when the maintainers repositories have been retrieved. Emits the maintainer name and the repository array.
* `emits`: `repo` Emits `repo` event for each repository after the repository's download counts are available.
* `emits`: `maintainer` Emits `maintainer` event when all of the download counts for all of the maintainer's repositories are available.

## About

### Related projects

[npm-api](https://www.npmjs.com/package/npm-api): Base class for retrieving data from the npm registry. | [homepage](https://github.com/doowb/npm-api "Base class for retrieving data from the npm registry.")

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

Please read the [contributing guide](contributing.md) for avice on opening issues, pull requests, and coding standards.

### Building docs

_(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).)_

To generate the readme and API documentation with [verb](https://github.com/verbose/verb):

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

### Running tests

Install dev dependencies:

```sh
$ npm install -d && npm test
```

### Author

**Brian Woodward**

* [github/doowb](https://github.com/doowb)
* [twitter/doowb](http://twitter.com/doowb)

### License

Copyright © 2016, [Brian Woodward](https://github.com/doowb).
Released under the [MIT license](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on November 13, 2016._