@stats-forge/github-stats-forge-core 0.0.2 → 0.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/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/contributed-to.d.ts +23 -0
- package/build/api/contributed-to.d.ts.map +1 -0
- package/build/api/contributed-to.js +43 -0
- package/build/api/gist.d.ts +8 -22
- package/build/api/gist.d.ts.map +1 -1
- package/build/api/gist.js +14 -36
- package/build/api/handler.d.ts +16 -0
- package/build/api/handler.d.ts.map +1 -0
- package/build/api/handler.js +29 -0
- package/build/api/index.d.ts +13 -12
- package/build/api/index.d.ts.map +1 -1
- package/build/api/index.js +1 -0
- package/build/api/params.d.ts +21 -12
- package/build/api/params.d.ts.map +1 -1
- package/build/api/params.js +41 -19
- package/build/api/pin.d.ts +11 -31
- package/build/api/pin.d.ts.map +1 -1
- package/build/api/pin.js +35 -63
- package/build/api/stats.d.ts +15 -16
- package/build/api/stats.d.ts.map +1 -1
- package/build/api/stats.js +60 -99
- package/build/api/top-langs.d.ts +13 -18
- package/build/api/top-langs.d.ts.map +1 -1
- package/build/api/top-langs.js +35 -72
- package/build/api/wakatime.d.ts +11 -17
- package/build/api/wakatime.d.ts.map +1 -1
- package/build/api/wakatime.js +27 -64
- package/build/calculateRank.d.ts +0 -9
- package/build/calculateRank.d.ts.map +1 -1
- package/build/calculateRank.js +12 -17
- package/build/cards/contributed-to.d.ts +19 -0
- package/build/cards/contributed-to.d.ts.map +1 -0
- package/build/cards/contributed-to.js +242 -0
- package/build/cards/gist.d.ts +3 -4
- package/build/cards/gist.d.ts.map +1 -1
- package/build/cards/gist.js +38 -43
- package/build/cards/options.d.ts +1 -1
- package/build/cards/repo.d.ts +14 -5
- package/build/cards/repo.d.ts.map +1 -1
- package/build/cards/repo.js +93 -103
- package/build/cards/stats.d.ts +18 -11
- package/build/cards/stats.d.ts.map +1 -1
- package/build/cards/stats.js +191 -222
- package/build/cards/top-languages.d.ts +18 -33
- package/build/cards/top-languages.d.ts.map +1 -1
- package/build/cards/top-languages.js +196 -387
- package/build/cards/wakatime.d.ts +17 -8
- package/build/cards/wakatime.d.ts.map +1 -1
- package/build/cards/wakatime.js +133 -187
- package/build/common/Card.d.ts +20 -59
- package/build/common/Card.d.ts.map +1 -1
- package/build/common/Card.js +131 -198
- package/build/common/I18n.d.ts +1 -7
- package/build/common/I18n.d.ts.map +1 -1
- package/build/common/I18n.js +7 -8
- package/build/common/brand.d.ts +76 -0
- package/build/common/brand.d.ts.map +1 -0
- package/build/common/brand.js +73 -0
- 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 +6 -2
- package/build/common/constants.d.ts.map +1 -1
- package/build/common/constants.js +5 -1
- package/build/common/date.d.ts +50 -5
- package/build/common/date.d.ts.map +1 -1
- package/build/common/date.js +104 -4
- 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 +20 -20
- package/build/common/icons.d.ts.map +1 -1
- package/build/common/icons.js +108 -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 +11 -17
- package/build/common/ops.d.ts.map +1 -1
- package/build/common/ops.js +22 -39
- package/build/common/render.d.ts +34 -82
- package/build/common/render.d.ts.map +1 -1
- package/build/common/render.js +225 -259
- 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/contributed-to.d.ts +62 -0
- package/build/fetchers/contributed-to.d.ts.map +1 -0
- package/build/fetchers/contributed-to.js +184 -0
- 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/graphql-error.d.ts +13 -0
- package/build/fetchers/graphql-error.d.ts.map +1 -0
- package/build/fetchers/graphql-error.js +29 -0
- package/build/fetchers/index.d.ts +13 -12
- package/build/fetchers/index.d.ts.map +1 -1
- package/build/fetchers/index.js +1 -0
- 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 +16 -40
- package/build/fetchers/stats.d.ts.map +1 -1
- package/build/fetchers/stats.js +89 -271
- 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 +16 -47
- package/build/fetchers/types.d.ts +25 -1
- package/build/fetchers/types.d.ts.map +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/contributionsCollection.d.ts +9 -0
- package/build/graphql/contributionsCollection.d.ts.map +1 -0
- package/build/graphql/contributionsCollection.js +12 -0
- package/build/graphql/contributionsDocument.d.ts +6 -6
- package/build/graphql/contributionsDocument.d.ts.map +1 -1
- package/build/graphql/contributionsDocument.js +8 -16
- package/build/graphql/generated/contributed-to.d.ts +22 -0
- package/build/graphql/generated/contributed-to.d.ts.map +1 -0
- package/build/graphql/generated/contributed-to.js +11 -0
- 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 +16 -4
- package/build/graphql/generated/stats.d.ts.map +1 -1
- package/build/graphql/generated/stats.js +2 -2
- package/build/graphql/generated/top-languages.d.ts +2 -2
- package/build/graphql/graphqlDocument.d.ts +1 -2
- 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 +11 -7
- 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 +66 -7
- package/build/translations.d.ts.map +1 -1
- package/build/translations.js +686 -629
- package/package.json +17 -26
- package/src/api/api-result.ts +10 -9
- package/src/api/contributed-to.ts +84 -0
- package/src/api/gist.ts +22 -46
- package/src/api/handler.ts +42 -0
- package/src/api/index.ts +13 -12
- package/src/api/params.ts +74 -29
- package/src/api/pin.ts +38 -65
- package/src/api/stats.ts +81 -118
- package/src/api/top-langs.ts +38 -80
- package/src/api/wakatime.ts +35 -73
- package/src/calculateRank.ts +12 -23
- package/src/cards/contributed-to.ts +373 -0
- package/src/cards/gist.ts +55 -49
- package/src/cards/options.ts +1 -1
- package/src/cards/repo.ts +134 -120
- package/src/cards/stats.ts +262 -252
- package/src/cards/top-languages.ts +315 -422
- package/src/cards/wakatime.ts +207 -225
- package/src/common/Card.ts +207 -214
- package/src/common/I18n.ts +7 -8
- package/src/common/brand.ts +109 -0
- package/src/common/color.ts +80 -57
- package/src/common/config.ts +5 -18
- package/src/common/constants.ts +8 -2
- package/src/common/date.ts +135 -5
- 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 +122 -42
- package/src/common/languageColors.json +18 -2
- package/src/common/languageColors.ts +1 -4
- package/src/common/ops.ts +31 -48
- package/src/common/render.ts +334 -284
- package/src/common/retryer.ts +8 -15
- package/src/fetchers/contributed-to.ts +271 -0
- package/src/fetchers/gist.ts +8 -12
- package/src/fetchers/graphql-error.ts +36 -0
- package/src/fetchers/index.ts +15 -12
- package/src/fetchers/repo.ts +27 -40
- package/src/fetchers/stats.ts +157 -366
- package/src/fetchers/top-languages.ts +27 -55
- package/src/fetchers/types.ts +27 -1
- package/src/fetchers/wakatime.ts +5 -9
- package/src/graphql/contributionsCollection.ts +18 -0
- package/src/graphql/contributionsDocument.ts +14 -19
- package/src/graphql/generated/contributed-to.ts +25 -0
- package/src/graphql/generated/gist.ts +1 -1
- package/src/graphql/generated/repo.ts +1 -1
- package/src/graphql/generated/stats.ts +21 -8
- package/src/graphql/generated/top-languages.ts +2 -2
- package/src/graphql/graphqlDocument.ts +1 -2
- package/src/graphql/queries/contributed-to.graphql +8 -0
- package/src/graphql/queries/stats.graphql +14 -2
- package/src/graphql/reposContributedToDocument.ts +16 -15
- 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 +699 -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,22 +40,14 @@ const parseArray = (str: string | undefined): Array<string> => {
|
|
|
42
40
|
/**
|
|
43
41
|
* Clamp the given number between the given range.
|
|
44
42
|
*
|
|
45
|
-
* @
|
|
46
|
-
* @param min The minimum value.
|
|
47
|
-
* @param max The maximum value.
|
|
48
|
-
* @returns The clamped number.
|
|
43
|
+
* @returns The clamped number; `min` for `NaN`.
|
|
49
44
|
*/
|
|
50
|
-
const clampValue = (number:
|
|
51
|
-
|
|
52
|
-
return min;
|
|
53
|
-
}
|
|
54
|
-
return Math.max(min, Math.min(Number(number), max));
|
|
55
|
-
};
|
|
45
|
+
const clampValue = (number: number, min: number, max: number): number =>
|
|
46
|
+
Number.isNaN(number) ? min : Math.max(min, Math.min(number, max));
|
|
56
47
|
|
|
57
48
|
/**
|
|
58
49
|
* Lowercase and trim string.
|
|
59
50
|
*
|
|
60
|
-
* @param name String to lowercase and trim.
|
|
61
51
|
* @returns Lowercased and trimmed string.
|
|
62
52
|
*/
|
|
63
53
|
const lowercaseTrim = (name: string): string => name.toLowerCase().trim();
|
|
@@ -65,34 +55,33 @@ const lowercaseTrim = (name: string): string => name.toLowerCase().trim();
|
|
|
65
55
|
/**
|
|
66
56
|
* Split array of languages in two columns.
|
|
67
57
|
*
|
|
68
|
-
* @template T Language object.
|
|
69
|
-
* @param arr Array of languages.
|
|
70
|
-
* @param perChunk Number of languages per column.
|
|
71
58
|
* @returns Array of languages split in two columns.
|
|
72
59
|
*/
|
|
73
60
|
const chunkArray = <T>(arr: Array<T>, perChunk: number): Array<Array<T>> => {
|
|
74
|
-
|
|
61
|
+
const chunks: Array<Array<T>> = [];
|
|
62
|
+
for (const [index, item] of arr.entries()) {
|
|
75
63
|
const chunkIndex = Math.floor(index / perChunk);
|
|
76
|
-
const chunk =
|
|
64
|
+
const chunk = chunks[chunkIndex] ?? [];
|
|
77
65
|
chunk.push(item);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
66
|
+
chunks[chunkIndex] = chunk;
|
|
67
|
+
}
|
|
68
|
+
return chunks;
|
|
81
69
|
};
|
|
82
70
|
|
|
83
71
|
/**
|
|
84
72
|
* Parse emoji from string.
|
|
85
73
|
*
|
|
86
|
-
* @param str String to parse emoji from.
|
|
87
74
|
* @returns String with emoji parsed.
|
|
88
75
|
*/
|
|
89
76
|
const parseEmojis = (str: string): string => {
|
|
90
77
|
if (!str) {
|
|
91
78
|
throw new Error('[parseEmoji]: str argument not provided');
|
|
92
79
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
80
|
+
// `+` and `-` are part of a shortcode: `:+1:`, `:non-potable_water:`.
|
|
81
|
+
return str.replaceAll(
|
|
82
|
+
/:(?<shortcode>[\w+-]+):/g,
|
|
83
|
+
(_match, shortcode: string) => getEmoji(shortcode) ?? '',
|
|
84
|
+
);
|
|
96
85
|
};
|
|
97
86
|
|
|
98
87
|
const isOwnerAffiliation = (value: string): value is RepositoryAffiliation =>
|
|
@@ -101,37 +90,31 @@ const isOwnerAffiliation = (value: string): value is RepositoryAffiliation =>
|
|
|
101
90
|
/**
|
|
102
91
|
* Parse owner affiliations.
|
|
103
92
|
*
|
|
104
|
-
* @param affiliations input affiliations to be parsed.
|
|
105
|
-
* @returns Parsed affiliations.
|
|
106
|
-
*
|
|
107
93
|
* @throws {CardError} If affiliations contains invalid values.
|
|
94
|
+
*
|
|
95
|
+
* @returns Parsed affiliations.
|
|
108
96
|
*/
|
|
109
97
|
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.
|
|
98
|
+
// `parseArray` returns an empty array for an absent param, so the default lands here.
|
|
113
99
|
const normalized =
|
|
114
100
|
affiliations.length > 0
|
|
115
101
|
? affiliations.map((affiliation) => affiliation.toUpperCase())
|
|
116
102
|
: ['OWNER'];
|
|
117
103
|
|
|
118
104
|
// Check if ownerAffiliations contains valid values.
|
|
119
|
-
if (!normalized.every(isOwnerAffiliation)) {
|
|
105
|
+
if (!normalized.every((value) => isOwnerAffiliation(value))) {
|
|
120
106
|
throw CardError.invalidParam('role', INVALID_AFFILIATION);
|
|
121
107
|
}
|
|
122
108
|
return normalized;
|
|
123
109
|
};
|
|
124
110
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
Array.isArray(owners) && owners.length > 0 ? owners.map((o) => `owner:${o} `).join('') : '';
|
|
133
|
-
return repoFilter + orgFilter;
|
|
134
|
-
};
|
|
111
|
+
/**
|
|
112
|
+
* The qualifiers that scope a REST search to repositories and owners.
|
|
113
|
+
*
|
|
114
|
+
* @returns e.g. `repo:a/b owner:c `, each qualifier followed by a space; empty when both lists are.
|
|
115
|
+
*/
|
|
116
|
+
const buildSearchFilter = (repos: Array<string>, owners: Array<string>): string =>
|
|
117
|
+
[...repos.map((repo) => `repo:${repo} `), ...owners.map((owner) => `owner:${owner} `)].join('');
|
|
135
118
|
|
|
136
119
|
export {
|
|
137
120
|
parseBoolean,
|