@stats-forge/github-stats-forge-core 0.0.2 → 0.1.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/README.md +0 -10
- package/build/api/api-result.d.ts +6 -7
- package/build/api/api-result.d.ts.map +1 -1
- package/build/api/api-result.js +4 -5
- package/build/api/gist.d.ts +3 -10
- package/build/api/gist.d.ts.map +1 -1
- package/build/api/gist.js +4 -11
- package/build/api/index.d.ts +12 -12
- package/build/api/params.d.ts +11 -8
- package/build/api/params.d.ts.map +1 -1
- package/build/api/params.js +16 -14
- package/build/api/pin.d.ts +3 -19
- package/build/api/pin.d.ts.map +1 -1
- package/build/api/pin.js +6 -22
- package/build/api/stats.d.ts +10 -4
- package/build/api/stats.d.ts.map +1 -1
- package/build/api/stats.js +6 -32
- package/build/api/top-langs.d.ts +12 -6
- package/build/api/top-langs.d.ts.map +1 -1
- package/build/api/top-langs.js +6 -26
- package/build/api/wakatime.d.ts +13 -5
- package/build/api/wakatime.d.ts.map +1 -1
- package/build/api/wakatime.js +4 -21
- package/build/calculateRank.d.ts +0 -9
- package/build/calculateRank.d.ts.map +1 -1
- package/build/calculateRank.js +12 -17
- package/build/cards/gist.d.ts +2 -4
- package/build/cards/gist.d.ts.map +1 -1
- package/build/cards/gist.js +27 -36
- package/build/cards/options.d.ts +1 -1
- package/build/cards/repo.d.ts +2 -4
- package/build/cards/repo.d.ts.map +1 -1
- package/build/cards/repo.js +61 -93
- package/build/cards/stats.d.ts +3 -8
- package/build/cards/stats.d.ts.map +1 -1
- package/build/cards/stats.js +119 -165
- package/build/cards/top-languages.d.ts +5 -31
- package/build/cards/top-languages.d.ts.map +1 -1
- package/build/cards/top-languages.js +176 -384
- package/build/cards/wakatime.d.ts +4 -6
- package/build/cards/wakatime.d.ts.map +1 -1
- package/build/cards/wakatime.js +118 -185
- package/build/common/Card.d.ts +14 -62
- package/build/common/Card.d.ts.map +1 -1
- package/build/common/Card.js +97 -199
- package/build/common/I18n.d.ts +0 -6
- package/build/common/I18n.d.ts.map +1 -1
- package/build/common/I18n.js +3 -6
- package/build/common/color.d.ts +4 -17
- package/build/common/color.d.ts.map +1 -1
- package/build/common/color.js +67 -49
- package/build/common/config.d.ts +4 -14
- package/build/common/config.d.ts.map +1 -1
- package/build/common/config.js +3 -16
- package/build/common/constants.d.ts +4 -2
- package/build/common/constants.d.ts.map +1 -1
- package/build/common/constants.js +3 -1
- package/build/common/date.d.ts +0 -2
- package/build/common/date.d.ts.map +1 -1
- package/build/common/date.js +0 -2
- package/build/common/emojiMap.d.ts +8 -0
- package/build/common/emojiMap.d.ts.map +1 -0
- package/build/common/emojiMap.js +10 -0
- package/build/common/emojiMap.json +1915 -0
- package/build/common/error.d.ts +1 -10
- package/build/common/error.d.ts.map +1 -1
- package/build/common/error.js +1 -10
- package/build/common/fmt.d.ts +3 -15
- package/build/common/fmt.d.ts.map +1 -1
- package/build/common/fmt.js +7 -35
- package/build/common/http.d.ts +2 -7
- package/build/common/http.d.ts.map +1 -1
- package/build/common/http.js +8 -17
- package/build/common/icons.d.ts +18 -20
- package/build/common/icons.d.ts.map +1 -1
- package/build/common/icons.js +103 -67
- package/build/common/languageColors.d.ts +0 -1
- package/build/common/languageColors.d.ts.map +1 -1
- package/build/common/languageColors.js +1 -4
- package/build/common/languageColors.json +18 -2
- package/build/common/ops.d.ts +3 -14
- package/build/common/ops.d.ts.map +1 -1
- package/build/common/ops.js +19 -30
- package/build/common/render.d.ts +28 -82
- package/build/common/render.d.ts.map +1 -1
- package/build/common/render.js +175 -211
- package/build/common/retryer.d.ts +2 -7
- package/build/common/retryer.d.ts.map +1 -1
- package/build/common/retryer.js +4 -11
- package/build/fetchers/gist.d.ts +2 -5
- package/build/fetchers/gist.d.ts.map +1 -1
- package/build/fetchers/gist.js +1 -5
- package/build/fetchers/index.d.ts +12 -12
- package/build/fetchers/repo.d.ts +2 -11
- package/build/fetchers/repo.d.ts.map +1 -1
- package/build/fetchers/repo.js +20 -33
- package/build/fetchers/stats.d.ts +2 -32
- package/build/fetchers/stats.d.ts.map +1 -1
- package/build/fetchers/stats.js +27 -86
- package/build/fetchers/top-languages.d.ts +2 -9
- package/build/fetchers/top-languages.d.ts.map +1 -1
- package/build/fetchers/top-languages.js +15 -31
- package/build/fetchers/types.d.ts +1 -1
- package/build/fetchers/wakatime.d.ts +2 -6
- package/build/fetchers/wakatime.d.ts.map +1 -1
- package/build/fetchers/wakatime.js +1 -5
- package/build/graphql/contributionsDocument.d.ts +3 -3
- package/build/graphql/contributionsDocument.d.ts.map +1 -1
- package/build/graphql/contributionsDocument.js +0 -1
- package/build/graphql/generated/gist.d.ts +1 -1
- package/build/graphql/generated/repo.d.ts +1 -1
- package/build/graphql/generated/stats.d.ts +3 -3
- package/build/graphql/generated/top-languages.d.ts +2 -2
- package/build/graphql/graphqlDocument.d.ts +0 -1
- package/build/graphql/graphqlDocument.d.ts.map +1 -1
- package/build/graphql/graphqlDocument.js +0 -1
- package/build/graphql/reposContributedToDocument.d.ts +4 -5
- package/build/graphql/reposContributedToDocument.d.ts.map +1 -1
- package/build/graphql/reposContributedToDocument.js +0 -2
- package/build/markup/css.d.ts +35 -0
- package/build/markup/css.d.ts.map +1 -0
- package/build/markup/css.js +64 -0
- package/build/markup/element.d.ts +41 -0
- package/build/markup/element.d.ts.map +1 -0
- package/build/markup/element.js +127 -0
- package/build/markup/html.d.ts +13 -0
- package/build/markup/html.d.ts.map +1 -0
- package/build/markup/html.js +27 -0
- package/build/markup/index.d.ts +9 -0
- package/build/markup/index.d.ts.map +1 -0
- package/build/markup/index.js +6 -0
- package/build/markup/serialize.d.ts +16 -0
- package/build/markup/serialize.d.ts.map +1 -0
- package/build/markup/serialize.js +17 -0
- package/build/themes/index.d.ts +332 -333
- package/build/themes/index.d.ts.map +1 -1
- package/build/themes/index.js +1 -1
- package/build/translations.d.ts +2 -6
- package/build/translations.d.ts.map +1 -1
- package/build/translations.js +621 -628
- package/package.json +17 -26
- package/src/api/api-result.ts +10 -9
- package/src/api/gist.ts +11 -18
- package/src/api/index.ts +12 -12
- package/src/api/params.ts +27 -21
- package/src/api/pin.ts +13 -28
- package/src/api/stats.ts +13 -39
- package/src/api/top-langs.ts +13 -33
- package/src/api/wakatime.ts +11 -28
- package/src/calculateRank.ts +12 -23
- package/src/cards/gist.ts +40 -43
- package/src/cards/options.ts +1 -1
- package/src/cards/repo.ts +97 -107
- package/src/cards/stats.ts +165 -184
- package/src/cards/top-languages.ts +297 -413
- package/src/cards/wakatime.ts +193 -221
- package/src/common/Card.ts +165 -217
- package/src/common/I18n.ts +3 -6
- package/src/common/color.ts +80 -57
- package/src/common/config.ts +5 -18
- package/src/common/constants.ts +5 -2
- package/src/common/date.ts +0 -2
- package/src/common/emojiMap.json +1915 -0
- package/src/common/emojiMap.ts +13 -0
- package/src/common/error.ts +2 -11
- package/src/common/fmt.ts +7 -44
- package/src/common/http.ts +9 -15
- package/src/common/icons.ts +117 -42
- package/src/common/languageColors.json +18 -2
- package/src/common/languageColors.ts +1 -4
- package/src/common/ops.ts +26 -34
- package/src/common/render.ts +279 -232
- package/src/common/retryer.ts +8 -15
- package/src/fetchers/gist.ts +8 -12
- package/src/fetchers/index.ts +12 -12
- package/src/fetchers/repo.ts +27 -40
- package/src/fetchers/stats.ts +44 -102
- package/src/fetchers/top-languages.ts +26 -40
- package/src/fetchers/types.ts +1 -1
- package/src/fetchers/wakatime.ts +5 -9
- package/src/graphql/contributionsDocument.ts +7 -5
- package/src/graphql/generated/gist.ts +1 -1
- package/src/graphql/generated/repo.ts +1 -1
- package/src/graphql/generated/stats.ts +2 -2
- package/src/graphql/generated/top-languages.ts +2 -2
- package/src/graphql/graphqlDocument.ts +0 -1
- package/src/graphql/reposContributedToDocument.ts +6 -7
- package/src/markup/css.ts +118 -0
- package/src/markup/element.ts +246 -0
- package/src/markup/html.ts +34 -0
- package/src/markup/index.ts +9 -0
- package/src/markup/serialize.ts +27 -0
- package/src/themes/index.ts +1 -1
- package/src/translations.ts +622 -629
- package/build/cards/index.d.ts +0 -11
- package/build/cards/index.d.ts.map +0 -1
- package/build/cards/index.js +0 -7
- package/build/common/html.d.ts +0 -8
- package/build/common/html.d.ts.map +0 -1
- package/build/common/html.js +0 -14
- package/build/index.d.ts +0 -15
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -10
- package/src/_emoji-name-map.d.ts +0 -10
- package/src/_github-username-regex.d.ts +0 -4
- package/src/cards/index.ts +0 -21
- package/src/common/html.ts +0 -17
- package/src/index.ts +0 -18
package/src/common/ops.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { RepositoryAffiliation } from '../graphql/generated/common.ts';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import { CardError, INVALID_AFFILIATION } from './error.js';
|
|
3
|
+
import { OWNER_AFFILIATIONS } from './constants.ts';
|
|
4
|
+
import { getEmoji } from './emojiMap.ts';
|
|
5
|
+
import { CardError, INVALID_AFFILIATION } from './error.ts';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Returns boolean if value is either "true" or "false" else the value as it is.
|
|
10
9
|
*
|
|
11
|
-
* @param value The value to parse; `undefined` when the param was not sent.
|
|
12
10
|
* @returns The parsed value.
|
|
13
11
|
*/
|
|
14
12
|
const parseBoolean = (value: string | boolean | undefined): boolean | undefined => {
|
|
@@ -19,7 +17,8 @@ const parseBoolean = (value: string | boolean | undefined): boolean | undefined
|
|
|
19
17
|
if (typeof value === 'string') {
|
|
20
18
|
if (value.toLowerCase() === 'true') {
|
|
21
19
|
return true;
|
|
22
|
-
}
|
|
20
|
+
}
|
|
21
|
+
if (value.toLowerCase() === 'false') {
|
|
23
22
|
return false;
|
|
24
23
|
}
|
|
25
24
|
}
|
|
@@ -29,7 +28,6 @@ const parseBoolean = (value: string | boolean | undefined): boolean | undefined
|
|
|
29
28
|
/**
|
|
30
29
|
* Parse string to array of strings.
|
|
31
30
|
*
|
|
32
|
-
* @param str The string to parse; `undefined` when the param was not sent.
|
|
33
31
|
* @returns The array of strings.
|
|
34
32
|
*/
|
|
35
33
|
const parseArray = (str: string | undefined): Array<string> => {
|
|
@@ -42,13 +40,10 @@ const parseArray = (str: string | undefined): Array<string> => {
|
|
|
42
40
|
/**
|
|
43
41
|
* Clamp the given number between the given range.
|
|
44
42
|
*
|
|
45
|
-
* @param number The number to clamp.
|
|
46
|
-
* @param min The minimum value.
|
|
47
|
-
* @param max The maximum value.
|
|
48
43
|
* @returns The clamped number.
|
|
49
44
|
*/
|
|
50
45
|
const clampValue = (number: string | number, min: number, max: number): number => {
|
|
51
|
-
if (Number.isNaN(parseInt(String(number), 10))) {
|
|
46
|
+
if (Number.isNaN(Number.parseInt(String(number), 10))) {
|
|
52
47
|
return min;
|
|
53
48
|
}
|
|
54
49
|
return Math.max(min, Math.min(Number(number), max));
|
|
@@ -57,7 +52,6 @@ const clampValue = (number: string | number, min: number, max: number): number =
|
|
|
57
52
|
/**
|
|
58
53
|
* Lowercase and trim string.
|
|
59
54
|
*
|
|
60
|
-
* @param name String to lowercase and trim.
|
|
61
55
|
* @returns Lowercased and trimmed string.
|
|
62
56
|
*/
|
|
63
57
|
const lowercaseTrim = (name: string): string => name.toLowerCase().trim();
|
|
@@ -65,34 +59,33 @@ const lowercaseTrim = (name: string): string => name.toLowerCase().trim();
|
|
|
65
59
|
/**
|
|
66
60
|
* Split array of languages in two columns.
|
|
67
61
|
*
|
|
68
|
-
* @template T Language object.
|
|
69
|
-
* @param arr Array of languages.
|
|
70
|
-
* @param perChunk Number of languages per column.
|
|
71
62
|
* @returns Array of languages split in two columns.
|
|
72
63
|
*/
|
|
73
64
|
const chunkArray = <T>(arr: Array<T>, perChunk: number): Array<Array<T>> => {
|
|
74
|
-
|
|
65
|
+
const chunks: Array<Array<T>> = [];
|
|
66
|
+
for (const [index, item] of arr.entries()) {
|
|
75
67
|
const chunkIndex = Math.floor(index / perChunk);
|
|
76
|
-
const chunk =
|
|
68
|
+
const chunk = chunks[chunkIndex] ?? [];
|
|
77
69
|
chunk.push(item);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
chunks[chunkIndex] = chunk;
|
|
71
|
+
}
|
|
72
|
+
return chunks;
|
|
81
73
|
};
|
|
82
74
|
|
|
83
75
|
/**
|
|
84
76
|
* Parse emoji from string.
|
|
85
77
|
*
|
|
86
|
-
* @param str String to parse emoji from.
|
|
87
78
|
* @returns String with emoji parsed.
|
|
88
79
|
*/
|
|
89
80
|
const parseEmojis = (str: string): string => {
|
|
90
81
|
if (!str) {
|
|
91
82
|
throw new Error('[parseEmoji]: str argument not provided');
|
|
92
83
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
84
|
+
// `+` and `-` are part of a shortcode: `:+1:`, `:non-potable_water:`.
|
|
85
|
+
return str.replaceAll(
|
|
86
|
+
/:(?<shortcode>[\w+-]+):/g,
|
|
87
|
+
(_match, shortcode: string) => getEmoji(shortcode) ?? '',
|
|
88
|
+
);
|
|
96
89
|
};
|
|
97
90
|
|
|
98
91
|
const isOwnerAffiliation = (value: string): value is RepositoryAffiliation =>
|
|
@@ -101,22 +94,19 @@ const isOwnerAffiliation = (value: string): value is RepositoryAffiliation =>
|
|
|
101
94
|
/**
|
|
102
95
|
* Parse owner affiliations.
|
|
103
96
|
*
|
|
104
|
-
* @param affiliations input affiliations to be parsed.
|
|
105
|
-
* @returns Parsed affiliations.
|
|
106
|
-
*
|
|
107
97
|
* @throws {CardError} If affiliations contains invalid values.
|
|
98
|
+
*
|
|
99
|
+
* @returns Parsed affiliations.
|
|
108
100
|
*/
|
|
109
101
|
const parseOwnerAffiliations = (affiliations: Array<string>): Array<RepositoryAffiliation> => {
|
|
110
|
-
//
|
|
111
|
-
// NOTE: Done here since parseArray() will always return an empty array even nothing
|
|
112
|
-
//was specified.
|
|
102
|
+
// `parseArray` returns an empty array for an absent param, so the default lands here.
|
|
113
103
|
const normalized =
|
|
114
104
|
affiliations.length > 0
|
|
115
105
|
? affiliations.map((affiliation) => affiliation.toUpperCase())
|
|
116
106
|
: ['OWNER'];
|
|
117
107
|
|
|
118
108
|
// Check if ownerAffiliations contains valid values.
|
|
119
|
-
if (!normalized.every(isOwnerAffiliation)) {
|
|
109
|
+
if (!normalized.every((value) => isOwnerAffiliation(value))) {
|
|
120
110
|
throw CardError.invalidParam('role', INVALID_AFFILIATION);
|
|
121
111
|
}
|
|
122
112
|
return normalized;
|
|
@@ -127,9 +117,11 @@ const buildSearchFilter = (
|
|
|
127
117
|
owners: Array<string> | string = [],
|
|
128
118
|
): string => {
|
|
129
119
|
const repoFilter =
|
|
130
|
-
Array.isArray(repos) && repos.length > 0 ? repos.map((
|
|
120
|
+
Array.isArray(repos) && repos.length > 0 ? repos.map((repo) => `repo:${repo} `).join('') : '';
|
|
131
121
|
const orgFilter =
|
|
132
|
-
Array.isArray(owners) && owners.length > 0
|
|
122
|
+
Array.isArray(owners) && owners.length > 0
|
|
123
|
+
? owners.map((owner) => `owner:${owner} `).join('')
|
|
124
|
+
: '';
|
|
133
125
|
return repoFilter + orgFilter;
|
|
134
126
|
};
|
|
135
127
|
|