-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (63 loc) · 1.48 KB
/
index.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
74
75
const GitHub = require('gh.js');
/**
* sortByStarredSize
* Sort your personal starred repos by size.
*
* @name sortByStarredSize
* @function
* @param {String} username The GitHub username.
* @param {String} lang A specific language.
* @param {Function} callback The callback function.
* @return {gh.js} The `gh.js` instance.
*/
function sortByStarredSize(username, lang, callback) {
if (typeof lang === 'function') {
callback = lang;
lang = undefined;
}
const gh = new GitHub();
gh.get(`users/${username}/starred`, { all: true }, (err, repos) => {
if (err) {
return callback(err);
}
if (lang) {
repos = repos.filter(x => x.language === standardLang(lang));
}
repos.sort((a, b) => {
return a.size > b.size ? 1 : -1;
});
callback(null, repos);
});
return gh;
}
const standardLang = lang => {
// js
if (['js', 'javascript', 'JavaScript'].includes(lang)) {
return 'JavaScript';
}
// py
if (['py', 'python', 'Python'].includes(lang)) {
return 'Python';
}
// ts
if (['ts', 'tsc', 'typescript', 'Typescript', 'TypeScript'].includes(lang)) {
return 'TypeScript';
}
// sh
if (['sh', 'shell', 'Shell'].includes(lang)) {
return 'Shell';
}
// md
if (['md', 'markdown', 'MarkDown', 'null'].includes(lang)) {
return null;
}
// c
if (['c', 'C'].includes(lang)) {
return 'C';
}
// c++
if (['c++', 'C++'].includes(lang)) {
return 'C++';
}
};
module.exports = sortByStarredSize;