@stats-forge/github-stats-forge-core 0.0.1 → 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
@@ -1,34 +1,27 @@
1
1
  import { isThemeName, themes } from '../themes/index.js';
2
2
  /** Matches a 3-, 4-, 6-, or 8-digit hex color with no leading `#`. */
3
- const HEX_COLOR = /^([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{3})$/;
3
+ const HEX_COLOR = /^(?<digits>[A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{3})$/;
4
4
  /**
5
5
  * Checks if a value is a bare hex color, i.e. hex digits with no `#` prefix
6
6
  * (`"f00"`, `"ffffff"`). This is the form user-supplied color params and
7
7
  * gradient stops arrive in.
8
8
  *
9
- * @param value Value to check.
10
9
  * @returns True if the value is a bare hex color.
11
10
  */
12
- const isBareHexColor = (value) => {
13
- return typeof value === 'string' && HEX_COLOR.test(value);
14
- };
11
+ const isBareHexColor = (value) => typeof value === 'string' && HEX_COLOR.test(value);
15
12
  /**
16
13
  * Checks if a value is a `#`-prefixed hex color (`"#f00"`, `"#ffffff"`). This
17
14
  * is the form colors take once resolved by {@link getCardColors}, i.e. right
18
15
  * before they are written into the SVG.
19
16
  *
20
- * @param value Value to check.
21
17
  * @returns True if the value is a `#`-prefixed hex color.
22
18
  */
23
- const isPrefixedHexColor = (value) => {
24
- return typeof value === 'string' && value.startsWith('#') && HEX_COLOR.test(value.slice(1));
25
- };
19
+ const isPrefixedHexColor = (value) => typeof value === 'string' && value.startsWith('#') && HEX_COLOR.test(value.slice(1));
26
20
  /**
27
21
  * Checks if the given parts form a valid gradient: a finite numeric angle
28
22
  * followed by at least two bare-hex color stops, e.g. `["90", "f00", "0f0"]`.
29
23
  * The angle is written into the SVG `gradientTransform="rotate(...)"`.
30
24
  *
31
- * @param parts Gradient parts: `[angle, ...stops]`.
32
25
  * @returns True if the parts form a valid gradient.
33
26
  */
34
27
  const isValidGradient = (parts) => {
@@ -37,12 +30,11 @@ const isValidGradient = (parts) => {
37
30
  angle !== undefined &&
38
31
  angle.trim() !== '' &&
39
32
  Number.isFinite(Number(angle)) &&
40
- stops.every(isBareHexColor));
33
+ stops.every((stop) => isBareHexColor(stop)));
41
34
  };
42
35
  /**
43
36
  * Checks if a string is a valid input for a color or gradient.
44
37
  *
45
- * @param color String to check, may be null or undefined.
46
38
  * @returns True if the given string is a valid input.
47
39
  */
48
40
  const isValidColorInput = (color) => {
@@ -54,11 +46,9 @@ const isValidColorInput = (color) => {
54
46
  /**
55
47
  * Retrieves a gradient if color has more than one valid hex codes else a single color.
56
48
  *
57
- * @param color The color to parse.
58
- * @param fallbackColor The fallback color.
59
49
  * @returns The gradient or color.
60
50
  */
61
- const fallbackColor = (color, fallbackColor) => {
51
+ const fallbackColor = (color, fallback) => {
62
52
  const colors = color ? color.split(',') : [];
63
53
  if (colors.length > 1 && isValidGradient(colors)) {
64
54
  return colors;
@@ -66,7 +56,39 @@ const fallbackColor = (color, fallbackColor) => {
66
56
  if (color !== undefined && isBareHexColor(color)) {
67
57
  return `#${color}`;
68
58
  }
69
- return fallbackColor;
59
+ return fallback;
60
+ };
61
+ /** Border a light background gets when neither the user nor the theme names one. */
62
+ const LIGHT_BG_BORDER = '#0000001f';
63
+ /** Border a dark background gets when neither the user nor the theme names one. */
64
+ const DARK_BG_BORDER = '#ffffff26';
65
+ /** Border a see-through background gets: neutral, since the page behind it decides the contrast. */
66
+ const TRANSLUCENT_BG_BORDER = '#8b949e59';
67
+ /**
68
+ * @returns Its `[r, g, b, a]` channels, each on 0–1.
69
+ */
70
+ const hexChannels = (hex) => {
71
+ const digits = hex.slice(1);
72
+ const expanded = digits.length <= 4 ? [...digits].map((digit) => digit + digit).join('') : digits;
73
+ const channel = (index) => Number.parseInt(expanded.slice(index * 2, index * 2 + 2), 16) / 255;
74
+ return [channel(0), channel(1), channel(2), expanded.length === 8 ? channel(3) : 1];
75
+ };
76
+ /**
77
+ * Derives a border from the background, so a dark card never gets a light hairline.
78
+ *
79
+ * @returns A translucent `#`-prefixed hex border color.
80
+ */
81
+ const borderColorFor = (bgColor) => {
82
+ // A gradient is judged by its first stop.
83
+ const hex = typeof bgColor === 'string' ? bgColor : `#${bgColor[1] ?? ''}`;
84
+ if (!isPrefixedHexColor(hex)) {
85
+ return LIGHT_BG_BORDER;
86
+ }
87
+ const [r, g, b, a] = hexChannels(hex);
88
+ if (a < 0.5) {
89
+ return TRANSLUCENT_BG_BORDER;
90
+ }
91
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b < 0.5 ? DARK_BG_BORDER : LIGHT_BG_BORDER;
70
92
  };
71
93
  /**
72
94
  * Every color param a card accepts, before any `_light` / `_dark` suffix.
@@ -88,30 +110,18 @@ const THEME_VARIANTS = ['light', 'dark'];
88
110
  /**
89
111
  * Returns theme based colors with proper overrides and defaults.
90
112
  *
91
- * @param props Function arguments.
92
- * @param props.title_color Card title color.
93
- * @param props.text_color Card text color.
94
- * @param props.icon_color Card icon color.
95
- * @param props.bg_color Card background color.
96
- * @param props.border_color Card border color.
97
- * @param props.ring_color Card ring color.
98
- * @param props.prog_bar_bg_color Progress bar background color.
99
- * @param props.theme Card theme.
100
113
  * @returns Card colors.
101
114
  */
102
115
  const getCardColors = ({ title_color, text_color, icon_color, bg_color, border_color, ring_color, prog_bar_bg_color, theme, }) => {
103
116
  const defaultTheme = themes.default;
104
117
  const selectedTheme = isThemeName(theme) ? themes[theme] : defaultTheme;
105
- const defaultBorderColor = 'border_color' in selectedTheme ? selectedTheme.border_color : defaultTheme.border_color;
106
- // get the color provided by the user else the theme color
107
- // finally if both colors are invalid fallback to default theme
108
- const titleColor = fallbackColor(title_color || selectedTheme.title_color, '#' + defaultTheme.title_color);
109
- // get the color provided by the user else the theme color
110
- // finally if both colors are invalid we use the titleColor
111
- const iconColor = fallbackColor(icon_color || selectedTheme.icon_color, '#' + defaultTheme.icon_color);
112
- const textColor = fallbackColor(text_color || selectedTheme.text_color, '#' + defaultTheme.text_color);
113
- const bgColor = fallbackColor(bg_color || selectedTheme.bg_color, '#' + defaultTheme.bg_color);
114
- const borderColor = fallbackColor(border_color || defaultBorderColor, '#' + defaultBorderColor);
118
+ const themeBorderColor = 'border_color' in selectedTheme ? selectedTheme.border_color : undefined;
119
+ // Each color is the user's, else the selected theme's, else the default theme's.
120
+ const titleColor = fallbackColor(title_color || selectedTheme.title_color, `#${defaultTheme.title_color}`);
121
+ const iconColor = fallbackColor(icon_color || selectedTheme.icon_color, `#${defaultTheme.icon_color}`);
122
+ const textColor = fallbackColor(text_color || selectedTheme.text_color, `#${defaultTheme.text_color}`);
123
+ const bgColor = fallbackColor(bg_color || selectedTheme.bg_color, `#${defaultTheme.bg_color}`);
124
+ const borderColor = fallbackColor(border_color || themeBorderColor, borderColorFor(bgColor));
115
125
  // No theme defines `ring_color`, so it falls back to the title color.
116
126
  const ringColor = fallbackColor(ring_color, titleColor);
117
127
  // No theme defines `prog_bar_bg_color`, so it falls back to "#ddd".
@@ -122,7 +132,7 @@ const getCardColors = ({ title_color, text_color, icon_color, bg_color, border_c
122
132
  typeof progBarBgColor !== 'string' ||
123
133
  typeof iconColor !== 'string' ||
124
134
  typeof borderColor !== 'string') {
125
- throw new Error('Unexpected behavior, all colors except background should be string.');
135
+ throw new TypeError('Unexpected behavior, all colors except background should be string.');
126
136
  }
127
137
  return {
128
138
  titleColor,
@@ -138,11 +148,23 @@ const getCardColors = ({ title_color, text_color, icon_color, bg_color, border_c
138
148
  * Returns the light- or dark-mode-specific color params, given a set of
139
149
  * raw query params. Also removes the "_light" or "_dark" suffixes.
140
150
  *
141
- * @param params Raw query params with optional `_light` / `_dark` suffixes.
142
- * @param suffix `"_light"` or `"_dark"`.
143
151
  * @returns ColorInput with the suffix stripped, ready for `getCardColors`.
144
152
  */
145
- const extractLightDarkColors = (params, suffix) => Object.fromEntries(BASE_COLOR_KEYS.map((key) => [key, params[`${key}${suffix}`]]));
153
+ const extractLightDarkColors = (params, suffix) => {
154
+ const colors = {};
155
+ for (const key of BASE_COLOR_KEYS) {
156
+ const value = params[`${key}${suffix}`];
157
+ if (value !== undefined) {
158
+ colors[key] = value;
159
+ }
160
+ }
161
+ return colors;
162
+ };
163
+ /**
164
+ * Every suffixed key, so asking "any per-scheme colors at all?" is one pass over names,
165
+ * not two objects built to be thrown away.
166
+ */
167
+ const MODE_OVERRIDE_KEYS = THEME_VARIANTS.flatMap((variant) => BASE_COLOR_KEYS.map((key) => `${key}_${variant}`));
146
168
  /**
147
169
  * Returns resolved colors for both light and dark mode given all input params.
148
170
  *
@@ -154,23 +176,19 @@ const extractLightDarkColors = (params, suffix) => Object.fromEntries(BASE_COLOR
154
176
  * Anything a mode does not override falls back to the general params,
155
177
  * so a partial override such as `bg_color_dark` alone keeps every other color from the base theme.
156
178
  *
157
- * When no `_light` / `_dark` param is provided at all, `darkColors` is `null` and the caller emits no dark-mode block.
179
+ * When no `_light` / `_dark` param is provided at all,
180
+ * `darkColors` is `null` and the caller emits no dark-mode block.
158
181
  *
159
- * @param params Raw query params, containing both general and `_light`/`_dark` suffixed colors and themes.
160
182
  * @returns `{ lightColors, darkColors }`, resolved colors for both light and dark mode
161
183
  */
162
184
  const getLightDarkColors = (params) => {
163
- const lightOverrides = extractLightDarkColors(params, '_light');
164
- const darkOverrides = extractLightDarkColors(params, '_dark');
165
- const hasModeOverrides = Object.values(lightOverrides).some((v) => v !== undefined) ||
166
- Object.values(darkOverrides).some((v) => v !== undefined);
167
- if (!hasModeOverrides) {
185
+ // The common case is no per-scheme params at all, so it never builds the overrides.
186
+ if (!MODE_OVERRIDE_KEYS.some((key) => params[key] !== undefined)) {
168
187
  return { lightColors: getCardColors(params), darkColors: null };
169
188
  }
170
- const defined = (obj) => Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined));
171
189
  return {
172
- lightColors: getCardColors({ ...params, ...defined(lightOverrides) }),
173
- darkColors: getCardColors({ ...params, ...defined(darkOverrides) }),
190
+ lightColors: getCardColors({ ...params, ...extractLightDarkColors(params, '_light') }),
191
+ darkColors: getCardColors({ ...params, ...extractLightDarkColors(params, '_dark') }),
174
192
  };
175
193
  };
176
194
  const COLOR_PARAM_KEYS = [
@@ -1,4 +1,4 @@
1
- import type { FetchLike } from './http.js';
1
+ import type { FetchLike } from './http.ts';
2
2
  type Env = Record<string, string | undefined>;
3
3
  interface PersonalAccessToken {
4
4
  /** Env variable the token came from — the retryer logs this name, never the value. */
@@ -32,21 +32,11 @@ export declare class CardConfig {
32
32
  /** Transport every fetcher sends through; defaults to `globalThis.fetch`. */
33
33
  readonly fetch: FetchLike;
34
34
  constructor(init?: CardConfigInit);
35
- /**
36
- * @param env Environment variables to read — the host passes `process.env` or an equivalent.
37
- * @returns Config for this deployment.
38
- */
35
+ /** @returns Config for this deployment. */
39
36
  static fromEnv(env: Env): CardConfig;
40
- /**
41
- * @param id Username or gist id being requested.
42
- * @param kind Which allowlist applies.
43
- * @returns Whether this deployment serves the id.
44
- */
37
+ /** @returns Whether this deployment serves the id. */
45
38
  isAllowed(id: string, kind: 'username' | 'gist'): boolean;
46
- /**
47
- * @param overrides Fields to replace.
48
- * @returns A copy with `overrides` applied — how a host swaps in a user's PAT per request.
49
- */
39
+ /** @returns A copy with `overrides` applied — how a host swaps in a user's PAT per request. */
50
40
  with(overrides: CardConfigInit): CardConfig;
51
41
  }
52
42
  export type { PersonalAccessToken, CardConfigInit };
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/common/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAE9C,UAAU,mBAAmB;IAC3B,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qFAAqF;AACrF,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC;IAC1C,iBAAiB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACtD,aAAa,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAClD,mBAAmB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC5C,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AA8BD;;;;;GAKG;AACH,qBAAa,UAAU;IACrB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC;IAClD,oEAAoE;IACpE,QAAQ,CAAC,iBAAiB,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAC9D,mEAAmE;IACnE,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAC1D,QAAQ,CAAC,mBAAmB,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACpD,mFAAmF;IACnF,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;gBAEd,IAAI,GAAE,cAAmB;IASrC;;;OAGG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,UAAU;IAUpC;;;;OAIG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO;IAKzD;;;OAGG;IACH,IAAI,CAAC,SAAS,EAAE,cAAc,GAAG,UAAU;CAW5C;AAED,YAAY,EAAE,mBAAmB,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/common/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAE9C,UAAU,mBAAmB;IAC3B,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qFAAqF;AACrF,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC;IAC1C,iBAAiB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACtD,aAAa,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAClD,mBAAmB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC5C,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AA2BD;;;;;GAKG;AACH,qBAAa,UAAU;IACrB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC;IAClD,oEAAoE;IACpE,QAAQ,CAAC,iBAAiB,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAC9D,mEAAmE;IACnE,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAC1D,QAAQ,CAAC,mBAAmB,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACpD,mFAAmF;IACnF,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAE1B,YAAY,IAAI,GAAE,cAAmB,EAOpC;IAED,2CAA2C;IAC3C,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,UAAU,CAQnC;IAED,sDAAsD;IACtD,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO,CAGxD;IAED,+FAA+F;IAC/F,IAAI,CAAC,SAAS,EAAE,cAAc,GAAG,UAAU,CAU1C;CACF;AAED,YAAY,EAAE,mBAAmB,EAAE,cAAc,EAAE,CAAC"}
@@ -1,11 +1,9 @@
1
1
  import { defaultFetch } from './http.js';
2
2
  /**
3
- * @param value Comma-separated string.
4
3
  * @returns Parsed string values.
5
4
  */
6
5
  const parseCsv = (value) => value ? value.split(',') : undefined;
7
6
  /**
8
- * @param value Raw `FETCH_MULTI_PAGE_STARS` value.
9
7
  * @returns Page limit: `"true"` means every page, a positive number caps the pages, anything else means one.
10
8
  */
11
9
  const parseFetchMultiPageStars = (value) => {
@@ -16,7 +14,6 @@ const parseFetchMultiPageStars = (value) => {
16
14
  return limit > 0 ? limit : 1;
17
15
  };
18
16
  /**
19
- * @param env Environment variables to inspect.
20
17
  * @returns Personal access tokens found in the environment.
21
18
  */
22
19
  const parsePATsFromEnv = (env) => Object.keys(env)
@@ -47,10 +44,7 @@ export class CardConfig {
47
44
  this.fetchMultiPageStars = init.fetchMultiPageStars ?? 1;
48
45
  this.fetch = init.fetch ?? defaultFetch;
49
46
  }
50
- /**
51
- * @param env Environment variables to read — the host passes `process.env` or an equivalent.
52
- * @returns Config for this deployment.
53
- */
47
+ /** @returns Config for this deployment. */
54
48
  static fromEnv(env) {
55
49
  return new CardConfig({
56
50
  pats: parsePATsFromEnv(env),
@@ -60,19 +54,12 @@ export class CardConfig {
60
54
  fetchMultiPageStars: parseFetchMultiPageStars(env['FETCH_MULTI_PAGE_STARS']),
61
55
  });
62
56
  }
63
- /**
64
- * @param id Username or gist id being requested.
65
- * @param kind Which allowlist applies.
66
- * @returns Whether this deployment serves the id.
67
- */
57
+ /** @returns Whether this deployment serves the id. */
68
58
  isAllowed(id, kind) {
69
59
  const list = kind === 'gist' ? this.gistAllowlist : this.usernameAllowlist;
70
60
  return list === undefined || list.includes(id);
71
61
  }
72
- /**
73
- * @param overrides Fields to replace.
74
- * @returns A copy with `overrides` applied — how a host swaps in a user's PAT per request.
75
- */
62
+ /** @returns A copy with `overrides` applied — how a host swaps in a user's PAT per request. */
76
63
  with(overrides) {
77
64
  return new CardConfig({
78
65
  pats: this.pats,
@@ -1,7 +1,9 @@
1
- import type { RepositoryAffiliation } from '../graphql/generated/common.js';
1
+ import type { RepositoryAffiliation } from '../graphql/generated/common.ts';
2
+ /** A GitHub login: alphanumerics and single inner hyphens, 39 characters at most. */
3
+ declare const GITHUB_USERNAME_PATTERN: RegExp;
2
4
  /**
3
5
  * Valid owner affiliations for GitHub API queries.
4
6
  */
5
7
  declare const OWNER_AFFILIATIONS: Array<RepositoryAffiliation>;
6
- export { OWNER_AFFILIATIONS };
8
+ export { GITHUB_USERNAME_PATTERN, OWNER_AFFILIATIONS };
7
9
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAE5E;;GAEG;AACH,QAAA,MAAM,kBAAkB,EAAE,KAAK,CAAC,qBAAqB,CAIpD,CAAC;AAEF,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAE5E,qFAAqF;AACrF,QAAA,MAAM,uBAAuB,QAA6C,CAAC;AAE3E;;GAEG;AACH,QAAA,MAAM,kBAAkB,EAAE,KAAK,CAAC,qBAAqB,CAIpD,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,CAAC"}
@@ -1,3 +1,5 @@
1
+ /** A GitHub login: alphanumerics and single inner hyphens, 39 characters at most. */
2
+ const GITHUB_USERNAME_PATTERN = /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i;
1
3
  /**
2
4
  * Valid owner affiliations for GitHub API queries.
3
5
  */
@@ -6,4 +8,4 @@ const OWNER_AFFILIATIONS = [
6
8
  'COLLABORATOR',
7
9
  'ORGANIZATION_MEMBER',
8
10
  ];
9
- export { OWNER_AFFILIATIONS };
11
+ export { GITHUB_USERNAME_PATTERN, OWNER_AFFILIATIONS };
@@ -9,7 +9,6 @@ interface GitHubDateRange {
9
9
  * Format a date as a GitHub `DateTime` scalar.
10
10
  * Seconds precision, no milliseconds.
11
11
  *
12
- * @param date Date to format.
13
12
  * @returns e.g. `2024-01-01T00:00:00Z`.
14
13
  */
15
14
  declare const toGitHubDateTime: (date: Date) => string;
@@ -20,7 +19,6 @@ declare const toGitHubDateTime: (date: Date) => string;
20
19
  * GitHub's `contributionsCollection` defaults `to` to one year after `from`,
21
20
  * which pulls the next 1st of January into the year.
22
21
  *
23
- * @param year Four-digit year.
24
22
  * @returns The range covering it.
25
23
  */
26
24
  declare const getGitHubYearRange: (year: number) => GitHubDateRange;
@@ -1 +1 @@
1
- {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/common/date.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,UAAU,eAAe;IACvB,qCAAqC;IACrC,IAAI,EAAE,IAAI,CAAC;IACX,mCAAmC;IACnC,EAAE,EAAE,IAAI,CAAC;CACV;AAED;;;;;;GAMG;AACH,QAAA,MAAM,gBAAgB,GAAI,MAAM,IAAI,KAAG,MAA+C,CAAC;AAEvF;;;;;;;;;GASG;AACH,QAAA,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,eAGzC,CAAC;AAEH,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,CAAC;AAChD,YAAY,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/common/date.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,UAAU,eAAe;IACvB,qCAAqC;IACrC,IAAI,EAAE,IAAI,CAAC;IACX,mCAAmC;IACnC,EAAE,EAAE,IAAI,CAAC;CACV;AAED;;;;;GAKG;AACH,QAAA,MAAM,gBAAgB,SAAU,IAAI,KAAG,MAA+C,CAAC;AAEvF;;;;;;;;GAQG;AACH,QAAA,MAAM,kBAAkB,SAAU,MAAM,KAAG,eAGzC,CAAC;AAEH,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,CAAC;AAChD,YAAY,EAAE,eAAe,EAAE,CAAC"}
@@ -2,7 +2,6 @@
2
2
  * Format a date as a GitHub `DateTime` scalar.
3
3
  * Seconds precision, no milliseconds.
4
4
  *
5
- * @param date Date to format.
6
5
  * @returns e.g. `2024-01-01T00:00:00Z`.
7
6
  */
8
7
  const toGitHubDateTime = (date) => `${date.toISOString().slice(0, 19)}Z`;
@@ -13,7 +12,6 @@ const toGitHubDateTime = (date) => `${date.toISOString().slice(0, 19)}Z`;
13
12
  * GitHub's `contributionsCollection` defaults `to` to one year after `from`,
14
13
  * which pulls the next 1st of January into the year.
15
14
  *
16
- * @param year Four-digit year.
17
15
  * @returns The range covering it.
18
16
  */
19
17
  const getGitHubYearRange = (year) => ({
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Resolves a GitHub emoji shortcode to its unicode character.
3
+ *
4
+ * @returns The emoji, or `undefined` when GitHub has no such shortcode.
5
+ */
6
+ declare const getEmoji: (name: string) => string | undefined;
7
+ export { getEmoji };
8
+ //# sourceMappingURL=emojiMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emojiMap.d.ts","sourceRoot":"","sources":["../../src/common/emojiMap.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,QAAA,MAAM,QAAQ,SAAU,MAAM,KAAG,MAAM,GAAG,SAA2B,CAAC;AAEtE,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,10 @@
1
+ import emojiMapJson from './emojiMap.json' with { type: 'json' };
2
+ // The generated JSON types has literal keys; index it as a plain lookup table.
3
+ const emojiMap = emojiMapJson;
4
+ /**
5
+ * Resolves a GitHub emoji shortcode to its unicode character.
6
+ *
7
+ * @returns The emoji, or `undefined` when GitHub has no such shortcode.
8
+ */
9
+ const getEmoji = (name) => emojiMap[name];
10
+ export { getEmoji };