Last active
May 2, 2022 00:53
-
-
Save LeaveNhA/14c1635b4532daaaa57331c6286145b9 to your computer and use it in GitHub Desktop.
List of the language I use, yet;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GH api is so annoying. It might show partial data. | |
// The structure is; | |
// [[language name, _, percent in total],,,] | |
await fetch('https://api.github.com/users/LeaveNhA/repos?per_page=1000') | |
.then(r => r.json()) | |
.then(rs => rs.map(r => r.languages_url)) | |
.then(rs => rs.map(async (r) => (await (await fetch(r)).json()))) | |
.then(lrs => Promise.all(lrs)) | |
.then(ls => ls.filter(l => !l.hasOwnProperty('message'))) | |
.then(ls => ls.map(l => Object.entries(l))) | |
.then(lrs => lrs.reduce((acc, l) => [...acc, ...l], [])) | |
.then(la => la.reduce((acc, l) => (acc.hasOwnProperty(l[0]) ? {...acc, [l[0]]: acc[l[0]] + l[1]} : {...acc, [l[0]]: l[1]} ), {})) | |
.then(lo => Object.entries(lo)) | |
.then(les => les.filter(([languageName]) => languageName != 'HTML')) | |
.then(les => les.sort(([, l1], [, l2]) => l1 === l2 ? 0 : (l1 > l2 ? 1 : -1))) | |
.then(ls => [ls.reduce((a, [, b]) => a+b, 0), ls]) | |
.then(([total, ls]) => ls.map(l => [...l, (l[1] / total).toFixed(4)])) | |
.then(lsa => lsa.sort(([, l1], [, l2]) => l1 === l2 ? 0 : (l1 > l2 ? 1 : -1))) | |
.then(a => a.reverse()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HTML is like an unwanted child, you have it but you want to keep it in it's room when you want to show-off;
Also, percents are fixed to be 4 digits, not 2. Yet, it's fine.