From 64b8eb903538eb691626428f19f52024b0d8d9ca Mon Sep 17 00:00:00 2001 From: Chongyi Zheng Date: Mon, 4 Mar 2024 22:27:18 -0500 Subject: [PATCH] [pull] master from anuraghazra:master (#35) * docs(contributing guidelines): remove duplicate license section (#3333) * refactor: fix typo in TRY_AGAIN_LATER constant name (#3274) * docs: add available locales section (#3331) * docs: add available locales section * dev * docs: remove broken sponsor links (#3336) solves: #3334 Removed broken "Supported by" links in documentation * CI: Add static code analysis workflow (CodeQL) (#2918) * infra: enable no-with eslint rule (#3233) * infra: enable no-multiple-empty-lines eslint rule (#3262) * docs: fix relative README links (#3067) --------- Co-authored-by: Alexandr Garbuzov Co-authored-by: Vishal Sharma <106011641+vishal-sharma-369@users.noreply.github.com> Co-authored-by: Rick Staa --- .eslintrc.json | 25 ++-- .github/workflows/ossf-analysis.yml | 1 + readme.md | 222 ++++++++++------------------ src/common/utils.js | 119 +++++---------- 4 files changed, 126 insertions(+), 241 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index cb584b9b1a3b56..d2908870fc7cf7 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -98,8 +98,8 @@ "terms": [ "TODO", "FIXME" ], "location": "start" }], - "no-with": "warn", - "radix": "warn", + // "no-with": "warn", + // "radix": "warn", // "vars-on-top": "error", // Enforces the style of wrapped functions @@ -113,7 +113,7 @@ // "init-declarations": [ "error", "always" ], // "no-catch-shadow": "warn", - "no-delete-var": "error", + // "no-delete-var": "error", // "no-label-var": "error", // "no-shadow-restricted-names": "error", // "no-shadow": "warn", @@ -150,12 +150,12 @@ // "arrow-body-style": [ "error", "always" ], // "arrow-parens": [ "error", "always" ], // "arrow-spacing": [ "error", { "before": true, "after": true }], - "constructor-super": "error", + // "constructor-super": "error", // "generator-star-spacing": [ "error", "before" ], // "no-arrow-condition": "error", - "no-class-assign": "error", - "no-const-assign": "error", - "no-dupe-class-members": "error", + // "no-class-assign": "error", + // "no-const-assign": "error", + // "no-dupe-class-members": "error", "no-this-before-super": "error", // "no-var": "warn", "object-shorthand": [ "warn" ], @@ -193,9 +193,9 @@ // "no-continue": "off", // "no-inline-comments": "off", // "no-lonely-if": "warn", - "no-mixed-spaces-and-tabs": "warn", - "no-multiple-empty-lines": "warn", - "no-negated-condition": "warn", + // "no-mixed-spaces-and-tabs": "warn", + // "no-multiple-empty-lines": "warn", + // "no-negated-condition": "off", // "no-nested-ternary": "warn", // "no-new-object": "warn", // "no-plusplus": "off", @@ -217,13 +217,14 @@ "MethodDefinition": true, "ClassDeclaration": false } - }], + }] // "semi-spacing": [ "warn", { "before": false, "after": true }], // "semi": [ "error", "always" ], // "sort-vars": "off", - "keyword-spacing": ["error", { "before": true, "after": true }] + // "space-after-keywords": [ "warn", "always" ], // "space-before-blocks": [ "warn", "always" ], // "space-before-function-paren": [ "warn", "never" ], + // "space-before-keywords": [ "warn", "always" ], // "space-in-parens": [ "warn", "never" ], // "space-infix-ops": [ "warn", { "int32Hint": true } ], // "space-return-throw-case": "error", diff --git a/.github/workflows/ossf-analysis.yml b/.github/workflows/ossf-analysis.yml index 180bf8926d3272..cb31e1f299313d 100644 --- a/.github/workflows/ossf-analysis.yml +++ b/.github/workflows/ossf-analysis.yml @@ -11,6 +11,7 @@ permissions: read-all jobs: analysis: + if: github.repository == 'anuraghazra/github-readme-stats' name: Scorecard analysis runs-on: ubuntu-latest permissions: diff --git a/readme.md b/readme.md index 363b008b2f8c2a..643499b09250fd 100644 --- a/readme.md +++ b/readme.md @@ -65,7 +65,7 @@

-

Please note that documentation translations may be outdated; try to use English documentation if possible.

+

Please note that documentation translations may be outdated, try to use english documentation if possible.

Love the project? Please consider donating to help it improve!

@@ -73,11 +73,11 @@ Give india logo -Are you considering supporting the project by donating to me? Please DO NOT!!! +Are you considering supporting the project by donating to me? Please DO NOT!! Picture of Coromandel Express train tragedy -India has recently suffered one of the most devastating train accidents, and your help will be immensely valuable for the people who were affected by this tragedy. +India just suffered one of the most devastating train accident and your help will be immensely valuable for the people who were affected by this tragedy. Please visit [this link](https://give.do/fundraisers/stand-beside-the-victims-of-the-coromandel-express-train-tragedy-in-odisha-donate-now) and make a small donation to help the people in need. A small donation goes a long way. :heart: @@ -109,7 +109,7 @@ Please visit [this link](https://give.do/fundraisers/stand-beside-the-victims-of - [Pie Chart Language Card Layout](#pie-chart-language-card-layout) - [Hide Progress Bars](#hide-progress-bars) - [Demo](#demo-2) -- [WakaTime Stats Card](#wakatime-stats-card) +- [Wakatime Stats Card](#wakatime-stats-card) - [Demo](#demo-3) - [All Demos](#all-demos) - [Quick Tip (Align The Cards)](#quick-tip-align-the-cards) @@ -121,19 +121,14 @@ Please visit [this link](https://give.do/fundraisers/stand-beside-the-victims-of - [Keep your fork up to date](#keep-your-fork-up-to-date) - [:sparkling\_heart: Support the project](#sparkling_heart-support-the-project) -# Important Notices +# Important Notice > [!IMPORTANT]\ > Since the GitHub API only [allows 5k requests per hour per user account](https://docs.github.com/en/graphql/overview/resource-limitations), the public Vercel instance hosted on `https://github-readme-stats.vercel.app/api` could possibly hit the rate limiter (see [#1471](https://github.com/anuraghazra/github-readme-stats/issues/1471)). We use caching to prevent this from happening (see https://github.com/anuraghazra/github-readme-stats#common-options). You can turn off these rate limit protections by deploying [your own Vercel instance](#disable-rate-limit-protections). -Uptime Badge - -> [!IMPORTANT]\ -> We're a small team, and to prioritize, we rely on upvotes :+1:. We use the Top Issues dashboard for tracking community demand (see [#1935](https://github.com/anuraghazra/github-readme-stats/issues/1935)). Do not hesitate to upvote the issues and pull requests you are interested in. We will work on the most upvoted first. - # GitHub Stats Card -Copy and paste this into your markdown, and that's it. Simple! +Copy-paste this into your markdown content, and that is it. Simple! Change the `?username=` value to your GitHub username. @@ -142,10 +137,10 @@ Change the `?username=` value to your GitHub username. ``` > [!WARNING]\ -> By default, the stats card only shows statistics like stars, commits, and pull requests from public repositories. To show private statistics on the stats card, you should [deploy your own instance](#deploy-on-your-own) using your own GitHub API token. +> By default, the stats card only shows statistics like stars, commits and pull requests from public repositories. To show private statistics on the stats card, you should [deploy your own instance](#deploy-on-your-own) using your own GitHub API token. > [!NOTE]\ -> Available ranks are S (top 1%), A+ (12.5%), A (25%), A- (37.5%), B+ (50%), B (62.5%), B- (75%), C+ (87.5%) and C (everyone). This ranking scheme is based on the [Japanese academic grading](https://wikipedia.org/wiki/Academic_grading_in_Japan) system. The global percentile is calculated as a weighted sum of percentiles for each statistic (number of commits, pull requests, reviews, issues, stars, and followers), based on the cumulative distribution function of the [exponential](https://wikipedia.org/wiki/exponential_distribution) and the [log-normal](https://wikipedia.org/wiki/Log-normal_distribution) distributions. The implementation can be investigated at [src/calculateRank.js](https://github.com/anuraghazra/github-readme-stats/blob/master/src/calculateRank.js). The circle around the rank shows 100 minus the global percentile. +> Available ranks are S (top 1%), A+ (12.5%), A (25%), A- (37.5%), B+ (50%), B (62.5%), B- (75%), C+ (87.5%) and C (everyone). This ranking scheme is based on the [Japanese academic grading](https://wikipedia.org/wiki/Academic_grading_in_Japan) system. The global percentile is calculated as a weighted sum of percentiles for each statistic (number of commits, pull requests, reviews, issues, stars and followers), based on the cumulative distribution function of the [exponential](https://wikipedia.org/wiki/exponential_distribution) and the [log-normal](https://wikipedia.org/wiki/Log-normal_distribution) distributions. The implementation can be investigated at [src/calculateRank.js](./src/calculateRank.js). The circle around the rank shows 100 minus the global percentile. ### Hiding individual stats @@ -191,7 +186,7 @@ GitHub Readme Stats comes with several built-in themes (e.g. `dark`, `radical`, GitHub Readme Stats Themes -You can look at a preview for [all available themes](themes/README.md) or checkout the [theme config file](themes/index.js). Please note that we paused the addition of new themes to decrease maintenance efforts; all pull requests related to new themes will be closed. +You can look at a preview for [all available themes](./themes/README.md) or checkout the [theme config file](./themes/index.js). You can also contribute new themes if you like, contributing guidelines can be found [here](./CONTRIBUTING.md#themes-contribution). #### Responsive Card Theme @@ -217,7 +212,7 @@ We have included a `transparent` theme that has a transparent background. This t ##### Add transparent alpha channel to a themes bg\_color -You can use the `bg_color` parameter to make any of [the available themes](themes/README.md) transparent. This is done by setting the `bg_color` to a color with a transparent alpha channel (i.e. `bg_color=00000000`): +You can use the `bg_color` parameter to make any of [the available themes](./themes/README.md) transparent. This is done by setting the `bg_color` to a color with a transparent alpha channel (i.e. `bg_color=00000000`): ```md ![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&bg_color=00000000) @@ -288,18 +283,16 @@ You can customize the appearance of all your cards however you wish with URL par #### Common Options -| Name | Description | Type | Default value | -| --- | --- | --- | --- | -| `title_color` | Card's title color. | string (hex color) | `2f80ed` | -| `text_color` | Body text color. | string (hex color) | `434d58` | -| `icon_color` | Icons color if available. | string (hex color) | `4c71f2` | -| `border_color` | Card's border color. Does not apply when `hide_border` is enabled. | string (hex color) | `e4e2e2` | -| `bg_color` | Card's background color. | string (hex color or a gradient in the form of *angle,start,end*) | `fffefe` | -| `hide_border` | Hides the card's border. | boolean | `false` | -| `theme` | Name of the theme, choose from [all available themes](themes/README.md). | enum | `default` | -| `cache_seconds` | Sets the cache header manually (min: 21600, max: 86400). | integer | `21600` | -| `locale` | Sets the language in the card, you can check full list of available locales [here](#available-locales). | enum | `en` | -| `border_radius` | Corner rounding on the card. | number | `4.5` | +* `title_color` - Card's title color *(hex color)*. Default: `2f80ed`. +* `text_color` - Body text color *(hex color)*. Default: `434d58`. +* `icon_color` - Icons color if available *(hex color)*. Default: `4c71f2`. +* `border_color` - Card's border color *(hex color)*. Default: `e4e2e2` (Does not apply when `hide_border` is enabled). +* `bg_color` - Card's background color *(hex color)* **or** a gradient in the form of *angle,start,end*. Default: `fffefe` +* `hide_border` - Hides the card's border *(boolean)*. Default: `false` +* `theme` - Name of the theme, choose from [all available themes](./themes/README.md). Default: `default` theme. +* `cache_seconds` - Sets the cache header manually *(min: 21600, max: 86400)*. Default: `21600 seconds (6 hours)`. +* `locale` - Sets the language in the card *(e.g. cn, de, es, etc.)*. Default: `en`. +* `border_radius` - Corner rounding on the card. Default: `4.5`. > [!WARNING]\ > We use caching to decrease the load on our servers (see ). Our cards have a default cache of 6 hours (21600 seconds). Also, note that the cache is clamped to a minimum of 6 hours and a maximum of 24 hours. If you want the data on your statistics card to be updated more often you can [deploy your own instance](#deploy-on-your-own) and set [environment variable](#disable-rate-limit-protections) `CACHE_SECONDS` to a value of your choosing. @@ -310,131 +303,64 @@ You can provide multiple comma-separated values in the bg\_color option to rende &bg_color=DEG,COLOR1,COLOR2,COLOR3...COLOR10 -##### Available locales - -Here is a list of all available locales: - - - -
- -| Code | Locale | -| --- | --- | -| `cn` | Chinese | -| `zh-tw` | Chinese (Taiwan) | -| `ar` | Arabic | -| `cs` | Czech | -| `de` | German | -| `en` | English | -| `bn` | Bengali | -| `es` | Spanish | -| `fr` | French | -| `hu` | Hungarian | - - - -| Code | Locale | -| --- | --- | -| `it` | Italian | -| `ja` | Japanese | -| `kr` | Korean | -| `nl` | Dutch | -| `pt-pt` | Portuguese (Portugal) | -| `pt-br` | Portuguese (Brazil) | -| `np` | Nepali | -| `el` | Greek | -| `ru` | Russian | -| `uk-ua` | Ukrainian | - - - -| Code | Locale | -| --- | --- | -| `id` | Indonesian | -| `ml` | Malayalam | -| `my` | Burmese | -| `sk` | Slovak | -| `tr` | Turkish | -| `pl` | Polish | -| `uz` | Uzbek | -| `vi` | Vietnamese | -| `se` | Swedish | - -
- -If we don't support your language, please consider contributing! You can find more information about how to do it in our [contributing guidelines](CONTRIBUTING.md#translations-contribution). - #### Stats Card Exclusive Options -| Name | Description | Type | Default value | -| --- | --- | --- | --- | -| `hide` | Hides the [specified items](#hiding-individual-stats) from stats. | string (comma-separated values) | `null` | -| `hide_title` | Hides the title of your stats card. | boolean | `false` | -| `card_width` | Sets the card's width manually. | number | `500px (approx.)` | -| `hide_rank` | Hides the rank and automatically resizes the card width. | boolean | `false` | -| `rank_icon` | Shows alternative rank icon (i.e. `github`, `percentile` or `default`). | enum | `default` | -| `show_icons` | Shows icons near all stats. | boolean | `false` | -| `include_all_commits` | Count total commits instead of just the current year commits. | boolean | `false` | -| `line_height` | Sets the line height between text. | integer | `25` | -| `exclude_repo` | Excludes specified repositories. | string (comma-separated values) | `null` | -| `custom_title` | Sets a custom title for the card. | string | ` GitHub Stats` | -| `text_bold` | Uses bold text. | boolean | `true` | -| `disable_animations` | Disables all animations in the card. | boolean | `false` | -| `ring_color` | Color of the rank circle. | string (hex color) | `2f80ed` | -| `number_format` | Switches between two available formats for displaying the card values `short` (i.e. `6.6k`) and `long` (i.e. `6626`). | enum | `short` | -| `show` | Shows [additional items](#showing-additional-individual-stats) on stats card (i.e. `reviews`, `discussions_started`, `discussions_answered`, `prs_merged` or `prs_merged_percentage`). | string (comma-separated values) | `null` | +* `hide` - Hides the [specified items](#hiding-individual-stats) from stats *(Comma-separated values)*. Default: `[] (blank array)`. +* `hide_title` - *(boolean)*. Default: `false`. +* `card_width` - Sets the card's width manually *(number)*. Default: `500px (approx.)`. +* `hide_rank` - *(boolean)* hides the rank and automatically resizes the card width. Default: `false`. +* `rank_icon` - Shows alternative rank icon (i.e. `github`, `percentile` or `default`). Default: `default`. +* `show_icons` - *(boolean)*. Default: `false`. +* `include_all_commits` - Counts total commits instead of just the current year commits *(boolean)*. Default: `false`. +* `line_height` - Sets the line height between text *(number)*. Default: `25`. +* `exclude_repo` - Excludes stars from specified repositories *(Comma-separated values)*. Default: `[] (blank array)`. +* `custom_title` - Sets a custom title for the card. Default: ` GitHub Stats`. +* `text_bold` - Uses bold text *(boolean)*. Default: `true`. +* `disable_animations` - Disables all animations in the card *(boolean)*. Default: `false`. +* `ring_color` - Color of the rank circle *(hex color)*. Defaults to the theme ring color if it exists and otherwise the title color. +* `number_format` - Switches between two available formats for displaying the card values `short` (i.e. `6.6k`) and `long` (i.e. `6626`). Default: `short`. +* `show` - Shows [additional items](#showing-additional-individual-stats) on stats card (i.e. `reviews`, `discussions_started`, `discussions_answered`, `prs_merged` or `prs_merged_percentage`) *(Comma-separated values)*. Default: `[] (blank array)`. > [!NOTE]\ > When hide\_rank=`true`, the minimum card width is 270 px + the title length and padding. #### Repo Card Exclusive Options -| Name | Description | Type | Default value | -| --- | --- | --- | --- | -| `show_owner` | Shows the repo's owner name. | boolean | `false` | -| `description_lines_count` | Manually set the number of lines for the description. Specified value will be clamped between 1 and 3. If this parameter is not specified, the number of lines will be automatically adjusted according to the actual length of the description. | number | `null` | +* `show_owner` - Shows the repo's owner name *(boolean)*. Default: `false`. #### Gist Card Exclusive Options -| Name | Description | Type | Default value | -| --- | --- | --- | --- | -| `show_owner` | Shows the gist's owner name. | boolean | `false` | +* `show_owner` - Shows the gist's owner name *(boolean)*. Default: `false`. #### Language Card Exclusive Options -| Name | Description | Type | Default value | -| --- | --- | --- | --- | -| `hide` | Hides the [specified languages](#hide-individual-languages) from card. | string (comma-separated values) | `null` | -| `hide_title` | Hides the title of your card. | boolean | `false` | -| `layout` | Switches between five available layouts `normal` & `compact` & `donut` & `donut-vertical` & `pie`. | enum | `normal` | -| `card_width` | Sets the card's width manually. | number | `300` | -| `langs_count` | Shows more languages on the card, between 1-20. | integer | `5` for `normal` and `donut`, `6` for other layouts | -| `exclude_repo` | Excludes specified repositories. | string (comma-separated values) | `null` | -| `custom_title` | Sets a custom title for the card. | string | `Most Used Languages` | -| `disable_animations` | Disables all animations in the card. | boolean | `false` | -| `hide_progress` | Uses the compact layout option, hides percentages, and removes the bars. | boolean | `false` | -| `size_weight` | Configures language stats algorithm (see [Language stats algorithm](#language-stats-algorithm)). | integer | `1` | -| `count_weight` | Configures language stats algorithm (see [Language stats algorithm](#language-stats-algorithm)). | integer | `0` | +* `hide` - Hides the languages specified from the card *(Comma-separated values)*. Default: `[] (blank array)`. +* `hide_title` - *(boolean)*. Default: `false`. +* `layout` - Switches between five available layouts `normal` & `compact` & `donut` & `donut-vertical` & `pie`. Default: `normal`. +* `card_width` - Sets the card's width manually *(number)*. Default `300`. +* `langs_count` - Shows more languages on the card, between 1-20 *(number)*. Default: `5` for `normal` and `donut`, `6` for other layouts. +* `exclude_repo` - Excludes specified repositories *(Comma-separated values)*. Default: `[] (blank array)`. +* `custom_title` - Sets a custom title for the card *(string)*. Default `Most Used Languages`. +* `disable_animations` - Disables all animations in the card *(boolean)*. Default: `false`. +* `hide_progress` - Uses the compact layout option, hides percentages, and removes the bars. Default: `false`. +* `size_weight` - Configures language stats algorithm *(number)* (see [Language stats algorithm](#Language-stats-algorithm)), defaults to 1. +* `count_weight` - Configures language stats algorithm *(number)* (see [Language stats algorithm](#Language-stats-algorithm)), defaults to 0. > [!WARNING]\ > Language names should be URI-escaped, as specified in [Percent Encoding](https://en.wikipedia.org/wiki/Percent-encoding) > (i.e: `c++` should become `c%2B%2B`, `jupyter notebook` should become `jupyter%20notebook`, etc.) You can use > [urlencoder.org](https://www.urlencoder.org/) to help you do this automatically. -#### WakaTime Card Exclusive Options - -| Name | Description | Type | Default value | -| --- | --- | --- | --- | -| `hide` | Hides the languages specified from the card. | string (comma-separated values) | `null` | -| `hide_title` | Hides the title of your card. | boolean | `false` | -| `line_height` | Sets the line height between text. | integer | `25` | -| `hide_progress` | Hides the progress bar and percentage. | boolean | `false` | -| `custom_title` | Sets a custom title for the card. | string | `WakaTime Stats` | -| `layout` | Switches between two available layouts `default` & `compact`. | enum | `default` | -| `langs_count` | Limits the number of languages on the card, defaults to all reported languages. | integer | `null` | -| `api_domain` | Sets a custom API domain for the card, e.g. to use services like [Hakatime](https://github.com/mujx/hakatime) or [Wakapi](https://github.com/muety/wakapi) | string | `wakatime.com` | -| `display_format` | Sets the WakaTime stats display format. Choose `time` to display time-based stats or `percent` to show percentages. | enum | `time` | -| `disable_animations` | Disables all animations in the card. | boolean | `false` | +#### Wakatime Card Exclusive Options + +* `hide` - Hides the languages specified from the card *(Comma-separated values)*. Default: `[] (blank array)`. +* `hide_title` - *(boolean)*. Default `false`. +* `line_height` - Sets the line height between text *(number)*. Default `25`. +* `hide_progress` - Hides the progress bar and percentage *(boolean)*. Default `false`. +* `custom_title` - Sets a custom title for the card *(string)*. Default `Wakatime Stats`. +* `layout` - Switches between two available layouts `default` & `compact`. Default `default`. +* `langs_count` - Limits the number of languages on the card, defaults to all reported languages *(number)*. +* `api_domain` - Sets a custom API domain for the card, e.g. to use services like [Hakatime](https://github.com/mujx/hakatime) or [Wakapi](https://github.com/muety/wakapi) *(string)*. Default `Waka API`. *** @@ -495,10 +421,10 @@ The top languages card shows a GitHub user's most frequently used languages. > Top Languages does not indicate the user's skill level or anything like that; it's a GitHub metric to determine which languages have the most code on GitHub. It is a new feature of github-readme-stats. > [!WARNING]\ -> This card shows language usage only inside your own non-forked repositories, not depending on who the author of the commits is. It does not include your contributions into another users/organizations repositories. Currently there are no way to get this data from GitHub API. If you want this behavior to be improved you can support [this feature request](https://github.com/orgs/community/discussions/18230) created by [@rickstaa](https://github.com/rickstaa) inside GitHub Community. +> This card shows languages usage only inside your own non-forked repositories, not depending from who is the author of the commits. It does not include your contributions into another users/organizations repositories. Currently there are no way to get this data from GitHub API. If you want this behavior to be improved you can support [this feature request](https://github.com/orgs/community/discussions/18230) created by [@rickstaa](https://github.com/rickstaa) inside GitHub Community. > [!WARNING]\ -> Currently this card shows data only about first 100 repositories. This is because GitHub API limitations which cause downtimes of public instances (see [#1471](https://github.com/anuraghazra/github-readme-stats/issues/1471)). In future this behavior will be improved by releasing GitHub action or providing environment variables for user's own instances. +> Currently this card shows data only about first 100 repositories. This is because GitHub API limitations which cause downtimes of public instance (see [#1471](https://github.com/anuraghazra/github-readme-stats/issues/1471)). In future this behavior will be improved by releasing GitHub action or providing environment variable for user's own instances. ### Usage @@ -616,26 +542,26 @@ You can use the `&hide_progress=true` option to hide the percentages and the pro ![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra\&hide_progress=true) -# WakaTime Stats Card +# Wakatime Stats Card > [!WARNING]\ -> Please be aware that we currently only show data from WakaTime profiles that are public. You therefore have to make sure that **BOTH** `Display code time publicly` and `Display languages, editors, os, categories publicly` are enabled. +> Please be aware that we currently only show data from Wakatime profiles that are public. You therefore have to make sure that **BOTH** `Display code time publicly` and `Display languages, editors, os, categories publicly` are enabled. -Change the `?username=` value to your [WakaTime](https://wakatime.com) username. +Change the `?username=` value to your [Wakatime](https://wakatime.com) username. ```md -[![Harlok's WakaTime stats](https://github-readme-stats.vercel.app/api/wakatime?username=ffflabs)](https://github.com/anuraghazra/github-readme-stats) +[![Harlok's wakatime stats](https://github-readme-stats.vercel.app/api/wakatime?username=ffflabs)](https://github.com/anuraghazra/github-readme-stats) ``` ### Demo -![Harlok's WakaTime stats](https://github-readme-stats.vercel.app/api/wakatime?username=ffflabs) +![Harlok's wakatime stats](https://github-readme-stats.vercel.app/api/wakatime?username=ffflabs) -![Harlok's WakaTime stats](https://github-readme-stats.vercel.app/api/wakatime?username=ffflabs\&hide_progress=true) +![Harlok's wakatime stats](https://github-readme-stats.vercel.app/api/wakatime?username=ffflabs\&hide_progress=true) * Compact layout -![Harlok's WakaTime stats](https://github-readme-stats.vercel.app/api/wakatime?username=ffflabs\&layout=compact) +![Harlok's wakatime stats](https://github-readme-stats.vercel.app/api/wakatime?username=ffflabs\&layout=compact) *** @@ -709,7 +635,7 @@ Choose from any of the [default themes](#themes) * WakaTime card -![Harlok's WakaTime stats](https://github-readme-stats.vercel.app/api/wakatime?username=ffflabs) +![Harlok's wakatime stats](https://github-readme-stats.vercel.app/api/wakatime?username=ffflabs) *** @@ -768,7 +694,7 @@ Since the GitHub API only allows 5k requests per hour, my `https://github-readme > Since [#58](https://github.com/anuraghazra/github-readme-stats/pull/58), we should be able to handle more than 5k requests and have fewer issues with downtime :grin:. > [!NOTE]\ -> If you are on the [Pro (i.e. paid)](https://vercel.com/pricing) Vercel plan, the [maxDuration](https://vercel.com/docs/concepts/projects/project-configuration#value-definition) value found in the [vercel.json](https://github.com/anuraghazra/github-readme-stats/blob/master/vercel.json) can be increased when your Vercel instance frequently times out during the card request. You are advised to keep this value lower than `30` seconds to prevent high memory usage. +> If you are on the [Pro (i.e. paid)](https://vercel.com/pricing) Vercel plan, the [maxDuration](https://vercel.com/docs/concepts/projects/project-configuration#value-definition) value found in the [Vercel.json](https://github.com/anuraghazra/github-readme-stats/blob/master/vercel.json) can be increased when your Vercel instance frequently times out during the card request. You are advised to keep this value lower than `30` seconds to prevent high memory usage. [![Deploy to Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/anuraghazra/github-readme-stats) @@ -815,7 +741,7 @@ Since the GitHub API only allows 5k requests per hour, my `https://github-readme Github Readme Stats contains several Vercel environment variables that can be used to remove the rate limit protections: -* `CACHE_SECONDS`: This environment variable takes precedence over our cache minimum and maximum values and can circumvent these values for self-hosted Vercel instances. +* `CACHE_SECONDS`: This environment variable takes precedence over our cache minimum and maximum values and can circumvent these values for self Hosted Vercel instances. See [the Vercel documentation](https://vercel.com/docs/concepts/projects/environment-variables) on adding these environment variables to your Vercel instance. @@ -830,15 +756,15 @@ this takes time. You can use this service for free. However, if you are using this project and are happy with it or just want to encourage me to continue creating stuff, there are a few ways you can do it: -* Giving proper credit when you use github-readme-stats on your readme, linking back to it. :D -* Starring and sharing the project. :rocket: -* [![paypal.me/anuraghazra](https://ionicabizau.github.io/badges/paypal.svg)](https://www.paypal.me/anuraghazra) - You can make a one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea: +* Giving proper credit when you use github-readme-stats on your readme, linking back to it :D +* Starring and sharing the project :rocket: +* [![paypal.me/anuraghazra](https://ionicabizau.github.io/badges/paypal.svg)](https://www.paypal.me/anuraghazra) - You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea: Thanks! :heart: *** -[![https://vercel.com?utm\_source=github\_readme\_stats\_team\&utm\_campaign=oss](powered-by-vercel.svg)](https://vercel.com?utm_source=github_readme_stats_team\&utm_campaign=oss) +[![https://vercel.com?utm\_source=github\_readme\_stats\_team\&utm\_campaign=oss](./powered-by-vercel.svg)](https://vercel.com?utm_source=github_readme_stats_team\&utm_campaign=oss) Contributions are welcome! <3 diff --git a/src/common/utils.js b/src/common/utils.js index 48ea051783b7f6..f55e780adf4a66 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -177,7 +177,7 @@ const parseArray = (str) => { */ const clampValue = (number, min, max) => { // @ts-ignore - if (Number.isNaN(parseInt(number, 10))) { + if (Number.isNaN(parseInt(number))) { return min; } return Math.max(min, Math.min(number, max)); @@ -190,10 +190,7 @@ const clampValue = (number, min, max) => { * @returns {boolean} True if the given string is a valid gradient. */ const isValidGradient = (colors) => { - return ( - colors.length > 2 && - colors.slice(1).every((color) => isValidHexColor(color)) - ); + return isValidHexColor(colors[1]) && isValidHexColor(colors[2]); }; /** @@ -325,81 +322,6 @@ const getCardColors = ({ return { titleColor, iconColor, textColor, bgColor, borderColor, ringColor }; }; -// Script parameters. -const ERROR_CARD_LENGTH = 576.5; - -/** - * Encode string as HTML. - * - * @see https://stackoverflow.com/a/48073476/10629172 - * - * @param {string} str String to encode. - * @returns {string} Encoded string. - */ -const encodeHTML = (str) => { - return str - .replace(/[\u00A0-\u9999<>&](?!#)/gim, (i) => { - return "&#" + i.charCodeAt(0) + ";"; - }) - .replace(/\u0008/gim, ""); -}; - -const UPSTREAM_API_ERRORS = [ - TRY_AGAIN_LATER, - SECONDARY_ERROR_MESSAGES.MAX_RETRY, -]; - -/** - * Renders error message on the card. - * - * @param {string} message Main error message. - * @param {string} secondaryMessage The secondary error message. - * @param {object} options Function options. - * @returns {string} The SVG markup. - */ -const renderError = (message, secondaryMessage = "", options = {}) => { - const { - title_color, - text_color, - bg_color, - border_color, - theme = "default", - } = options; - - // returns theme based colors with proper overrides and defaults - const { titleColor, textColor, bgColor, borderColor } = getCardColors({ - title_color, - text_color, - icon_color: "", - bg_color, - border_color, - ring_color: "", - theme, - }); - - return ` - - - - Something went wrong!${ - UPSTREAM_API_ERRORS.includes(secondaryMessage) - ? "" - : " file an issue at https://tiny.one/readme-stats" - } - - ${encodeHTML(message)} - ${secondaryMessage} - - - `; -}; - /** * Split text over multiple lines based on the card width. * @@ -438,7 +360,7 @@ const wrapTextMultiline = (text, width = 59, maxLines = 3) => { const noop = () => {}; // return console instance based on the environment const logger = - process.env.NODE_ENV === "test" ? { log: noop, error: noop } : console; + process.env.NODE_ENV !== "test" ? console : { log: noop, error: noop }; const ONE_MINUTE = 60; const FIVE_MINUTES = 300; @@ -466,6 +388,41 @@ const CONSTANTS = { ERROR_CACHE_SECONDS: TEN_MINUTES, }; +const TRY_AGAING_LATER = "Please try again later"; + +const SECONDARY_ERROR_MESSAGES = { + MAX_RETRY: + "You can deploy own instance or wait until public will be no longer limited", + NO_TOKENS: + "Please add an env variable called PAT_1 with your GitHub API token in vercel", + USER_NOT_FOUND: "Make sure the provided username is not an organization", + GRAPHQL_ERROR: TRY_AGAING_LATER, + GITHUB_REST_API_ERROR: TRY_AGAING_LATER, + WAKATIME_USER_NOT_FOUND: "Make sure you have a public WakaTime profile", +}; + +/** + * Custom error class to handle custom GRS errors. + */ +class CustomError extends Error { + /** + * @param {string} message Error message. + * @param {string} type Error type. + */ + constructor(message, type) { + super(message); + this.type = type; + this.secondaryMessage = SECONDARY_ERROR_MESSAGES[type] || type; + } + + static MAX_RETRY = "MAX_RETRY"; + static NO_TOKENS = "NO_TOKENS"; + static USER_NOT_FOUND = "USER_NOT_FOUND"; + static GRAPHQL_ERROR = "GRAPHQL_ERROR"; + static GITHUB_REST_API_ERROR = "GITHUB_REST_API_ERROR"; + static WAKATIME_ERROR = "WAKATIME_ERROR"; +} + /** * Missing query parameter class. */