fix: langs_count overflow when hide is set (#989)

This commit is contained in:
Florian Bussmann
2021-05-06 21:01:04 +02:00
committed by GitHub
parent 7a096acf66
commit f8b0c8767e
5 changed files with 27 additions and 21 deletions
+7 -3
View File
@@ -1,5 +1,5 @@
const Card = require("../common/Card");
const { getCardColors, FlexLayout } = require("../common/utils");
const { clampValue, getCardColors, FlexLayout } = require("../common/utils");
const { createProgressNode } = require("../common/createProgressNode");
const { langCardLocales } = require("../translations");
const I18n = require("../common/I18n");
@@ -73,8 +73,9 @@ const renderTopLanguages = (topLangs, options = {}) => {
layout,
custom_title,
locale,
langs_count = 5,
border_radius,
border_color,
border_color
} = options;
const i18n = new I18n({
@@ -85,6 +86,8 @@ const renderTopLanguages = (topLangs, options = {}) => {
let langs = Object.values(topLangs);
let langsToHide = {};
langsCount = clampValue(parseInt(langs_count), 1, 10);
// populate langsToHide map for quick lookup
// while filtering out
if (hide) {
@@ -98,7 +101,8 @@ const renderTopLanguages = (topLangs, options = {}) => {
.sort((a, b) => b.size - a.size)
.filter((lang) => {
return !langsToHide[lowercaseTrim(lang.name)];
});
})
.slice(0, langsCount);
const totalLanguageSize = langs.reduce((acc, curr) => {
return acc + curr.size;
-4
View File
@@ -36,13 +36,10 @@ const fetcher = (variables, token) => {
async function fetchTopLanguages(
username,
langsCount = 5,
exclude_repo = [],
hide = [],
) {
if (!username) throw Error("Invalid username");
langsCount = parseInt(langsCount) + hide.length;
langsCount = clampValue(langsCount, 1, 10 + hide.length);
const res = await retryer(fetcher, { login: username });
@@ -97,7 +94,6 @@ async function fetchTopLanguages(
const topLangs = Object.keys(repoNodes)
.sort((a, b) => repoNodes[b].size - repoNodes[a].size)
.slice(0, langsCount)
.reduce((result, key) => {
result[key] = repoNodes[key];
return result;