forked from generalentropy/bit-scripts-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
56 lines (50 loc) · 1.46 KB
/
Copy pathhelpers.js
File metadata and controls
56 lines (50 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import i18n from "i18next";
export const changeLanguage = (language) => {
i18n.changeLanguage(language);
};
export const fetchReposData = async (orgName) => {
try {
const response = await fetch(
`https://api.github.com/orgs/${orgName}/repos`,
);
if (!response.ok) {
throw new Error(`Error: ${response.status} ${response.statusText}`);
}
const repos = await response.json();
return repos;
} catch (error) {
console.error("Fetch error:", error);
}
};
export const getDicordInviteInfo = async (inviteCode) => {
if (!inviteCode) {
console.error("Un code d'invitation est nécessaire");
return null;
}
try {
const response = await fetch(
`https://discord.com/api/v10/invites/${inviteCode}`,
);
if (!response.ok) {
throw new Error(`Error: ${response.status} ${response.statusText}`);
}
const channelInfo = await response.json();
console.log(channelInfo);
return channelInfo;
} catch (error) {
console.error("Fetch error:", error);
return null;
}
};
export const normalizeLang = (lang) => {
if (typeof lang === "string" && lang.includes("-")) {
return lang.split("-")[0];
}
return lang;
};
export function convertDate(dateStr) {
if (!dateStr) return null;
const dateObj = new Date(dateStr);
const formattedDate = `${String(dateObj.getDate()).padStart(2, "0")}/${String(dateObj.getMonth() + 1).padStart(2, "0")}/${dateObj.getFullYear()}`;
return formattedDate;
}