fix: hide parameter array implementation (#162)

* fix: hide paramter array implementation

* chore: parseArray str check

* docs: updated readme

* chore: add codecov threshold

* docs: update docs
This commit is contained in:
Anurag Hazra 2020-07-23 21:01:23 +05:30 committed by GitHub
parent c2adcfd6fe
commit aa44bd7615
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 35 deletions

View File

@ -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),

View File

@ -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,

View File

@ -7,4 +7,7 @@ coverage:
range: "70...100"
status:
project:
default:
threshold: 5
patch: false

View File

@ -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
@ -98,13 +98,13 @@ 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 | 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 |
@ -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

View File

@ -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,

View File

@ -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,

View File

@ -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(