|
1 | | -const cache = new (require('./cache').ApiCache)(); |
| 1 | +const cache = require('./cache').cache; |
2 | 2 |
|
3 | | -const store_units = ["b", "KiB", "MiB", "GiB", "TiB", "PiB"]; |
4 | | -const dec_units = ["", "k", "m"]; |
5 | | - |
6 | | -const lang_colors = { /** thanks, @anuraghazra's github-readme-stats **/ |
| 3 | +const colors = { /** thanks, @anuraghazra's github-readme-stats **/ |
7 | 4 | "1C Enterprise": "#814CCC", |
8 | 5 | "2-Dimensional Array": "#38761D", |
9 | 6 | "4D": "#004289", |
@@ -552,45 +549,6 @@ const lang_colors = { /** thanks, @anuraghazra's github-readme-stats **/ |
552 | 549 | "xBase": "#403a40" |
553 | 550 | } |
554 | 551 |
|
555 | | -function sort(arr) { |
556 | | - const len = arr.length - 1; |
557 | | - for (let i = 0; i <= len; i++) {for (let j = 0; j < len - i; j++) {if (arr[j] > arr[j + 1]) {[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]}}} |
558 | | - return arr |
559 | | -} |
560 | | - |
561 | | -function storeConvert(size, idx=0) { |
562 | | - if (size <= 0) { |
563 | | - return "0"; |
564 | | - } |
565 | | - while (idx < (store_units.length - 1) && size > 1024) { |
566 | | - size /= 1024; |
567 | | - idx ++; |
568 | | - } |
569 | | - return `${size.toFixed(1)} ${store_units[idx]}`; |
570 | | -} |
571 | | - |
572 | | -function decConvert(n, allowed_pre=true) { |
573 | | - let idx = 0; |
574 | | - let condition = allowed_pre ? 100 : 1000; |
575 | | - while (idx < (dec_units.length - 1) && n > condition) { n /= 1000 ; idx ++ } |
576 | | - return idx === 0 ? n : n.toFixed(1) + dec_units[idx]; |
577 | | -} |
578 | | - |
579 | | -function sum(arr) { |
580 | | - switch (arr.length) { |
581 | | - case 0 : |
582 | | - return 0; |
583 | | - case 1: |
584 | | - return arr[0]; |
585 | | - default: |
586 | | - return arr.reduce((a, b) => a + b); |
587 | | - } |
588 | | -} |
589 | | - |
590 | | -async function getLanguage(user, repo) { |
591 | | - return await cache.requestWithCache(`/repos/${user}/${repo}/languages`); |
592 | | -} |
593 | | - |
594 | 552 | async function langStatistics(queue) { |
595 | 553 | const res = {}; |
596 | 554 | for (const idx in queue) { |
@@ -622,7 +580,7 @@ function langHandler(langs) { |
622 | 580 | cursor += ratio; |
623 | 581 | return { |
624 | 582 | name: lang, |
625 | | - color: lang_colors[lang], |
| 583 | + color: colors[lang], |
626 | 584 | cursor: cursor - ratio, |
627 | 585 | ratio: ratio, |
628 | 586 | text: `${lang} ${(ratio * 100).toFixed(0)}% (${decConvert(key, false)})`, |
@@ -662,7 +620,7 @@ async function getRepository(username, repo, dark=false) { |
662 | 620 | stars: decConvert(res['stargazers_count']), |
663 | 621 | watchers: decConvert(res['watchers_count']), |
664 | 622 | license: license ? license['spdx_id'] : "Empty", |
665 | | - color: lang_colors[res['language']], |
| 623 | + color: colors[res['language']], |
666 | 624 | langs: langHandler(await getLanguage(username, repo)), |
667 | 625 | }; |
668 | 626 | } |
|
0 commit comments