forked from doowb/npm-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maintainer.js
73 lines (63 loc) · 1.51 KB
/
maintainer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*!
* npm-api <https://github.com/doowb/npm-api>
*
* Copyright (c) 2016, Brian Woodward.
* Licensed under the MIT License.
*/
'use strict';
var utils = require('../utils');
var Base = require('./base');
/**
* Maintainer constructor. Create an instance of an npm maintainer by maintainer name.
*
* ```js
* var maintainer = new Maintainer('doowb');
* ```
*
* @param {String} `name` Name of the npm maintainer to get information about.
* @param {Object} `store` Optional cache store instance for caching results. Defaults to a memory store.
* @api public
*/
function Maintainer (name, store) {
if (!(this instanceof Maintainer)) {
return new Maintainer(name);
}
Base.call(this, store);
this.is('maintainer');
this.name = name;
}
/**
* Extend `Base`
*/
Base.extend(Maintainer);
/**
* Get the repositories owned by this maintainer.
*
* ```js
* maintainer.repos()
* .then(function(repos) {
* console.log(repos);
* }, function(err) {
* console.error(err);
* });
* ```
*
* @return {Promise} Returns array of repository names when promise resolves.
* @api public
*/
Maintainer.prototype.repos = function() {
return utils.co(function* (self) {
if (!self.cache.repos) {
var view = new self.View('byUser');
var results = yield view.query({key: JSON.stringify(self.name)});
self.cache.repos = results.map(function (repo) {
return repo.value;
});
}
return self.cache.repos;
}, this);
};
/**
* Exposes `Maintainer`
*/
module.exports = Maintainer;