diff --git a/api/index.js b/api/index.js index 2939bba4..f1ad48b6 100644 --- a/api/index.js +++ b/api/index.js @@ -2,7 +2,7 @@ require("dotenv").config(); const { renderError, parseBoolean, - parseJSON, + parseArray, clampValue, CONSTANTS, } = require("../src/utils"); @@ -45,7 +45,7 @@ module.exports = async (req, res) => { res.send( renderStatsCard(stats, { - hide: parseJSON(hide), + hide: parseArray(hide), show_icons: parseBoolean(show_icons), hide_title: parseBoolean(hide_title), hide_border: parseBoolean(hide_border), diff --git a/api/top-langs.js b/api/top-langs.js index f0db2af5..23fddbcc 100644 --- a/api/top-langs.js +++ b/api/top-langs.js @@ -3,7 +3,7 @@ const { renderError, clampValue, parseBoolean, - parseJSON, + parseArray, CONSTANTS, } = require("../src/utils"); const fetchTopLanguages = require("../src/fetchTopLanguages"); @@ -44,7 +44,7 @@ module.exports = async (req, res) => { theme, hide_title: parseBoolean(hide_title), card_width: parseInt(card_width, 10), - hide: parseJSON(hide), + hide: parseArray(hide), title_color, text_color, bg_color, diff --git a/codecov.yml b/codecov.yml index 19bd22df..da46f730 100644 --- a/codecov.yml +++ b/codecov.yml @@ -7,4 +7,7 @@ coverage: range: "70...100" status: + project: + default: + threshold: 5 patch: false diff --git a/readme.md b/readme.md index 51f57e09..54ae5f23 100644 --- a/readme.md +++ b/readme.md @@ -57,12 +57,12 @@ _Note: Ranks are calculated based on user's stats, see [src/calculateRank.js](./ ### Hiding individual stats -To hide any specific stats, you can pass a query parameter `?hide=` with an array of items you wanna hide. +To hide any specific stats, you can pass a query parameter `?hide=` with comma seperated values. -> Options: `&hide=["stars","commits","prs","issues","contribs"]` +> Options: `&hide=stars,commits,prs,issues,contribs` ```md -![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=["contribs","prs"]) +![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=contribs,prs]) ``` ### Showing icons @@ -97,21 +97,21 @@ You can customize the appearance of your `Stats Card` or `Repo Card` however you Customization Options: -| Option | type | description | Stats Card (default) | Repo Card (default) | Top Lang Card (default) | -| ------------- | ---------- | -------------------------------------- | -------------------- | ------------------- | ----------------------- | -| title_color | hex color | title color | 2f80ed | 2f80ed | 2f80ed | -| text_color | hex color | body color | 333 | 333 | 333 | -| icon_color | hex color | icon color | 4c71f2 | 586069 | 586069 | -| bg_color | hex color | card bg color | FFFEFE | FFFEFE | FFFEFE | -| line_height | number | control the line-height between text | 30 | N/A | N/A | -| hide | JSON array | hides the items specified on the array | [] | N/A | [] | -| hide_rank | boolean | hides the ranking | false | N/A | N/A | -| hide_title | boolean | hides the stats title | false | N/A | false | -| hide_border | boolean | hides the stats card border | false | N/A | N/A | -| show_owner | boolean | shows owner name in repo card | N/A | false | N/A | -| show_icons | boolean | shows icons | false | N/A | N/A | -| theme | string | sets inbuilt theme | 'default' | 'default_repocard' | 'default | -| cache_seconds | number | manually set custom cache control | 1800 | 1800 | '1800' | +| Option | type | description | Stats Card (default) | Repo Card (default) | Top Lang Card (default) | +| ------------- | --------- | ------------------------------------ | -------------------- | ------------------- | ----------------------- | +| title_color | hex color | title color | 2f80ed | 2f80ed | 2f80ed | +| text_color | hex color | body color | 333 | 333 | 333 | +| icon_color | hex color | icon color | 4c71f2 | 586069 | 586069 | +| bg_color | hex color | card bg color | FFFEFE | FFFEFE | FFFEFE | +| line_height | number | control the line-height between text | 30 | N/A | N/A | +| hide | CSV | hides the items specified | undefined | N/A | undefined | +| hide_rank | boolean | hides the ranking | false | N/A | N/A | +| hide_title | boolean | hides the stats title | false | N/A | false | +| hide_border | boolean | hides the stats card border | false | N/A | N/A | +| show_owner | boolean | shows owner name in repo card | N/A | false | N/A | +| show_icons | boolean | shows icons | false | N/A | N/A | +| theme | string | sets inbuilt theme | 'default' | 'default_repocard' | 'default | +| cache_seconds | number | manually set custom cache control | 1800 | 1800 | '1800' | > Note on cache: Repo cards have default cache of 30mins (1800 seconds) if the fork count & star count is less than 1k otherwise it's 2hours (7200). Also note that cache is clamped to minimum of 30min and maximum of 24hours @@ -157,10 +157,10 @@ Endpoint: `api/top-langs?username=anuraghazra` ### Hide individual languages -You can use `?hide=["language1","language2"]` parameter to hide languages below a specified threshold percentage. +You can use `?hide=language1,language2` parameter to hide individual languages. ```md -[![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra&hide=["javascript","html"])](https://github.com/anuraghazra/github-readme-stats) +[![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra&hide=javascript,html])](https://github.com/anuraghazra/github-readme-stats) ``` ### Demo @@ -177,11 +177,11 @@ You can use `?hide=["language1","language2"]` parameter to hide languages below - Hiding specific stats -![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=["contribs","issues"]) +![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=contribs,issues]) - Showing icons -![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=["issues"]&show_icons=true) +![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=issues&show_icons=true) - Themes diff --git a/src/utils.js b/src/utils.js index 38ad27f6..465b4dac 100644 --- a/src/utils.js +++ b/src/utils.js @@ -44,12 +44,9 @@ function parseBoolean(value) { } } -function parseJSON(str) { - try { - return JSON.parse(str); - } catch (err) { - return []; - } +function parseArray(str) { + if (!str) return []; + return str.split(","); } function clampValue(number, min, max) { @@ -141,7 +138,7 @@ module.exports = { encodeHTML, isValidHexColor, request, - parseJSON, + parseArray, parseBoolean, fallbackColor, FlexLayout, diff --git a/tests/api.test.js b/tests/api.test.js index 4f0be8fb..a9a640b1 100644 --- a/tests/api.test.js +++ b/tests/api.test.js @@ -98,7 +98,7 @@ describe("Test /api/", () => { const { req, res } = faker( { username: "anuraghazra", - hide: `["issues","prs","contribs"]`, + hide: "issues,prs,contribs", show_icons: true, hide_border: true, line_height: 100, diff --git a/tests/renderStatsCard.test.js b/tests/renderStatsCard.test.js index 06c32308..eaec45fb 100644 --- a/tests/renderStatsCard.test.js +++ b/tests/renderStatsCard.test.js @@ -55,7 +55,7 @@ describe("Test renderStatsCard", () => { it("should hide individual stats", () => { document.body.innerHTML = renderStatsCard(stats, { - hide: "['issues', 'prs', 'contribs']", + hide: ["issues", "prs", "contribs"], }); expect(