funcraft-api-v3 0.0.1-security → 3.0.2

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.

Potentially problematic release.


This version of funcraft-api-v3 might be problematic. Click here for more details.

@@ -0,0 +1,249 @@
1
+ export type StatsResponse = {
2
+ code: number;
3
+ error: string;
4
+ userId: string;
5
+ username: string;
6
+ month: number;
7
+ monthName: string;
8
+ game: string;
9
+ rank: number;
10
+ skin?: string;
11
+ data: {
12
+ points: number;
13
+ gameCount: number;
14
+ winCount: number;
15
+ defeatCount: number;
16
+ gameTime: number;
17
+ kills: number;
18
+ deathCount: number;
19
+ };
20
+ stats: {
21
+ winrate: number;
22
+ kd: number;
23
+ ragequit?: number;
24
+ killsPerGame: number;
25
+ deathsPerGame: number;
26
+ pointsPerGame: number;
27
+ timePerGame?: number;
28
+ killsPerMinute?: number;
29
+ secondsPerKill?: number;
30
+ bedsPerGame?: number;
31
+ nexusPerGame?: number;
32
+ damagePerGame?: number;
33
+ };
34
+ };
35
+ export type InfosResponse = {
36
+ code: number;
37
+ error: string;
38
+ grade: string;
39
+ username: string;
40
+ userId: string;
41
+ skin: string;
42
+ inscription: Date;
43
+ lastConnection: Date;
44
+ gloires: number;
45
+ gameCount: number;
46
+ points: number;
47
+ winCount: number;
48
+ defeatCount: number;
49
+ gameTime: number;
50
+ kills: number;
51
+ deathCount: number;
52
+ friends?: {
53
+ nom: string;
54
+ skin: string;
55
+ }[];
56
+ ban: ("TEMP" | "DEF" | "NONE");
57
+ };
58
+ export type AllStatsResponse = {
59
+ [game: string]: string | number | {
60
+ [period: string]: StatsResponse;
61
+ always?: StatsResponse;
62
+ } | {
63
+ username: string;
64
+ skin: string;
65
+ userId: string;
66
+ };
67
+ code: number;
68
+ error: string;
69
+ infos: {
70
+ username: string;
71
+ skin: string;
72
+ userId: string;
73
+ };
74
+ };
75
+ /**
76
+ * @typedef {{
77
+ * code: number,
78
+ * error: string,
79
+ * userId: string,
80
+ * username: string,
81
+ * month: number,
82
+ * monthName: string,
83
+ * game: string,
84
+ * rank: number,
85
+ * skin?: string,
86
+ * data: {
87
+ * points: number,
88
+ * gameCount: number,
89
+ * winCount: number,
90
+ * defeatCount: number,
91
+ * gameTime: number,
92
+ * kills: number,
93
+ * deathCount: number
94
+ * },
95
+ * stats: {
96
+ * winrate: number,
97
+ * kd: number,
98
+ * ragequit?: number,
99
+ * killsPerGame: number,
100
+ * deathsPerGame: number,
101
+ * pointsPerGame: number,
102
+ * timePerGame?: number,
103
+ * killsPerMinute?: number,
104
+ * secondsPerKill?: number,
105
+ * bedsPerGame?: number,
106
+ * nexusPerGame?: number,
107
+ * damagePerGame?: number
108
+ * }
109
+ * }} StatsResponse
110
+ */
111
+ /**
112
+ * @typedef {{
113
+ * code: number,
114
+ * error: string,
115
+ * grade: string,
116
+ * username: string,
117
+ * userId: string,
118
+ * skin: string,
119
+ * inscription: Date,
120
+ * lastConnection: Date,
121
+ * gloires: number,
122
+ * gameCount: number,
123
+ * points: number,
124
+ * winCount: number,
125
+ * defeatCount: number,
126
+ * gameTime: number,
127
+ * kills: number,
128
+ * deathCount: number,
129
+ * friends?: {
130
+ * nom: string,
131
+ * skin: string
132
+ * }[],
133
+ * ban: ("TEMP"|"DEF"|"NONE")
134
+ * }} InfosResponse
135
+ */
136
+ /**
137
+ * @typedef {{
138
+ * code: number,
139
+ * error: string,
140
+ * infos: {
141
+ * username: string,
142
+ * skin: string,
143
+ * userId: string
144
+ * },
145
+ * [game: string]: (
146
+ * number | string | {
147
+ * [period: string]: StatsResponse
148
+ * always?: StatsResponse
149
+ * } | {
150
+ * username: string,
151
+ * skin: string,
152
+ * userId: string
153
+ * }
154
+ * )
155
+ * }} AllStatsResponse
156
+ */
157
+ /**
158
+ * Get stats for a player, for a game in a specific period
159
+ * @param {string} period
160
+ * @param {string} game
161
+ * @param {string} username
162
+ * @returns {Promise<StatsResponse>}
163
+ */
164
+ export function stats(period: string, game: string, username: string): Promise<StatsResponse>;
165
+ /**
166
+ * Get all stats of a player
167
+ * @param {string} username
168
+ * @returns {Promise<AllStatsResponse>}
169
+ */
170
+ export function allStats(username: string): Promise<AllStatsResponse>;
171
+ /**
172
+ * Get infos about a player
173
+ * @param {string} username
174
+ * @returns {Promise<InfosResponse>}
175
+ */
176
+ export function infos(username: string, fetchFriends?: boolean): Promise<InfosResponse>;
177
+ /**
178
+ * Get friends from a player id
179
+ * @param {string} userId
180
+ * @returns {Promise<{
181
+ * code: number,
182
+ * error: string,
183
+ * friends: {
184
+ * nom: string,
185
+ * skin: string
186
+ * }[]
187
+ * }>}
188
+ */
189
+ export function friends(userId: string): Promise<{
190
+ code: number;
191
+ error: string;
192
+ friends: {
193
+ nom: string;
194
+ skin: string;
195
+ }[];
196
+ }>;
197
+ /**
198
+ * Get head of a player
199
+ * @param {string} username
200
+ * @returns {Promise<string>}
201
+ */
202
+ export function head(username: string): Promise<string>;
203
+ /**
204
+ * Get stats table of a game
205
+ * @param {string} period
206
+ * @param {string} game
207
+ * @returns {Promise<StatsResponse[]>}
208
+ */
209
+ export function table(period: string, game: string): Promise<StatsResponse[]>;
210
+ /**
211
+ * Compute some stats properties
212
+ * @param {StatsResponse} stats
213
+ * @param {boolean} onlyHat
214
+ * @param {boolean} data
215
+ * @returns {StatsResponse}
216
+ */
217
+ export function computeStats(stats: StatsResponse, onlyHat?: boolean, data?: boolean): StatsResponse;
218
+ import parsers = require("./parsers");
219
+ import errors = require("./errors");
220
+ import utils = require("./utils");
221
+ export const data: {
222
+ games: string[];
223
+ months: string[];
224
+ gameAliases: {
225
+ infecte: string;
226
+ shoot: string;
227
+ land: string;
228
+ mma: string;
229
+ pvp: string;
230
+ hika: string;
231
+ sky: string;
232
+ rush: string;
233
+ };
234
+ monthAliases: {
235
+ janvier: string;
236
+ fevrier: string;
237
+ mars: string;
238
+ avril: string;
239
+ mai: string;
240
+ juin: string;
241
+ juillet: string;
242
+ aout: string;
243
+ septembre: string;
244
+ octobre: string;
245
+ novembre: string;
246
+ decembre: string;
247
+ };
248
+ };
249
+ export { parsers, errors, utils };
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Get stats from html body
3
+ * @param {string} body
4
+ * @param {string} href
5
+ * @param {{ username: string, monthDiff: number, numGame: number, month: number }} data
6
+ * @returns {import('./').StatsResponse}
7
+ */
8
+ export function stats(body: string, href: string, { username, monthDiff, numGame, month }: {
9
+ username: string;
10
+ monthDiff: number;
11
+ numGame: number;
12
+ month: number;
13
+ }): import('./').StatsResponse;
14
+ /**
15
+ * Get all stats from html body
16
+ * @param {string} body
17
+ * @param {string} href
18
+ * @param {{ username: string }} data
19
+ * @returns {import('./').AllStatsResponse}
20
+ */
21
+ export function allStats(body: string, href: string, { username }: {
22
+ username: string;
23
+ }): import('./').AllStatsResponse;
24
+ /**
25
+ * Get infos from html body
26
+ * @param {string} body
27
+ * @param {string} href
28
+ * @param {{ username: string }} data
29
+ * @returns {import('./').InfosResponse}
30
+ */
31
+ export function infos(body: string, href: string, { username }: {
32
+ username: string;
33
+ }): import('./').InfosResponse;
34
+ /**
35
+ * Get friends from html body
36
+ * @param {string} body
37
+ * @returns {{
38
+ * code: number,
39
+ * error: string,
40
+ * friends: {
41
+ * nom: string,
42
+ * skin: string
43
+ * }[]
44
+ * }}
45
+ */
46
+ export function friends(body: string): {
47
+ code: number;
48
+ error: string;
49
+ friends: {
50
+ nom: string;
51
+ skin: string;
52
+ }[];
53
+ };
54
+ /**
55
+ * Get stats table from html body
56
+ * @param {string} body
57
+ * @param {{ period: string, game: string }} data
58
+ * @returns {{
59
+ * code: number,
60
+ * error: string,
61
+ * table: import('./').StatsResponse[]
62
+ * }}
63
+ */
64
+ export function table(body: string, { period, game }: {
65
+ period: string;
66
+ game: string;
67
+ }): {
68
+ code: number;
69
+ error: string;
70
+ table: import('./').StatsResponse[];
71
+ };
72
+ /**
73
+ * Get head fril html body
74
+ * @param {string} body
75
+ * @param {{ username: string }} data
76
+ * @returns {{
77
+ * code: number,
78
+ * error: string,
79
+ * head: string
80
+ * }}
81
+ */
82
+ export function head(body: string, { username }: {
83
+ username: string;
84
+ }): {
85
+ code: number;
86
+ error: string;
87
+ head: string;
88
+ };
89
+ /**
90
+ *
91
+ * @param {object} stats
92
+ * @param {object} datas
93
+ * @param {number} month
94
+ * @param {number} numGame
95
+ * @returns {object}
96
+ */
97
+ export function statsFromData(stats: object, datas: object, month: number, numGame: number): object;
@@ -0,0 +1,86 @@
1
+ declare const games: string[];
2
+ declare const months: string[];
3
+ declare namespace gameAliases {
4
+ const infecte: string;
5
+ const shoot: string;
6
+ const land: string;
7
+ const mma: string;
8
+ const pvp: string;
9
+ const hika: string;
10
+ const sky: string;
11
+ const rush: string;
12
+ }
13
+ declare namespace monthAliases {
14
+ const janvier: string;
15
+ const fevrier: string;
16
+ const mars: string;
17
+ const avril: string;
18
+ const mai: string;
19
+ const juin: string;
20
+ const juillet: string;
21
+ const aout: string;
22
+ const septembre: string;
23
+ const octobre: string;
24
+ const novembre: string;
25
+ const decembre: string;
26
+ }
27
+ /**
28
+ * Round a number with a decimal count
29
+ * @param {string} number
30
+ * @param {number} decimalCount
31
+ * @returns {number}
32
+ */
33
+ export function Round(number: string, decimalCount?: number): number;
34
+ /**
35
+ * Parse a FunCraft number field
36
+ * @param {string} value
37
+ * @returns {number}
38
+ */
39
+ export function parseFCInt(value: string): number;
40
+ /**
41
+ * Remove all accents from a string
42
+ * @param {string} string
43
+ * @returns {string}
44
+ */
45
+ export function removeAccents(string: string): string;
46
+ /**
47
+ * Parse a FunCraft date
48
+ * @param {string} value
49
+ * @param {string} utc
50
+ * @returns {Date}
51
+ */
52
+ export function parseFCDate(value: string, utc?: string): Date;
53
+ /**
54
+ * @param {string} period
55
+ * @returns {number}
56
+ */
57
+ export function getMonth(period: string): number;
58
+ /**
59
+ * @param {string} month
60
+ * @returns {number}
61
+ */
62
+ export function parseMonth(month: string): number;
63
+ /**
64
+ * @param {string} game
65
+ * @returns {string}
66
+ */
67
+ export function getGame(game: string): string;
68
+ /**
69
+ * Determine whether a string is a valid period
70
+ * @param {string} period
71
+ * @returns {string}
72
+ */
73
+ export function vGetPeriod(period: string, strict?: boolean): string;
74
+ /**
75
+ * Determine whether a string is a valid game
76
+ * @param {string} game
77
+ * @returns {string}
78
+ */
79
+ export function vGetGame(game: string): string;
80
+ export declare namespace data {
81
+ export { games };
82
+ export { months };
83
+ export { gameAliases };
84
+ export { monthAliases };
85
+ }
86
+ export {};
package/utils.js ADDED
@@ -0,0 +1,178 @@
1
+ const games = ['rush_mdt', 'hikabrain', 'skywars', 'octogone', 'shootcraft', 'infected', 'blitz', 'pvpsmash', 'survival', 'rush_retro', 'landrush'];
2
+ const months = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
3
+ const gameAliases = {
4
+ "infecte": "infected",
5
+ "shoot": "shootcraft",
6
+ "land": "landrush",
7
+ "mma": "octogone",
8
+ "pvp": "pvpsmash",
9
+ "hika": "hikabrain",
10
+ "sky": "skywars",
11
+ "rush": "rush_mdt"
12
+ };
13
+ const monthAliases = {
14
+ 'janvier': 'january',
15
+ 'fevrier': 'february',
16
+ 'mars': 'march',
17
+ 'avril': 'april',
18
+ 'mai': 'may',
19
+ 'juin': 'june',
20
+ 'juillet': 'july',
21
+ 'aout': 'august',
22
+ 'septembre': 'september',
23
+ 'octobre': 'october',
24
+ 'novembre': 'november',
25
+ 'decembre': 'december'
26
+ };
27
+
28
+ /**
29
+ * Round a number with a decimal count
30
+ * @param {string} number
31
+ * @param {number} decimalCount
32
+ * @returns {number}
33
+ */
34
+ function Round(number, decimalCount = 0) {
35
+ return Math.round(number * Math.pow(10, decimalCount)) / Math.pow(10, decimalCount);
36
+ }
37
+
38
+ /**
39
+ * Parse a FunCraft number field
40
+ * @param {string} value
41
+ * @returns {number}
42
+ */
43
+ function parseFCInt(value) {
44
+ if (value.trim().replace(/\s+/ig, "") === "" || Number.isNaN(parseInt(value, 10)))
45
+ return 0;
46
+ else
47
+ return parseInt(value, 10);
48
+ }
49
+
50
+ /**
51
+ * Remove all accents from a string
52
+ * @param {string} string
53
+ * @returns {string}
54
+ */
55
+ function removeAccents(string) {
56
+ return string.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
57
+ }
58
+
59
+ /**
60
+ * Parse a FunCraft date
61
+ * @param {string} value
62
+ * @param {string} utc
63
+ * @returns {Date}
64
+ */
65
+ function parseFCDate(value, utc = 'UTC+01') {
66
+ const monthAliases = {
67
+ 'janvier': 'Jan',
68
+ 'fevrier': 'Feb',
69
+ 'mars': 'Mar',
70
+ 'avril': 'Apr',
71
+ 'mai': 'May',
72
+ 'juin': 'Jun',
73
+ 'juillet': 'Jul',
74
+ 'aout': 'Aug',
75
+ 'septembre': 'Sep',
76
+ 'octobre': 'Oct',
77
+ 'novembre': 'Nov',
78
+ 'decembre': 'Dec'
79
+ };
80
+ value = removeAccents(value).replace(/, (\d{2})h(\d{2})$/, ' $1:$2:00 ' + utc);
81
+ for (let month of Object.keys(monthAliases)) {
82
+ value = value.replace(month, monthAliases[month]);
83
+ }
84
+ return new Date(value);
85
+ }
86
+
87
+
88
+ /**
89
+ * @param {string} period
90
+ * @returns {number}
91
+ */
92
+ function getMonth(period) {
93
+ if (period.match(/^\d+$/) && parseInt(period) <= 12 && parseInt(period) >= 0)
94
+ return parseInt(period);
95
+ if (months.includes(period))
96
+ return months.indexOf(period) + 1;
97
+ if (Object.keys(monthAliases).includes(period))
98
+ return months.indexOf(monthAliases[period]) + 1;
99
+ if (period === "month" || period === "mois")
100
+ return (new Date()).getMonth() + 1;
101
+ if (period === "always" || period === "toujours")
102
+ return 0;
103
+ }
104
+ /**
105
+ * @param {string} month
106
+ * @returns {number}
107
+ */
108
+ function parseMonth(month) {
109
+ if (month === undefined)
110
+ return;
111
+ else if (month === 0)
112
+ return 0;
113
+ let numMonth = (new Date()).getMonth() + 1 - month;
114
+ if (numMonth < 0)
115
+ numMonth = 12 + numMonth;
116
+ return numMonth + 1;
117
+ }
118
+ /**
119
+ * @param {string} game
120
+ * @returns {string}
121
+ */
122
+ function getGame(game) {
123
+ game = game.replace(/[\s-]+/g, '_');
124
+ if (Object.keys(gameAliases).includes(game))
125
+ game = gameAliases[game];
126
+ if (games.includes(game))
127
+ return games.indexOf(game);
128
+ }
129
+
130
+
131
+ /**
132
+ * Determine whether a string is a valid period
133
+ * @param {string} period
134
+ * @returns {string}
135
+ */
136
+ function vGetPeriod(period, strict = false) {
137
+ let p;
138
+ if (strict)
139
+ p = parseMonth(getMonth(period.trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "")));
140
+ else
141
+ p = getMonth(period.trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, ""));
142
+ if (p !== undefined) {
143
+ if (p === 0)
144
+ p = "always";
145
+ else
146
+ p = months[p - 1];
147
+ }
148
+ return p;
149
+ }
150
+ /**
151
+ * Determine whether a string is a valid game
152
+ * @param {string} game
153
+ * @returns {string}
154
+ */
155
+ function vGetGame(game) {
156
+ let m = getGame(game.trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, ""));
157
+ if (m !== undefined)
158
+ m = games[m];
159
+ return m;
160
+ }
161
+
162
+ module.exports = {
163
+ data: {
164
+ games,
165
+ months,
166
+ gameAliases,
167
+ monthAliases
168
+ },
169
+ Round,
170
+ parseFCInt,
171
+ removeAccents,
172
+ parseFCDate,
173
+ getMonth,
174
+ parseMonth,
175
+ getGame,
176
+ vGetPeriod,
177
+ vGetGame
178
+ };