@stats-organization/github-readme-stats-core 2.1.4 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/api/gist.d.ts +2 -7
- package/build/api/gist.d.ts.map +1 -1
- package/build/api/gist.js +28 -26
- package/build/api/index.d.ts +3 -8
- package/build/api/index.d.ts.map +1 -1
- package/build/api/index.js +32 -36
- package/build/api/pin.d.ts +2 -7
- package/build/api/pin.d.ts.map +1 -1
- package/build/api/pin.js +18 -33
- package/build/api/top-langs.d.ts +2 -7
- package/build/api/top-langs.d.ts.map +1 -1
- package/build/api/top-langs.js +32 -44
- package/build/api/wakatime.d.ts +2 -7
- package/build/api/wakatime.d.ts.map +1 -1
- package/build/api/wakatime.js +28 -26
- package/build/calculateRank.d.ts +12 -11
- package/build/calculateRank.d.ts.map +1 -1
- package/build/calculateRank.js +18 -18
- package/build/cards/common-options.d.ts +13 -0
- package/build/cards/common-options.d.ts.map +1 -0
- package/build/cards/common-options.js +1 -0
- package/build/cards/gist.d.ts +11 -16
- package/build/cards/gist.d.ts.map +1 -1
- package/build/cards/gist.js +26 -31
- package/build/cards/repo.d.ts +19 -16
- package/build/cards/repo.d.ts.map +1 -1
- package/build/cards/repo.js +79 -72
- package/build/cards/stats.d.ts +29 -44
- package/build/cards/stats.d.ts.map +1 -1
- package/build/cards/stats.js +118 -173
- package/build/cards/top-languages.d.ts +81 -77
- package/build/cards/top-languages.d.ts.map +1 -1
- package/build/cards/top-languages.js +186 -184
- package/build/cards/wakatime.d.ts +21 -11
- package/build/cards/wakatime.d.ts.map +1 -1
- package/build/cards/wakatime.js +92 -109
- package/build/common/Card.d.ts +41 -14
- package/build/common/Card.d.ts.map +1 -1
- package/build/common/Card.js +92 -31
- package/build/common/I18n.d.ts +4 -2
- package/build/common/I18n.d.ts.map +1 -1
- package/build/common/color.d.ts +91 -15
- package/build/common/color.d.ts.map +1 -1
- package/build/common/color.js +163 -17
- package/build/common/config.d.ts +2 -1
- package/build/common/config.d.ts.map +1 -1
- package/build/common/config.js +16 -26
- package/build/common/constants.d.ts +2 -1
- package/build/common/constants.d.ts.map +1 -1
- package/build/common/date.d.ts +37 -0
- package/build/common/date.d.ts.map +1 -0
- package/build/common/date.js +31 -0
- package/build/common/html.js +1 -1
- package/build/common/http.d.ts +37 -5
- package/build/common/http.d.ts.map +1 -1
- package/build/common/http.js +29 -6
- package/build/common/icons.d.ts +1 -0
- package/build/common/icons.d.ts.map +1 -1
- package/build/common/icons.js +1 -0
- package/build/common/languageColors.d.ts +11 -0
- package/build/common/languageColors.d.ts.map +1 -0
- package/build/common/languageColors.js +15 -0
- package/build/common/languageColors.json +10 -1
- package/build/common/ops.d.ts +27 -33
- package/build/common/ops.d.ts.map +1 -1
- package/build/common/ops.js +31 -48
- package/build/common/render.d.ts +154 -113
- package/build/common/render.d.ts.map +1 -1
- package/build/common/render.js +209 -92
- package/build/common/retryer.d.ts +15 -6
- package/build/common/retryer.d.ts.map +1 -1
- package/build/common/retryer.js +2 -0
- package/build/fetchers/gist.d.ts +6 -21
- package/build/fetchers/gist.d.ts.map +1 -1
- package/build/fetchers/gist.js +28 -64
- package/build/fetchers/repo.d.ts +12 -11
- package/build/fetchers/repo.d.ts.map +1 -1
- package/build/fetchers/repo.js +27 -68
- package/build/fetchers/stats.d.ts +24 -17
- package/build/fetchers/stats.d.ts.map +1 -1
- package/build/fetchers/stats.js +302 -184
- package/build/fetchers/top-languages.d.ts +10 -15
- package/build/fetchers/top-languages.d.ts.map +1 -1
- package/build/fetchers/top-languages.js +52 -103
- package/build/fetchers/types.d.ts +130 -0
- package/build/fetchers/types.d.ts.map +1 -0
- package/build/fetchers/types.js +1 -0
- package/build/fetchers/wakatime.d.ts +9 -5
- package/build/fetchers/wakatime.d.ts.map +1 -1
- package/build/fetchers/wakatime.js +8 -4
- package/build/graphql/contributionsDocument.d.ts +18 -0
- package/build/graphql/contributionsDocument.d.ts.map +1 -0
- package/build/graphql/contributionsDocument.js +30 -0
- package/build/graphql/generated/common.d.ts +42 -0
- package/build/graphql/generated/common.d.ts.map +1 -0
- package/build/graphql/generated/common.js +2 -0
- package/build/graphql/generated/gist.d.ts +44 -0
- package/build/graphql/generated/gist.d.ts.map +1 -0
- package/build/graphql/generated/gist.js +27 -0
- package/build/graphql/generated/repo.d.ts +67 -0
- package/build/graphql/generated/repo.d.ts.map +1 -0
- package/build/graphql/generated/repo.js +30 -0
- package/build/graphql/generated/stats.d.ts +150 -0
- package/build/graphql/generated/stats.d.ts.map +1 -0
- package/build/graphql/generated/stats.js +95 -0
- package/build/graphql/generated/top-languages.d.ts +54 -0
- package/build/graphql/generated/top-languages.d.ts.map +1 -0
- package/build/graphql/generated/top-languages.js +27 -0
- package/build/graphql/graphqlDocument.d.ts +22 -0
- package/build/graphql/graphqlDocument.d.ts.map +1 -0
- package/build/graphql/graphqlDocument.js +8 -0
- package/build/graphql/reposContributedToDocument.d.ts +27 -0
- package/build/graphql/reposContributedToDocument.d.ts.map +1 -0
- package/build/graphql/reposContributedToDocument.js +59 -0
- package/build/index.d.ts +3 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -1
- package/build/themes/index.d.ts +32 -0
- package/build/themes/index.d.ts.map +1 -1
- package/build/themes/index.js +28 -0
- package/build/translations.d.ts +17 -0
- package/build/translations.d.ts.map +1 -1
- package/build/translations.js +17 -0
- package/package.json +14 -8
- package/src/_emoji-name-map.d.ts +10 -0
- package/src/_github-username-regex.d.ts +4 -0
- package/src/api/gist.js +31 -31
- package/src/api/index.js +40 -42
- package/src/api/pin.js +20 -38
- package/src/api/top-langs.js +36 -49
- package/src/api/wakatime.js +31 -31
- package/src/{calculateRank.js → calculateRank.ts} +29 -19
- package/src/cards/common-options.ts +13 -0
- package/src/cards/{gist.js → gist.ts} +37 -37
- package/src/cards/{repo.js → repo.ts} +107 -79
- package/src/cards/{stats.js → stats.ts} +173 -210
- package/src/cards/{top-languages.js → top-languages.ts} +325 -243
- package/src/cards/{wakatime.js → wakatime.ts} +158 -127
- package/src/common/Card.ts +123 -43
- package/src/common/I18n.ts +6 -2
- package/src/common/color.ts +240 -28
- package/src/common/config.ts +22 -29
- package/src/common/constants.ts +3 -1
- package/src/common/date.ts +45 -0
- package/src/common/html.ts +1 -1
- package/src/common/http.ts +71 -0
- package/src/common/icons.ts +1 -0
- package/src/common/languageColors.json +10 -1
- package/src/common/languageColors.ts +19 -0
- package/src/common/ops.ts +158 -0
- package/src/common/render.ts +652 -0
- package/src/common/retryer.ts +21 -12
- package/src/fetchers/gist.ts +79 -0
- package/src/fetchers/repo.ts +114 -0
- package/src/fetchers/stats.ts +743 -0
- package/src/fetchers/top-languages.ts +135 -0
- package/src/fetchers/{types.d.ts → types.ts} +28 -20
- package/src/fetchers/{wakatime.js → wakatime.ts} +19 -5
- package/src/graphql/contributionsDocument.ts +44 -0
- package/src/graphql/generated/common.ts +26 -0
- package/src/graphql/generated/gist.ts +59 -0
- package/src/graphql/generated/repo.ts +90 -0
- package/src/graphql/generated/stats.ts +194 -0
- package/src/graphql/generated/top-languages.ts +75 -0
- package/src/graphql/graphqlDocument.ts +25 -0
- package/src/graphql/queries/gist.graphql +25 -0
- package/src/graphql/queries/repo.graphql +28 -0
- package/src/graphql/queries/stats.graphql +120 -0
- package/src/graphql/queries/top-languages.graphql +34 -0
- package/src/graphql/reposContributedToDocument.ts +86 -0
- package/src/index.ts +3 -1
- package/src/themes/index.ts +33 -0
- package/src/translations.ts +17 -0
- package/src/cards/types.d.ts +0 -78
- package/src/common/http.js +0 -19
- package/src/common/ops.js +0 -170
- package/src/common/render.js +0 -440
- package/src/fetchers/gist.js +0 -112
- package/src/fetchers/repo.js +0 -161
- package/src/fetchers/stats.js +0 -474
- package/src/fetchers/top-languages.js +0 -175
- package/src/themes/README.md +0 -229
package/src/api/top-langs.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { renderTopLanguages } from "../cards/top-languages.js";
|
|
2
|
+
import { findInvalidColorParam, pickColorParams } from "../common/color.js";
|
|
2
3
|
import {
|
|
3
4
|
MissingParamError,
|
|
4
5
|
retrieveSecondaryMessage,
|
|
@@ -16,11 +17,6 @@ export default async (
|
|
|
16
17
|
hide_title,
|
|
17
18
|
hide_border,
|
|
18
19
|
card_width,
|
|
19
|
-
title_color,
|
|
20
|
-
text_color,
|
|
21
|
-
bg_color,
|
|
22
|
-
prog_bar_bg_color,
|
|
23
|
-
theme,
|
|
24
20
|
layout,
|
|
25
21
|
langs_count,
|
|
26
22
|
exclude_repo,
|
|
@@ -29,70 +25,76 @@ export default async (
|
|
|
29
25
|
custom_title,
|
|
30
26
|
locale,
|
|
31
27
|
border_radius,
|
|
32
|
-
border_color,
|
|
33
28
|
role,
|
|
34
29
|
disable_animations,
|
|
35
30
|
hide_progress,
|
|
36
31
|
hide_values,
|
|
37
32
|
stats_format,
|
|
33
|
+
...remainingParams
|
|
38
34
|
},
|
|
39
35
|
pat = null,
|
|
40
36
|
) => {
|
|
37
|
+
const colorParams = pickColorParams(remainingParams);
|
|
38
|
+
|
|
39
|
+
const invalidColorInput = findInvalidColorParam(colorParams);
|
|
40
|
+
|
|
41
|
+
if (invalidColorInput) {
|
|
42
|
+
return {
|
|
43
|
+
status: "error - permanent",
|
|
44
|
+
content: renderError({
|
|
45
|
+
message: "Something went wrong",
|
|
46
|
+
secondaryMessage: `Invalid color input for parameter "${invalidColorInput}"`,
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
41
51
|
if (locale && !isLocaleAvailable(locale)) {
|
|
42
52
|
return {
|
|
43
53
|
status: "error - permanent",
|
|
44
54
|
content: renderError({
|
|
45
55
|
message: "Something went wrong",
|
|
46
56
|
secondaryMessage: "Locale not found",
|
|
47
|
-
renderOptions:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
renderOptions: colorParams,
|
|
58
|
+
}),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const safePattern = /^[-\w/.,]+$/;
|
|
63
|
+
if (username && !safePattern.test(username)) {
|
|
64
|
+
return {
|
|
65
|
+
status: "error - permanent",
|
|
66
|
+
content: renderError({
|
|
67
|
+
message: "Something went wrong",
|
|
68
|
+
secondaryMessage: "Username contains unsafe characters",
|
|
69
|
+
renderOptions: colorParams,
|
|
54
70
|
}),
|
|
55
71
|
};
|
|
56
72
|
}
|
|
57
73
|
|
|
58
74
|
if (
|
|
59
75
|
layout !== undefined &&
|
|
60
|
-
|
|
61
|
-
!["compact", "normal", "donut", "donut-vertical", "pie"].includes(layout))
|
|
76
|
+
!["compact", "normal", "donut", "donut-vertical", "pie"].includes(layout)
|
|
62
77
|
) {
|
|
63
78
|
return {
|
|
64
79
|
status: "error - permanent",
|
|
65
80
|
content: renderError({
|
|
66
81
|
message: "Something went wrong",
|
|
67
82
|
secondaryMessage: "Incorrect layout input",
|
|
68
|
-
renderOptions:
|
|
69
|
-
title_color,
|
|
70
|
-
text_color,
|
|
71
|
-
bg_color,
|
|
72
|
-
border_color,
|
|
73
|
-
theme,
|
|
74
|
-
},
|
|
83
|
+
renderOptions: colorParams,
|
|
75
84
|
}),
|
|
76
85
|
};
|
|
77
86
|
}
|
|
78
87
|
|
|
79
88
|
if (
|
|
80
89
|
stats_format !== undefined &&
|
|
81
|
-
|
|
82
|
-
!["bytes", "percentages"].includes(stats_format))
|
|
90
|
+
!["bytes", "percentages"].includes(stats_format)
|
|
83
91
|
) {
|
|
84
92
|
return {
|
|
85
93
|
status: "error - permanent",
|
|
86
94
|
content: renderError({
|
|
87
95
|
message: "Something went wrong",
|
|
88
96
|
secondaryMessage: "Incorrect stats_format input",
|
|
89
|
-
renderOptions:
|
|
90
|
-
title_color,
|
|
91
|
-
text_color,
|
|
92
|
-
bg_color,
|
|
93
|
-
border_color,
|
|
94
|
-
theme,
|
|
95
|
-
},
|
|
97
|
+
renderOptions: colorParams,
|
|
96
98
|
}),
|
|
97
99
|
};
|
|
98
100
|
}
|
|
@@ -110,20 +112,15 @@ export default async (
|
|
|
110
112
|
return {
|
|
111
113
|
status: "success",
|
|
112
114
|
content: renderTopLanguages(topLangs, {
|
|
115
|
+
...colorParams,
|
|
113
116
|
custom_title,
|
|
114
117
|
hide_title: parseBoolean(hide_title),
|
|
115
118
|
hide_border: parseBoolean(hide_border),
|
|
116
119
|
card_width: parseInt(card_width, 10),
|
|
117
120
|
hide: parseArray(hide),
|
|
118
|
-
title_color,
|
|
119
|
-
text_color,
|
|
120
|
-
bg_color,
|
|
121
|
-
prog_bar_bg_color,
|
|
122
|
-
theme,
|
|
123
121
|
layout,
|
|
124
122
|
langs_count,
|
|
125
123
|
border_radius,
|
|
126
|
-
border_color,
|
|
127
124
|
locale: locale ? locale.toLowerCase() : null,
|
|
128
125
|
disable_animations: parseBoolean(disable_animations),
|
|
129
126
|
hide_progress: parseBoolean(hide_progress),
|
|
@@ -139,11 +136,7 @@ export default async (
|
|
|
139
136
|
message: err.message,
|
|
140
137
|
secondaryMessage: retrieveSecondaryMessage(err),
|
|
141
138
|
renderOptions: {
|
|
142
|
-
|
|
143
|
-
text_color,
|
|
144
|
-
bg_color,
|
|
145
|
-
border_color,
|
|
146
|
-
theme,
|
|
139
|
+
...colorParams,
|
|
147
140
|
show_repo_link: !(err instanceof MissingParamError),
|
|
148
141
|
},
|
|
149
142
|
}),
|
|
@@ -153,13 +146,7 @@ export default async (
|
|
|
153
146
|
status: "error - temporary",
|
|
154
147
|
content: renderError({
|
|
155
148
|
message: "An unknown error occurred",
|
|
156
|
-
renderOptions:
|
|
157
|
-
title_color,
|
|
158
|
-
text_color,
|
|
159
|
-
bg_color,
|
|
160
|
-
border_color,
|
|
161
|
-
theme,
|
|
162
|
-
},
|
|
149
|
+
renderOptions: colorParams,
|
|
163
150
|
}),
|
|
164
151
|
};
|
|
165
152
|
}
|
package/src/api/wakatime.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { renderWakatimeCard } from "../cards/wakatime.js";
|
|
2
|
+
import { findInvalidColorParam, pickColorParams } from "../common/color.js";
|
|
2
3
|
import {
|
|
3
4
|
MissingParamError,
|
|
4
5
|
retrieveSecondaryMessage,
|
|
@@ -11,14 +12,9 @@ import { isLocaleAvailable } from "../translations.js";
|
|
|
11
12
|
// @ts-ignore
|
|
12
13
|
export default async ({
|
|
13
14
|
username,
|
|
14
|
-
title_color,
|
|
15
|
-
icon_color,
|
|
16
15
|
hide_border,
|
|
17
16
|
card_width,
|
|
18
17
|
line_height,
|
|
19
|
-
text_color,
|
|
20
|
-
bg_color,
|
|
21
|
-
theme,
|
|
22
18
|
hide_title,
|
|
23
19
|
hide_progress,
|
|
24
20
|
custom_title,
|
|
@@ -28,23 +24,42 @@ export default async ({
|
|
|
28
24
|
hide,
|
|
29
25
|
api_domain,
|
|
30
26
|
border_radius,
|
|
31
|
-
border_color,
|
|
32
27
|
display_format,
|
|
33
28
|
disable_animations,
|
|
29
|
+
...remainingParams
|
|
34
30
|
}) => {
|
|
31
|
+
const colorParams = pickColorParams(remainingParams);
|
|
32
|
+
|
|
33
|
+
const invalidColorInput = findInvalidColorParam(colorParams);
|
|
34
|
+
if (invalidColorInput) {
|
|
35
|
+
return {
|
|
36
|
+
status: "error - permanent",
|
|
37
|
+
content: renderError({
|
|
38
|
+
message: "Something went wrong",
|
|
39
|
+
secondaryMessage: `Invalid color input for parameter "${invalidColorInput}"`,
|
|
40
|
+
}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
35
44
|
if (locale && !isLocaleAvailable(locale)) {
|
|
36
45
|
return {
|
|
37
46
|
status: "error - permanent",
|
|
38
47
|
content: renderError({
|
|
39
48
|
message: "Something went wrong",
|
|
40
49
|
secondaryMessage: "Language not found",
|
|
41
|
-
renderOptions:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
renderOptions: colorParams,
|
|
51
|
+
}),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const safePattern = /^[-\w/.,]+$/;
|
|
56
|
+
if (username && !safePattern.test(username)) {
|
|
57
|
+
return {
|
|
58
|
+
status: "error - permanent",
|
|
59
|
+
content: renderError({
|
|
60
|
+
message: "Something went wrong",
|
|
61
|
+
secondaryMessage: "Username contains unsafe characters",
|
|
62
|
+
renderOptions: colorParams,
|
|
48
63
|
}),
|
|
49
64
|
};
|
|
50
65
|
}
|
|
@@ -55,20 +70,15 @@ export default async ({
|
|
|
55
70
|
return {
|
|
56
71
|
status: "success",
|
|
57
72
|
content: renderWakatimeCard(stats, {
|
|
73
|
+
...colorParams,
|
|
58
74
|
custom_title,
|
|
59
75
|
hide_title: parseBoolean(hide_title),
|
|
60
76
|
hide_border: parseBoolean(hide_border),
|
|
61
77
|
card_width: parseInt(card_width, 10),
|
|
62
78
|
hide: parseArray(hide),
|
|
63
79
|
line_height,
|
|
64
|
-
title_color,
|
|
65
|
-
icon_color,
|
|
66
|
-
text_color,
|
|
67
|
-
bg_color,
|
|
68
|
-
theme,
|
|
69
80
|
hide_progress,
|
|
70
81
|
border_radius,
|
|
71
|
-
border_color,
|
|
72
82
|
locale: locale ? locale.toLowerCase() : null,
|
|
73
83
|
layout,
|
|
74
84
|
langs_count,
|
|
@@ -84,11 +94,7 @@ export default async ({
|
|
|
84
94
|
message: err.message,
|
|
85
95
|
secondaryMessage: retrieveSecondaryMessage(err),
|
|
86
96
|
renderOptions: {
|
|
87
|
-
|
|
88
|
-
text_color,
|
|
89
|
-
bg_color,
|
|
90
|
-
border_color,
|
|
91
|
-
theme,
|
|
97
|
+
...colorParams,
|
|
92
98
|
show_repo_link: !(err instanceof MissingParamError),
|
|
93
99
|
},
|
|
94
100
|
}),
|
|
@@ -98,13 +104,7 @@ export default async ({
|
|
|
98
104
|
status: "error - temporary",
|
|
99
105
|
content: renderError({
|
|
100
106
|
message: "An unknown error occurred",
|
|
101
|
-
renderOptions:
|
|
102
|
-
title_color,
|
|
103
|
-
text_color,
|
|
104
|
-
bg_color,
|
|
105
|
-
border_color,
|
|
106
|
-
theme,
|
|
107
|
-
},
|
|
107
|
+
renderOptions: colorParams,
|
|
108
108
|
}),
|
|
109
109
|
};
|
|
110
110
|
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Calculates the exponential cdf.
|
|
3
3
|
*
|
|
4
|
-
* @param
|
|
5
|
-
* @returns
|
|
4
|
+
* @param x The value.
|
|
5
|
+
* @returns The exponential cdf.
|
|
6
6
|
*/
|
|
7
|
-
function exponential_cdf(x) {
|
|
7
|
+
function exponential_cdf(x: number): number {
|
|
8
8
|
return 1 - 2 ** -x;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Calculates the log normal cdf.
|
|
13
13
|
*
|
|
14
|
-
* @param
|
|
15
|
-
* @returns
|
|
14
|
+
* @param x The value.
|
|
15
|
+
* @returns The log normal cdf.
|
|
16
16
|
*/
|
|
17
|
-
function log_normal_cdf(x) {
|
|
17
|
+
function log_normal_cdf(x: number): number {
|
|
18
18
|
// approximation
|
|
19
19
|
return x / (1 + x);
|
|
20
20
|
}
|
|
@@ -22,16 +22,16 @@ function log_normal_cdf(x) {
|
|
|
22
22
|
/**
|
|
23
23
|
* Calculates the users rank.
|
|
24
24
|
*
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @returns
|
|
25
|
+
* @param params Parameters on which the user's rank depends.
|
|
26
|
+
* @param params.all_commits Whether `include_all_commits` was used.
|
|
27
|
+
* @param params.commits Number of commits.
|
|
28
|
+
* @param params.prs The number of pull requests.
|
|
29
|
+
* @param params.issues The number of issues.
|
|
30
|
+
* @param params.reviews The number of reviews.
|
|
31
|
+
* @param params.repos Total number of repos (accepted for compatibility, unused in the calculation).
|
|
32
|
+
* @param params.stars The number of stars.
|
|
33
|
+
* @param params.followers The number of followers.
|
|
34
|
+
* @returns The users rank.
|
|
35
35
|
*/
|
|
36
36
|
function calculateRank({
|
|
37
37
|
all_commits,
|
|
@@ -39,11 +39,18 @@ function calculateRank({
|
|
|
39
39
|
prs,
|
|
40
40
|
issues,
|
|
41
41
|
reviews,
|
|
42
|
-
// eslint-disable-next-line no-unused-vars
|
|
43
|
-
repos, // unused
|
|
44
42
|
stars,
|
|
45
43
|
followers,
|
|
46
|
-
}
|
|
44
|
+
}: {
|
|
45
|
+
all_commits: boolean;
|
|
46
|
+
commits: number;
|
|
47
|
+
prs: number;
|
|
48
|
+
issues: number;
|
|
49
|
+
reviews: number;
|
|
50
|
+
repos: number;
|
|
51
|
+
stars: number;
|
|
52
|
+
followers: number;
|
|
53
|
+
}): { level: string; percentile: number } {
|
|
47
54
|
const COMMITS_MEDIAN = all_commits ? 1000 : 250,
|
|
48
55
|
COMMITS_WEIGHT = 2;
|
|
49
56
|
const PRS_MEDIAN = 50,
|
|
@@ -79,6 +86,9 @@ function calculateRank({
|
|
|
79
86
|
TOTAL_WEIGHT;
|
|
80
87
|
|
|
81
88
|
const level = LEVELS[THRESHOLDS.findIndex((t) => rank * 100 <= t)];
|
|
89
|
+
if (level === undefined) {
|
|
90
|
+
throw new Error("Unable to determine rank level");
|
|
91
|
+
}
|
|
82
92
|
|
|
83
93
|
return { level, percentile: rank * 100 };
|
|
84
94
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ThemeName } from "../themes/index.js";
|
|
2
|
+
|
|
3
|
+
export interface CommonOptions {
|
|
4
|
+
title_color: string;
|
|
5
|
+
icon_color: string;
|
|
6
|
+
text_color: string;
|
|
7
|
+
bg_color: string;
|
|
8
|
+
theme: ThemeName;
|
|
9
|
+
border_radius: number;
|
|
10
|
+
border_color: string;
|
|
11
|
+
locale: string;
|
|
12
|
+
hide_border: boolean;
|
|
13
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { default as Card } from "../common/Card.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getLightDarkColors } from "../common/color.js";
|
|
3
3
|
import { kFormatter, wrapTextMultiline } from "../common/fmt.js";
|
|
4
4
|
import { encodeHTML } from "../common/html.js";
|
|
5
5
|
import { icons } from "../common/icons.js";
|
|
6
|
-
import
|
|
6
|
+
import { getLanguageColor } from "../common/languageColors.js";
|
|
7
7
|
import { parseEmojis } from "../common/ops.js";
|
|
8
8
|
import {
|
|
9
9
|
countWrappedLines,
|
|
@@ -14,6 +14,9 @@ import {
|
|
|
14
14
|
wrappedTextNode,
|
|
15
15
|
wrappedTextStyles,
|
|
16
16
|
} from "../common/render.js";
|
|
17
|
+
import type { GistData } from "../fetchers/types.js";
|
|
18
|
+
|
|
19
|
+
import type { CommonOptions } from "./common-options.js";
|
|
17
20
|
|
|
18
21
|
const ICON_SIZE = 16;
|
|
19
22
|
const CARD_DEFAULT_WIDTH = 400;
|
|
@@ -24,48 +27,39 @@ const DESCRIPTION_FONT_SIZE = 13;
|
|
|
24
27
|
const DESCRIPTION_LINE_HEIGHT_PX = 16;
|
|
25
28
|
const DESCRIPTION_MAX_LINES = 10;
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
interface GistCardOptions extends CommonOptions {
|
|
31
|
+
show_owner: boolean;
|
|
32
|
+
browser_rendering: boolean;
|
|
33
|
+
}
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* Render gist card.
|
|
34
37
|
*
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @returns
|
|
38
|
+
* @param gistData Gist data.
|
|
39
|
+
* @param options Gist card options.
|
|
40
|
+
* @returns Gist card.
|
|
38
41
|
*/
|
|
39
|
-
const renderGistCard = (
|
|
42
|
+
const renderGistCard = (
|
|
43
|
+
gistData: GistData,
|
|
44
|
+
options: Partial<GistCardOptions> = {},
|
|
45
|
+
): string => {
|
|
40
46
|
const { name, nameWithOwner, description, language, starsCount, forksCount } =
|
|
41
47
|
gistData;
|
|
42
48
|
const {
|
|
43
|
-
title_color,
|
|
44
|
-
icon_color,
|
|
45
|
-
text_color,
|
|
46
|
-
bg_color,
|
|
47
49
|
theme = "default_repocard",
|
|
48
50
|
border_radius,
|
|
49
|
-
border_color,
|
|
50
51
|
show_owner = false,
|
|
51
52
|
browser_rendering = false,
|
|
52
53
|
hide_border = false,
|
|
53
54
|
} = options;
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
const {
|
|
57
|
-
getCardColors({
|
|
58
|
-
title_color,
|
|
59
|
-
icon_color,
|
|
60
|
-
text_color,
|
|
61
|
-
bg_color,
|
|
62
|
-
border_color,
|
|
63
|
-
theme,
|
|
64
|
-
});
|
|
56
|
+
const { lightColors, darkColors } = getLightDarkColors({ ...options, theme });
|
|
57
|
+
const { textColor, iconColor } = lightColors;
|
|
65
58
|
|
|
66
59
|
const desc = parseEmojis(description || "No description provided");
|
|
67
60
|
|
|
68
|
-
let descriptionLines
|
|
61
|
+
let descriptionLines: number;
|
|
62
|
+
let descriptionSvg: string;
|
|
69
63
|
if (browser_rendering) {
|
|
70
64
|
// The browser performs the actual text wrapping inside the foreignObject;
|
|
71
65
|
// we only estimate the line count server-side so the SVG can reserve enough
|
|
@@ -128,8 +122,7 @@ const renderGistCard = (gistData, options = {}) => {
|
|
|
128
122
|
);
|
|
129
123
|
|
|
130
124
|
const languageName = language || "Unspecified";
|
|
131
|
-
|
|
132
|
-
const languageColor = languageColors[languageName] || "#858585";
|
|
125
|
+
const languageColor = getLanguageColor(languageName);
|
|
133
126
|
|
|
134
127
|
const svgLanguage = createLanguageNode(languageName, languageColor);
|
|
135
128
|
|
|
@@ -154,23 +147,30 @@ const renderGistCard = (gistData, options = {}) => {
|
|
|
154
147
|
width: CARD_DEFAULT_WIDTH,
|
|
155
148
|
height,
|
|
156
149
|
border_radius,
|
|
157
|
-
colors: {
|
|
158
|
-
titleColor,
|
|
159
|
-
textColor,
|
|
160
|
-
iconColor,
|
|
161
|
-
bgColor,
|
|
162
|
-
borderColor,
|
|
163
|
-
},
|
|
150
|
+
colors: { light: lightColors, dark: darkColors },
|
|
164
151
|
});
|
|
165
152
|
|
|
166
|
-
card.setCSS(
|
|
153
|
+
card.setCSS({
|
|
154
|
+
light: `
|
|
167
155
|
.description {
|
|
168
156
|
font: 400 ${DESCRIPTION_FONT_SIZE}px 'Segoe UI', Ubuntu, Sans-Serif;fill: ${textColor};
|
|
169
157
|
${browser_rendering ? wrappedTextStyles(textColor) : ""}
|
|
170
158
|
}
|
|
171
159
|
.gray { font: 400 12px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${textColor} }
|
|
172
160
|
.icon { fill: ${iconColor} }
|
|
173
|
-
|
|
161
|
+
`,
|
|
162
|
+
dark: darkColors
|
|
163
|
+
? `
|
|
164
|
+
.description {
|
|
165
|
+
fill: ${darkColors.textColor};
|
|
166
|
+
${browser_rendering ? wrappedTextStyles(darkColors.textColor) : ""}
|
|
167
|
+
}
|
|
168
|
+
.gray { fill: ${darkColors.textColor} }
|
|
169
|
+
.icon { fill: ${darkColors.iconColor} }
|
|
170
|
+
`
|
|
171
|
+
: null,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
174
|
card.setHideBorder(hide_border);
|
|
175
175
|
|
|
176
176
|
return card.render(`
|