@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.
Files changed (182) hide show
  1. package/build/api/gist.d.ts +2 -7
  2. package/build/api/gist.d.ts.map +1 -1
  3. package/build/api/gist.js +28 -26
  4. package/build/api/index.d.ts +3 -8
  5. package/build/api/index.d.ts.map +1 -1
  6. package/build/api/index.js +32 -36
  7. package/build/api/pin.d.ts +2 -7
  8. package/build/api/pin.d.ts.map +1 -1
  9. package/build/api/pin.js +18 -33
  10. package/build/api/top-langs.d.ts +2 -7
  11. package/build/api/top-langs.d.ts.map +1 -1
  12. package/build/api/top-langs.js +32 -44
  13. package/build/api/wakatime.d.ts +2 -7
  14. package/build/api/wakatime.d.ts.map +1 -1
  15. package/build/api/wakatime.js +28 -26
  16. package/build/calculateRank.d.ts +12 -11
  17. package/build/calculateRank.d.ts.map +1 -1
  18. package/build/calculateRank.js +18 -18
  19. package/build/cards/common-options.d.ts +13 -0
  20. package/build/cards/common-options.d.ts.map +1 -0
  21. package/build/cards/common-options.js +1 -0
  22. package/build/cards/gist.d.ts +11 -16
  23. package/build/cards/gist.d.ts.map +1 -1
  24. package/build/cards/gist.js +26 -31
  25. package/build/cards/repo.d.ts +19 -16
  26. package/build/cards/repo.d.ts.map +1 -1
  27. package/build/cards/repo.js +79 -72
  28. package/build/cards/stats.d.ts +29 -44
  29. package/build/cards/stats.d.ts.map +1 -1
  30. package/build/cards/stats.js +118 -173
  31. package/build/cards/top-languages.d.ts +81 -77
  32. package/build/cards/top-languages.d.ts.map +1 -1
  33. package/build/cards/top-languages.js +186 -184
  34. package/build/cards/wakatime.d.ts +21 -11
  35. package/build/cards/wakatime.d.ts.map +1 -1
  36. package/build/cards/wakatime.js +92 -109
  37. package/build/common/Card.d.ts +41 -14
  38. package/build/common/Card.d.ts.map +1 -1
  39. package/build/common/Card.js +92 -31
  40. package/build/common/I18n.d.ts +4 -2
  41. package/build/common/I18n.d.ts.map +1 -1
  42. package/build/common/color.d.ts +91 -15
  43. package/build/common/color.d.ts.map +1 -1
  44. package/build/common/color.js +163 -17
  45. package/build/common/config.d.ts +2 -1
  46. package/build/common/config.d.ts.map +1 -1
  47. package/build/common/config.js +16 -26
  48. package/build/common/constants.d.ts +2 -1
  49. package/build/common/constants.d.ts.map +1 -1
  50. package/build/common/date.d.ts +37 -0
  51. package/build/common/date.d.ts.map +1 -0
  52. package/build/common/date.js +31 -0
  53. package/build/common/html.js +1 -1
  54. package/build/common/http.d.ts +37 -5
  55. package/build/common/http.d.ts.map +1 -1
  56. package/build/common/http.js +29 -6
  57. package/build/common/icons.d.ts +1 -0
  58. package/build/common/icons.d.ts.map +1 -1
  59. package/build/common/icons.js +1 -0
  60. package/build/common/languageColors.d.ts +11 -0
  61. package/build/common/languageColors.d.ts.map +1 -0
  62. package/build/common/languageColors.js +15 -0
  63. package/build/common/languageColors.json +10 -1
  64. package/build/common/ops.d.ts +27 -33
  65. package/build/common/ops.d.ts.map +1 -1
  66. package/build/common/ops.js +31 -48
  67. package/build/common/render.d.ts +154 -113
  68. package/build/common/render.d.ts.map +1 -1
  69. package/build/common/render.js +209 -92
  70. package/build/common/retryer.d.ts +15 -6
  71. package/build/common/retryer.d.ts.map +1 -1
  72. package/build/common/retryer.js +2 -0
  73. package/build/fetchers/gist.d.ts +6 -21
  74. package/build/fetchers/gist.d.ts.map +1 -1
  75. package/build/fetchers/gist.js +28 -64
  76. package/build/fetchers/repo.d.ts +12 -11
  77. package/build/fetchers/repo.d.ts.map +1 -1
  78. package/build/fetchers/repo.js +27 -68
  79. package/build/fetchers/stats.d.ts +24 -17
  80. package/build/fetchers/stats.d.ts.map +1 -1
  81. package/build/fetchers/stats.js +302 -184
  82. package/build/fetchers/top-languages.d.ts +10 -15
  83. package/build/fetchers/top-languages.d.ts.map +1 -1
  84. package/build/fetchers/top-languages.js +52 -103
  85. package/build/fetchers/types.d.ts +130 -0
  86. package/build/fetchers/types.d.ts.map +1 -0
  87. package/build/fetchers/types.js +1 -0
  88. package/build/fetchers/wakatime.d.ts +9 -5
  89. package/build/fetchers/wakatime.d.ts.map +1 -1
  90. package/build/fetchers/wakatime.js +8 -4
  91. package/build/graphql/contributionsDocument.d.ts +18 -0
  92. package/build/graphql/contributionsDocument.d.ts.map +1 -0
  93. package/build/graphql/contributionsDocument.js +30 -0
  94. package/build/graphql/generated/common.d.ts +42 -0
  95. package/build/graphql/generated/common.d.ts.map +1 -0
  96. package/build/graphql/generated/common.js +2 -0
  97. package/build/graphql/generated/gist.d.ts +44 -0
  98. package/build/graphql/generated/gist.d.ts.map +1 -0
  99. package/build/graphql/generated/gist.js +27 -0
  100. package/build/graphql/generated/repo.d.ts +67 -0
  101. package/build/graphql/generated/repo.d.ts.map +1 -0
  102. package/build/graphql/generated/repo.js +30 -0
  103. package/build/graphql/generated/stats.d.ts +150 -0
  104. package/build/graphql/generated/stats.d.ts.map +1 -0
  105. package/build/graphql/generated/stats.js +95 -0
  106. package/build/graphql/generated/top-languages.d.ts +54 -0
  107. package/build/graphql/generated/top-languages.d.ts.map +1 -0
  108. package/build/graphql/generated/top-languages.js +27 -0
  109. package/build/graphql/graphqlDocument.d.ts +22 -0
  110. package/build/graphql/graphqlDocument.d.ts.map +1 -0
  111. package/build/graphql/graphqlDocument.js +8 -0
  112. package/build/graphql/reposContributedToDocument.d.ts +27 -0
  113. package/build/graphql/reposContributedToDocument.d.ts.map +1 -0
  114. package/build/graphql/reposContributedToDocument.js +59 -0
  115. package/build/index.d.ts +3 -1
  116. package/build/index.d.ts.map +1 -1
  117. package/build/index.js +2 -1
  118. package/build/themes/index.d.ts +32 -0
  119. package/build/themes/index.d.ts.map +1 -1
  120. package/build/themes/index.js +28 -0
  121. package/build/translations.d.ts +17 -0
  122. package/build/translations.d.ts.map +1 -1
  123. package/build/translations.js +17 -0
  124. package/package.json +14 -8
  125. package/src/_emoji-name-map.d.ts +10 -0
  126. package/src/_github-username-regex.d.ts +4 -0
  127. package/src/api/gist.js +31 -31
  128. package/src/api/index.js +40 -42
  129. package/src/api/pin.js +20 -38
  130. package/src/api/top-langs.js +36 -49
  131. package/src/api/wakatime.js +31 -31
  132. package/src/{calculateRank.js → calculateRank.ts} +29 -19
  133. package/src/cards/common-options.ts +13 -0
  134. package/src/cards/{gist.js → gist.ts} +37 -37
  135. package/src/cards/{repo.js → repo.ts} +107 -79
  136. package/src/cards/{stats.js → stats.ts} +173 -210
  137. package/src/cards/{top-languages.js → top-languages.ts} +325 -243
  138. package/src/cards/{wakatime.js → wakatime.ts} +158 -127
  139. package/src/common/Card.ts +123 -43
  140. package/src/common/I18n.ts +6 -2
  141. package/src/common/color.ts +240 -28
  142. package/src/common/config.ts +22 -29
  143. package/src/common/constants.ts +3 -1
  144. package/src/common/date.ts +45 -0
  145. package/src/common/html.ts +1 -1
  146. package/src/common/http.ts +71 -0
  147. package/src/common/icons.ts +1 -0
  148. package/src/common/languageColors.json +10 -1
  149. package/src/common/languageColors.ts +19 -0
  150. package/src/common/ops.ts +158 -0
  151. package/src/common/render.ts +652 -0
  152. package/src/common/retryer.ts +21 -12
  153. package/src/fetchers/gist.ts +79 -0
  154. package/src/fetchers/repo.ts +114 -0
  155. package/src/fetchers/stats.ts +743 -0
  156. package/src/fetchers/top-languages.ts +135 -0
  157. package/src/fetchers/{types.d.ts → types.ts} +28 -20
  158. package/src/fetchers/{wakatime.js → wakatime.ts} +19 -5
  159. package/src/graphql/contributionsDocument.ts +44 -0
  160. package/src/graphql/generated/common.ts +26 -0
  161. package/src/graphql/generated/gist.ts +59 -0
  162. package/src/graphql/generated/repo.ts +90 -0
  163. package/src/graphql/generated/stats.ts +194 -0
  164. package/src/graphql/generated/top-languages.ts +75 -0
  165. package/src/graphql/graphqlDocument.ts +25 -0
  166. package/src/graphql/queries/gist.graphql +25 -0
  167. package/src/graphql/queries/repo.graphql +28 -0
  168. package/src/graphql/queries/stats.graphql +120 -0
  169. package/src/graphql/queries/top-languages.graphql +34 -0
  170. package/src/graphql/reposContributedToDocument.ts +86 -0
  171. package/src/index.ts +3 -1
  172. package/src/themes/index.ts +33 -0
  173. package/src/translations.ts +17 -0
  174. package/src/cards/types.d.ts +0 -78
  175. package/src/common/http.js +0 -19
  176. package/src/common/ops.js +0 -170
  177. package/src/common/render.js +0 -440
  178. package/src/fetchers/gist.js +0 -112
  179. package/src/fetchers/repo.js +0 -161
  180. package/src/fetchers/stats.js +0 -474
  181. package/src/fetchers/top-languages.js +0 -175
  182. package/src/themes/README.md +0 -229
@@ -1,112 +0,0 @@
1
- import { MissingParamError } from "../common/error.js";
2
- import { request } from "../common/http.js";
3
- import { retryer } from "../common/retryer.js";
4
-
5
- const QUERY = `
6
- query gistInfo($gistName: String!) {
7
- viewer {
8
- gist(name: $gistName) {
9
- description
10
- owner {
11
- login
12
- }
13
- stargazerCount
14
- forks {
15
- totalCount
16
- }
17
- files {
18
- name
19
- language {
20
- name
21
- }
22
- size
23
- }
24
- }
25
- }
26
- }
27
- `;
28
-
29
- /**
30
- * Gist data fetcher.
31
- *
32
- * @param {object} variables Fetcher variables.
33
- * @param {string} token GitHub token.
34
- * @returns {Promise<import('axios').AxiosResponse>} The response.
35
- */
36
- const fetcher = async (variables, token) => {
37
- return await request(
38
- { query: QUERY, variables },
39
- { Authorization: `token ${token}` },
40
- );
41
- };
42
-
43
- /**
44
- * @typedef {{ name: string; language: { name: string; }, size: number }} GistFile Gist file.
45
- */
46
-
47
- /**
48
- * This function calculates the primary language of a gist by files size.
49
- *
50
- * @param {GistFile[]} files Files.
51
- * @returns {string} Primary language.
52
- */
53
- const calculatePrimaryLanguage = (files) => {
54
- /** @type {Record<string, number>} */
55
- const languages = {};
56
-
57
- for (const file of files) {
58
- if (file.language) {
59
- if (languages[file.language.name]) {
60
- languages[file.language.name] += file.size;
61
- } else {
62
- languages[file.language.name] = file.size;
63
- }
64
- }
65
- }
66
-
67
- let primaryLanguage = Object.keys(languages)[0];
68
- for (const language in languages) {
69
- if (languages[language] > languages[primaryLanguage]) {
70
- primaryLanguage = language;
71
- }
72
- }
73
-
74
- return primaryLanguage;
75
- };
76
-
77
- /**
78
- * @typedef {import('./types').GistData} GistData Gist data.
79
- */
80
-
81
- /**
82
- * Fetch GitHub gist information by given username and ID.
83
- *
84
- * @param {string} id GitHub gist ID.
85
- * @param {string | null} pat Optional PAT override.
86
- * @returns {Promise<GistData>} Gist data.
87
- */
88
- const fetchGist = async (id, pat = null) => {
89
- if (!id) {
90
- throw new MissingParamError(["id"], "/api/gist?id=GIST_ID");
91
- }
92
- const res = await retryer(fetcher, { gistName: id }, pat);
93
- if (res.data.errors) {
94
- throw new Error(res.data.errors[0].message);
95
- }
96
- if (!res.data.data.viewer.gist) {
97
- throw new Error("Gist not found");
98
- }
99
- const data = res.data.data.viewer.gist;
100
- return {
101
- name: data.files[Object.keys(data.files)[0]].name,
102
- nameWithOwner: `${data.owner.login}/${
103
- data.files[Object.keys(data.files)[0]].name
104
- }`,
105
- description: data.description,
106
- language: calculatePrimaryLanguage(data.files),
107
- starsCount: data.stargazerCount,
108
- forksCount: data.forks.totalCount,
109
- };
110
- };
111
-
112
- export { fetchGist };
@@ -1,161 +0,0 @@
1
- import { MissingParamError } from "../common/error.js";
2
- import { request } from "../common/http.js";
3
- import { retryer } from "../common/retryer.js";
4
-
5
- import { fetchRepoUserStats } from "./stats.js";
6
-
7
- /**
8
- * Repo data fetcher.
9
- *
10
- * @param {object} variables Fetcher variables.
11
- * @param {string} token GitHub token.
12
- * @returns {Promise<import('axios').AxiosResponse>} The response.
13
- */
14
- const fetcher = (variables, token) => {
15
- return request(
16
- {
17
- query: `
18
- fragment RepoInfo on Repository {
19
- name
20
- nameWithOwner
21
- isPrivate
22
- isArchived
23
- isTemplate
24
- stargazerCount
25
- description
26
- primaryLanguage {
27
- color
28
- id
29
- name
30
- }
31
- forkCount
32
- }
33
- query getRepo($login: String!, $repo: String!) {
34
- user(login: $login) {
35
- repository(name: $repo) {
36
- ...RepoInfo
37
- }
38
- }
39
- organization(login: $login) {
40
- repository(name: $repo) {
41
- ...RepoInfo
42
- }
43
- }
44
- }
45
- `,
46
- variables,
47
- },
48
- {
49
- Authorization: `token ${token}`,
50
- },
51
- );
52
- };
53
-
54
- const urlExample = "/api/pin?username=USERNAME&amp;repo=REPO_NAME";
55
-
56
- /**
57
- * @typedef {import("./types").RepositoryData} RepositoryData Repository data.
58
- */
59
-
60
- /**
61
- * Fetch repository data.
62
- *
63
- * @param {string} username GitHub username.
64
- * @param {string} reponame GitHub repository name.
65
- * @returns {Promise<RepositoryData>} Repository data.
66
- */
67
- const fetchRepo = async (
68
- username,
69
- reponame,
70
- include_prs_authored = false,
71
- include_prs_commented = false,
72
- include_prs_reviewed = false,
73
- include_issues_authored = false,
74
- include_issues_commented = false,
75
- pat = null,
76
- ) => {
77
- let owner = username;
78
- if (reponame && reponame.includes("/")) {
79
- const [parsed_owner, parsed_repo] = reponame.split("/");
80
- owner = parsed_owner;
81
- reponame = parsed_repo;
82
- }
83
-
84
- if (owner && !username) {
85
- username = owner;
86
- }
87
- if (username && !owner) {
88
- owner = username;
89
- }
90
- if (!username && !reponame) {
91
- throw new MissingParamError(["username", "repo"], urlExample);
92
- }
93
- if (!username) {
94
- throw new MissingParamError(["username"], urlExample);
95
- }
96
- if (!reponame) {
97
- throw new MissingParamError(["repo"], urlExample);
98
- }
99
-
100
- let res = await retryer(fetcher, { login: owner, repo: reponame }, pat);
101
-
102
- const data = res.data.data;
103
-
104
- if (!data.user && !data.organization) {
105
- throw new Error("Not found");
106
- }
107
-
108
- const isUser = data.organization === null && data.user;
109
- const isOrg = data.user === null && data.organization;
110
-
111
- if (isUser) {
112
- if (!data.user.repository || data.user.repository.isPrivate) {
113
- throw new Error("User Repository Not found");
114
- }
115
- let repoUserStats = await fetchRepoUserStats(
116
- username,
117
- [owner + "/" + reponame],
118
- [],
119
- include_prs_authored,
120
- include_prs_commented,
121
- include_prs_reviewed,
122
- include_issues_authored,
123
- include_issues_commented,
124
- pat,
125
- );
126
- return {
127
- ...repoUserStats,
128
- ...data.user.repository,
129
- starCount: data.user.repository.stargazerCount,
130
- };
131
- }
132
-
133
- if (isOrg) {
134
- if (
135
- !data.organization.repository ||
136
- data.organization.repository.isPrivate
137
- ) {
138
- throw new Error("Organization Repository Not found");
139
- }
140
- let repoUserStats = await fetchRepoUserStats(
141
- username,
142
- [owner + "/" + reponame],
143
- [],
144
- include_prs_authored,
145
- include_prs_commented,
146
- include_prs_reviewed,
147
- include_issues_authored,
148
- include_issues_commented,
149
- pat,
150
- );
151
- return {
152
- ...repoUserStats,
153
- ...data.organization.repository,
154
- starCount: data.organization.repository.stargazerCount,
155
- };
156
- }
157
-
158
- throw new Error("Unexpected behavior");
159
- };
160
-
161
- export { fetchRepo };