@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.
Files changed (208) hide show
  1. package/README.md +0 -10
  2. package/build/api/api-result.d.ts +6 -7
  3. package/build/api/api-result.d.ts.map +1 -1
  4. package/build/api/api-result.js +4 -5
  5. package/build/api/gist.d.ts +3 -10
  6. package/build/api/gist.d.ts.map +1 -1
  7. package/build/api/gist.js +4 -11
  8. package/build/api/index.d.ts +12 -12
  9. package/build/api/params.d.ts +11 -8
  10. package/build/api/params.d.ts.map +1 -1
  11. package/build/api/params.js +16 -14
  12. package/build/api/pin.d.ts +3 -19
  13. package/build/api/pin.d.ts.map +1 -1
  14. package/build/api/pin.js +6 -22
  15. package/build/api/stats.d.ts +10 -4
  16. package/build/api/stats.d.ts.map +1 -1
  17. package/build/api/stats.js +6 -32
  18. package/build/api/top-langs.d.ts +12 -6
  19. package/build/api/top-langs.d.ts.map +1 -1
  20. package/build/api/top-langs.js +6 -26
  21. package/build/api/wakatime.d.ts +13 -5
  22. package/build/api/wakatime.d.ts.map +1 -1
  23. package/build/api/wakatime.js +4 -21
  24. package/build/calculateRank.d.ts +0 -9
  25. package/build/calculateRank.d.ts.map +1 -1
  26. package/build/calculateRank.js +12 -17
  27. package/build/cards/gist.d.ts +2 -4
  28. package/build/cards/gist.d.ts.map +1 -1
  29. package/build/cards/gist.js +27 -36
  30. package/build/cards/options.d.ts +1 -1
  31. package/build/cards/repo.d.ts +2 -4
  32. package/build/cards/repo.d.ts.map +1 -1
  33. package/build/cards/repo.js +61 -93
  34. package/build/cards/stats.d.ts +3 -8
  35. package/build/cards/stats.d.ts.map +1 -1
  36. package/build/cards/stats.js +119 -165
  37. package/build/cards/top-languages.d.ts +5 -31
  38. package/build/cards/top-languages.d.ts.map +1 -1
  39. package/build/cards/top-languages.js +176 -384
  40. package/build/cards/wakatime.d.ts +4 -6
  41. package/build/cards/wakatime.d.ts.map +1 -1
  42. package/build/cards/wakatime.js +118 -185
  43. package/build/common/Card.d.ts +14 -62
  44. package/build/common/Card.d.ts.map +1 -1
  45. package/build/common/Card.js +97 -199
  46. package/build/common/I18n.d.ts +0 -6
  47. package/build/common/I18n.d.ts.map +1 -1
  48. package/build/common/I18n.js +3 -6
  49. package/build/common/color.d.ts +4 -17
  50. package/build/common/color.d.ts.map +1 -1
  51. package/build/common/color.js +67 -49
  52. package/build/common/config.d.ts +4 -14
  53. package/build/common/config.d.ts.map +1 -1
  54. package/build/common/config.js +3 -16
  55. package/build/common/constants.d.ts +4 -2
  56. package/build/common/constants.d.ts.map +1 -1
  57. package/build/common/constants.js +3 -1
  58. package/build/common/date.d.ts +0 -2
  59. package/build/common/date.d.ts.map +1 -1
  60. package/build/common/date.js +0 -2
  61. package/build/common/emojiMap.d.ts +8 -0
  62. package/build/common/emojiMap.d.ts.map +1 -0
  63. package/build/common/emojiMap.js +10 -0
  64. package/build/common/emojiMap.json +1915 -0
  65. package/build/common/error.d.ts +1 -10
  66. package/build/common/error.d.ts.map +1 -1
  67. package/build/common/error.js +1 -10
  68. package/build/common/fmt.d.ts +3 -15
  69. package/build/common/fmt.d.ts.map +1 -1
  70. package/build/common/fmt.js +7 -35
  71. package/build/common/http.d.ts +2 -7
  72. package/build/common/http.d.ts.map +1 -1
  73. package/build/common/http.js +8 -17
  74. package/build/common/icons.d.ts +18 -20
  75. package/build/common/icons.d.ts.map +1 -1
  76. package/build/common/icons.js +103 -67
  77. package/build/common/languageColors.d.ts +0 -1
  78. package/build/common/languageColors.d.ts.map +1 -1
  79. package/build/common/languageColors.js +1 -4
  80. package/build/common/languageColors.json +18 -2
  81. package/build/common/ops.d.ts +3 -14
  82. package/build/common/ops.d.ts.map +1 -1
  83. package/build/common/ops.js +19 -30
  84. package/build/common/render.d.ts +28 -82
  85. package/build/common/render.d.ts.map +1 -1
  86. package/build/common/render.js +175 -211
  87. package/build/common/retryer.d.ts +2 -7
  88. package/build/common/retryer.d.ts.map +1 -1
  89. package/build/common/retryer.js +4 -11
  90. package/build/fetchers/gist.d.ts +2 -5
  91. package/build/fetchers/gist.d.ts.map +1 -1
  92. package/build/fetchers/gist.js +1 -5
  93. package/build/fetchers/index.d.ts +12 -12
  94. package/build/fetchers/repo.d.ts +2 -11
  95. package/build/fetchers/repo.d.ts.map +1 -1
  96. package/build/fetchers/repo.js +20 -33
  97. package/build/fetchers/stats.d.ts +2 -32
  98. package/build/fetchers/stats.d.ts.map +1 -1
  99. package/build/fetchers/stats.js +27 -86
  100. package/build/fetchers/top-languages.d.ts +2 -9
  101. package/build/fetchers/top-languages.d.ts.map +1 -1
  102. package/build/fetchers/top-languages.js +15 -31
  103. package/build/fetchers/types.d.ts +1 -1
  104. package/build/fetchers/wakatime.d.ts +2 -6
  105. package/build/fetchers/wakatime.d.ts.map +1 -1
  106. package/build/fetchers/wakatime.js +1 -5
  107. package/build/graphql/contributionsDocument.d.ts +3 -3
  108. package/build/graphql/contributionsDocument.d.ts.map +1 -1
  109. package/build/graphql/contributionsDocument.js +0 -1
  110. package/build/graphql/generated/gist.d.ts +1 -1
  111. package/build/graphql/generated/repo.d.ts +1 -1
  112. package/build/graphql/generated/stats.d.ts +3 -3
  113. package/build/graphql/generated/top-languages.d.ts +2 -2
  114. package/build/graphql/graphqlDocument.d.ts +0 -1
  115. package/build/graphql/graphqlDocument.d.ts.map +1 -1
  116. package/build/graphql/graphqlDocument.js +0 -1
  117. package/build/graphql/reposContributedToDocument.d.ts +4 -5
  118. package/build/graphql/reposContributedToDocument.d.ts.map +1 -1
  119. package/build/graphql/reposContributedToDocument.js +0 -2
  120. package/build/markup/css.d.ts +35 -0
  121. package/build/markup/css.d.ts.map +1 -0
  122. package/build/markup/css.js +64 -0
  123. package/build/markup/element.d.ts +41 -0
  124. package/build/markup/element.d.ts.map +1 -0
  125. package/build/markup/element.js +127 -0
  126. package/build/markup/html.d.ts +13 -0
  127. package/build/markup/html.d.ts.map +1 -0
  128. package/build/markup/html.js +27 -0
  129. package/build/markup/index.d.ts +9 -0
  130. package/build/markup/index.d.ts.map +1 -0
  131. package/build/markup/index.js +6 -0
  132. package/build/markup/serialize.d.ts +16 -0
  133. package/build/markup/serialize.d.ts.map +1 -0
  134. package/build/markup/serialize.js +17 -0
  135. package/build/themes/index.d.ts +332 -333
  136. package/build/themes/index.d.ts.map +1 -1
  137. package/build/themes/index.js +1 -1
  138. package/build/translations.d.ts +2 -6
  139. package/build/translations.d.ts.map +1 -1
  140. package/build/translations.js +621 -628
  141. package/package.json +17 -26
  142. package/src/api/api-result.ts +10 -9
  143. package/src/api/gist.ts +11 -18
  144. package/src/api/index.ts +12 -12
  145. package/src/api/params.ts +27 -21
  146. package/src/api/pin.ts +13 -28
  147. package/src/api/stats.ts +13 -39
  148. package/src/api/top-langs.ts +13 -33
  149. package/src/api/wakatime.ts +11 -28
  150. package/src/calculateRank.ts +12 -23
  151. package/src/cards/gist.ts +40 -43
  152. package/src/cards/options.ts +1 -1
  153. package/src/cards/repo.ts +97 -107
  154. package/src/cards/stats.ts +165 -184
  155. package/src/cards/top-languages.ts +297 -413
  156. package/src/cards/wakatime.ts +193 -221
  157. package/src/common/Card.ts +165 -217
  158. package/src/common/I18n.ts +3 -6
  159. package/src/common/color.ts +80 -57
  160. package/src/common/config.ts +5 -18
  161. package/src/common/constants.ts +5 -2
  162. package/src/common/date.ts +0 -2
  163. package/src/common/emojiMap.json +1915 -0
  164. package/src/common/emojiMap.ts +13 -0
  165. package/src/common/error.ts +2 -11
  166. package/src/common/fmt.ts +7 -44
  167. package/src/common/http.ts +9 -15
  168. package/src/common/icons.ts +117 -42
  169. package/src/common/languageColors.json +18 -2
  170. package/src/common/languageColors.ts +1 -4
  171. package/src/common/ops.ts +26 -34
  172. package/src/common/render.ts +279 -232
  173. package/src/common/retryer.ts +8 -15
  174. package/src/fetchers/gist.ts +8 -12
  175. package/src/fetchers/index.ts +12 -12
  176. package/src/fetchers/repo.ts +27 -40
  177. package/src/fetchers/stats.ts +44 -102
  178. package/src/fetchers/top-languages.ts +26 -40
  179. package/src/fetchers/types.ts +1 -1
  180. package/src/fetchers/wakatime.ts +5 -9
  181. package/src/graphql/contributionsDocument.ts +7 -5
  182. package/src/graphql/generated/gist.ts +1 -1
  183. package/src/graphql/generated/repo.ts +1 -1
  184. package/src/graphql/generated/stats.ts +2 -2
  185. package/src/graphql/generated/top-languages.ts +2 -2
  186. package/src/graphql/graphqlDocument.ts +0 -1
  187. package/src/graphql/reposContributedToDocument.ts +6 -7
  188. package/src/markup/css.ts +118 -0
  189. package/src/markup/element.ts +246 -0
  190. package/src/markup/html.ts +34 -0
  191. package/src/markup/index.ts +9 -0
  192. package/src/markup/serialize.ts +27 -0
  193. package/src/themes/index.ts +1 -1
  194. package/src/translations.ts +622 -629
  195. package/build/cards/index.d.ts +0 -11
  196. package/build/cards/index.d.ts.map +0 -1
  197. package/build/cards/index.js +0 -7
  198. package/build/common/html.d.ts +0 -8
  199. package/build/common/html.d.ts.map +0 -1
  200. package/build/common/html.js +0 -14
  201. package/build/index.d.ts +0 -15
  202. package/build/index.d.ts.map +0 -1
  203. package/build/index.js +0 -10
  204. package/src/_emoji-name-map.d.ts +0 -10
  205. package/src/_github-username-regex.d.ts +0 -4
  206. package/src/cards/index.ts +0 -21
  207. package/src/common/html.ts +0 -17
  208. package/src/index.ts +0 -18
package/src/common/ops.ts CHANGED
@@ -1,14 +1,12 @@
1
- import toEmoji from 'emoji-name-map';
1
+ import type { RepositoryAffiliation } from '../graphql/generated/common.ts';
2
2
 
3
- import type { RepositoryAffiliation } from '../graphql/generated/common.js';
4
-
5
- import { OWNER_AFFILIATIONS } from './constants.js';
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
- } else if (value.toLowerCase() === 'false') {
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
- return arr.reduce<Array<Array<T>>>((resultArray, item, index) => {
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 = resultArray[chunkIndex] ?? [];
68
+ const chunk = chunks[chunkIndex] ?? [];
77
69
  chunk.push(item);
78
- resultArray[chunkIndex] = chunk;
79
- return resultArray;
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
- return str.replace(/:\w+:/gm, (emoji) => {
94
- return toEmoji.get(emoji) || '';
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
- // Set default value for ownerAffiliations.
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((r) => `repo:${r} `).join('') : '';
120
+ Array.isArray(repos) && repos.length > 0 ? repos.map((repo) => `repo:${repo} `).join('') : '';
131
121
  const orgFilter =
132
- Array.isArray(owners) && owners.length > 0 ? owners.map((o) => `owner:${o} `).join('') : '';
122
+ Array.isArray(owners) && owners.length > 0
123
+ ? owners.map((owner) => `owner:${owner} `).join('')
124
+ : '';
133
125
  return repoFilter + orgFilter;
134
126
  };
135
127