Skip to content

Instantly share code, notes, and snippets.

@yesmeck
Last active September 30, 2018 23:19
Show Gist options
  • Save yesmeck/8d9cc14275b0d7b33dbd2c22f9f50beb to your computer and use it in GitHub Desktop.
Save yesmeck/8d9cc14275b0d7b33dbd2c22f9f50beb to your computer and use it in GitHub Desktop.
css in js lib stars
const fs = require('fs');
const request = require('superagent');
const content = fs.readFileSync('./README.md').toString();
const matches = content.match(/\|\s+\[.+?\]\(.+?\)\s+\|/g);
const token = '26010ba7569034ff9ce5913d5c15b5f233cf3c0c';
let list = [];
Promise.all(matches.map(line => {
const [_, name, url] = line.match(/\[(.+?)\]\((.+?)\)/);
const repo = url.match(/github.com\/(.+)/)[1];
return new Promise(resolve => {
request
.get(`https://api.github.com/repos/${repo}`)
.set('Authorization', 'Basic xxx')
.end((err, res) => {
list.push({
name,
url,
stargazers_count: res.body.stargazers_count,
});
resolve();
});
})
})).then(() => {
list = list.sort((a, b) => b.stargazers_count - a.stargazers_count);
console.log(list.slice(0, 10));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment