-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (23 loc) · 761 Bytes
/
index.js
File metadata and controls
28 lines (23 loc) · 761 Bytes
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
'use strict';
const got = require('got');
const cheerio = require('cheerio');
module.exports = (username, repository) => {
const url = `https://github.com/${username}/${repository}/network/dependents`;
if (typeof repository !== 'string' || typeof repository !== 'string') {
throw new TypeError(`Expected a string, got ${typeof username} and ${typeof repository}`);
}
return got(url).then(res => {
const $ = cheerio.load(res.body);
const repo = $('.btn-link').eq(0).text().trim().split('\n')[0];
const pkg = $('.btn-link').eq(1).text().trim().split('\n')[0];
return {
repositories: repo,
packages: pkg
};
}).catch(err => {
if (err) {
err.message = `${username} has not build ${repository} yet`;
}
return err.message;
});
};