Skip to content

Commit

Permalink
fix: hide parameter array implementation (anuraghazra#162)
Browse files Browse the repository at this point in the history
* fix: hide paramter array implementation

* chore: parseArray str check

* docs: updated readme

* chore: add codecov threshold

* docs: update docs
  • Loading branch information
anuraghazra authored Jul 23, 2020
1 parent c2adcfd commit aa44bd7
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require("dotenv").config();
const {
renderError,
parseBoolean,
parseJSON,
parseArray,
clampValue,
CONSTANTS,
} = require("../src/utils");
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions api/top-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {
renderError,
clampValue,
parseBoolean,
parseJSON,
parseArray,
CONSTANTS,
} = require("../src/utils");
const fetchTopLanguages = require("../src/fetchTopLanguages");
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ coverage:
range: "70...100"

status:
project:
default:
threshold: 5
patch: false
44 changes: 22 additions & 22 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
11 changes: 4 additions & 7 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -141,7 +138,7 @@ module.exports = {
encodeHTML,
isValidHexColor,
request,
parseJSON,
parseArray,
parseBoolean,
fallbackColor,
FlexLayout,
Expand Down
2 changes: 1 addition & 1 deletion tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/renderStatsCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit aa44bd7

Please sign in to comment.