@juki-team/commons 0.2.0 → 0.2.1
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.
- package/dist/constants/commons.d.ts +1 -1
- package/dist/constants/commons.js +1 -1
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.js +1 -1
- package/dist/dto/index.d.ts +2 -1
- package/dist/dto/index.js +2 -1
- package/dist/helpers/array.d.ts +3 -0
- package/dist/helpers/array.js +28 -0
- package/dist/helpers/console.d.ts +3 -0
- package/dist/helpers/console.js +9 -0
- package/dist/{date/index.d.ts → helpers/date.d.ts} +11 -0
- package/dist/{date/index.js → helpers/date.js} +24 -0
- package/dist/helpers/document.d.ts +1 -11
- package/dist/helpers/document.js +1 -21
- package/dist/helpers/duration.d.ts +2 -0
- package/dist/helpers/duration.js +57 -0
- package/dist/helpers/entity.d.ts +11 -0
- package/dist/helpers/entity.js +20 -0
- package/dist/helpers/file.d.ts +6 -1
- package/dist/helpers/file.js +23 -2
- package/dist/helpers/http.d.ts +1 -0
- package/dist/helpers/http.js +8 -0
- package/dist/helpers/index.d.ts +12 -3
- package/dist/helpers/index.js +12 -3
- package/dist/helpers/json.d.ts +3 -0
- package/dist/helpers/json.js +31 -0
- package/dist/helpers/object.d.ts +2 -0
- package/dist/helpers/object.js +28 -0
- package/dist/helpers/problem.d.ts +2 -0
- package/dist/helpers/problem.js +1 -0
- package/dist/helpers/responses.d.ts +1 -1
- package/dist/helpers/responses.js +3 -2
- package/dist/helpers/string.d.ts +7 -0
- package/dist/helpers/string.js +52 -0
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/prisma/enums/index.d.ts +11 -11
- package/dist/prisma/enums/index.js +11 -11
- package/dist/types/assignment.d.ts +28 -0
- package/dist/types/assignment.js +7 -0
- package/dist/types/class.d.ts +1 -27
- package/dist/types/class.js +1 -7
- package/dist/types/code.d.ts +39 -0
- package/dist/types/{commons.js → code.js} +0 -28
- package/dist/types/contest.d.ts +2 -2
- package/dist/types/device.d.ts +7 -0
- package/dist/types/device.js +1 -0
- package/dist/types/duration.d.ts +7 -0
- package/dist/types/duration.js +1 -0
- package/dist/types/entity.d.ts +12 -0
- package/dist/types/entity.js +14 -0
- package/dist/types/id.d.ts +3 -0
- package/dist/types/id.js +1 -0
- package/dist/types/index.d.ts +10 -5
- package/dist/types/index.js +10 -5
- package/dist/types/judge.d.ts +1 -1
- package/dist/types/{problems.d.ts → problem.d.ts} +2 -1
- package/dist/types/services.d.ts +1 -1
- package/dist/types/socket.d.ts +1 -1
- package/dist/types/state.d.ts +12 -0
- package/dist/types/state.js +14 -0
- package/dist/types/teams.d.ts +1 -1
- package/dist/types/text.d.ts +4 -0
- package/dist/types/text.js +1 -0
- package/dist/types/{users.d.ts → user.d.ts} +1 -1
- package/dist/types/{users.js → user.js} +1 -1
- package/dist/types/worksheet.d.ts +105 -2
- package/dist/types/worksheet.js +16 -0
- package/package.json +6 -19
- package/dist/helpers/commons.d.ts +0 -33
- package/dist/helpers/commons.js +0 -191
- package/dist/helpers/time.d.ts +0 -13
- package/dist/helpers/time.js +0 -101
- package/dist/types/commons.d.ts +0 -84
- package/dist/types/sheet.d.ts +0 -104
- package/dist/types/sheet.js +0 -16
- /package/dist/constants/{time.d.ts → duration.d.ts} +0 -0
- /package/dist/constants/{time.js → duration.js} +0 -0
- /package/dist/dto/{virtual-user.d.ts → virtualUser.d.ts} +0 -0
- /package/dist/dto/{virtual-user.js → virtualUser.js} +0 -0
- /package/dist/dto/{worksheet-submissions.d.ts → worksheetSubmission.d.ts} +0 -0
- /package/dist/dto/{worksheet-submissions.js → worksheetSubmission.js} +0 -0
- /package/dist/helpers/{class.d.ts → assignment.d.ts} +0 -0
- /package/dist/helpers/{class.js → assignment.js} +0 -0
- /package/dist/{errors/index.d.ts → helpers/errors.d.ts} +0 -0
- /package/dist/{errors/index.js → helpers/errors.js} +0 -0
- /package/dist/{number/index.d.ts → helpers/number.d.ts} +0 -0
- /package/dist/{number/index.js → helpers/number.js} +0 -0
- /package/dist/types/{problems.js → problem.js} +0 -0
- /package/dist/types/{account.d.ts → profile.d.ts} +0 -0
- /package/dist/types/{account.js → profile.js} +0 -0
|
@@ -579,7 +579,7 @@ export const CODE_LANGUAGE = {
|
|
|
579
579
|
},
|
|
580
580
|
};
|
|
581
581
|
export const PAGE_SIZES = ['32', '64', '128', '256', '512'];
|
|
582
|
-
export const
|
|
582
|
+
export const PALETTE = {
|
|
583
583
|
vivos: [
|
|
584
584
|
{ color: '#FF0000', title: 'Rojo' },
|
|
585
585
|
{ color: '#FF5900', title: 'Rojo - Naranja' },
|
|
@@ -3,6 +3,7 @@ export * from './company.js';
|
|
|
3
3
|
export * from './contest.js';
|
|
4
4
|
export * from './course.js';
|
|
5
5
|
export * from './date.js';
|
|
6
|
+
export * from './duration.js';
|
|
6
7
|
export * from './email.js';
|
|
7
8
|
export * from './entity.js';
|
|
8
9
|
export * from './file.js';
|
|
@@ -12,7 +13,6 @@ export * from './routing.js';
|
|
|
12
13
|
export * from './services.js';
|
|
13
14
|
export * from './system.js';
|
|
14
15
|
export * from './teams.js';
|
|
15
|
-
export * from './time.js';
|
|
16
16
|
export * from './user.js';
|
|
17
17
|
export * from './websocket.js';
|
|
18
18
|
export * from './worksheet.js';
|
package/dist/constants/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from './company.js';
|
|
|
3
3
|
export * from './contest.js';
|
|
4
4
|
export * from './course.js';
|
|
5
5
|
export * from './date.js';
|
|
6
|
+
export * from './duration.js';
|
|
6
7
|
export * from './email.js';
|
|
7
8
|
export * from './entity.js';
|
|
8
9
|
export * from './file.js';
|
|
@@ -12,7 +13,6 @@ export * from './routing.js';
|
|
|
12
13
|
export * from './services.js';
|
|
13
14
|
export * from './system.js';
|
|
14
15
|
export * from './teams.js';
|
|
15
|
-
export * from './time.js';
|
|
16
16
|
export * from './user.js';
|
|
17
17
|
export * from './websocket.js';
|
|
18
18
|
export * from './worksheet.js';
|
package/dist/dto/index.d.ts
CHANGED
|
@@ -20,5 +20,6 @@ export * from './submission.js';
|
|
|
20
20
|
export * from './system.js';
|
|
21
21
|
export * from './url.js';
|
|
22
22
|
export * from './user.js';
|
|
23
|
+
export * from './virtualUser.js';
|
|
23
24
|
export * from './worksheet.js';
|
|
24
|
-
export * from './
|
|
25
|
+
export * from './worksheetSubmission.js';
|
package/dist/dto/index.js
CHANGED
|
@@ -20,5 +20,6 @@ export * from './submission.js';
|
|
|
20
20
|
export * from './system.js';
|
|
21
21
|
export * from './url.js';
|
|
22
22
|
export * from './user.js';
|
|
23
|
+
export * from './virtualUser.js';
|
|
23
24
|
export * from './worksheet.js';
|
|
24
|
-
export * from './
|
|
25
|
+
export * from './worksheetSubmission.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const mex = (array) => {
|
|
2
|
+
let i = 0;
|
|
3
|
+
while (array.indexOf(i) !== -1) {
|
|
4
|
+
i++;
|
|
5
|
+
}
|
|
6
|
+
return i;
|
|
7
|
+
};
|
|
8
|
+
export const range = (start, end) => {
|
|
9
|
+
const result = [];
|
|
10
|
+
for (let i = start; i < end; i++) {
|
|
11
|
+
result.push(i);
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
};
|
|
15
|
+
export const areArraysDifferent = (a, b) => {
|
|
16
|
+
if (a === b) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (a.length !== b.length) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
for (let i = 0; i < b.length; i += 1) {
|
|
23
|
+
if (b[i] !== a[i]) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const consoleWarn = (...warn) => {
|
|
2
|
+
console.warn(new Date().toLocaleString(), ...warn);
|
|
3
|
+
};
|
|
4
|
+
export const consoleInfo = (...info) => {
|
|
5
|
+
console.info(new Date().toLocaleString(), ...info);
|
|
6
|
+
};
|
|
7
|
+
export const consoleError = (...error) => {
|
|
8
|
+
console.error(new Date().toLocaleString(), ...error);
|
|
9
|
+
};
|
|
@@ -55,3 +55,14 @@ export declare const isWithinInterval: (date: Date, { start, end }: {
|
|
|
55
55
|
start: Date;
|
|
56
56
|
end: Date;
|
|
57
57
|
}, cmp?: "[]" | "()" | "[)" | "(]") => boolean;
|
|
58
|
+
export declare const normalizeToLocalStartOfDay: (timestamp: number | Date) => Date;
|
|
59
|
+
export declare const normalizeToLocalStartOfHour: (timestamp: number | Date) => Date;
|
|
60
|
+
export declare const normalizeToLocalStartOfMinutes: (timestamp: number | Date) => Date;
|
|
61
|
+
export declare const normalizeToLocalStartOfSeconds: (timestamp: number | Date) => Date;
|
|
62
|
+
export declare const getYears: (d: Date) => number;
|
|
63
|
+
export declare const getMonths: (d: Date) => number;
|
|
64
|
+
export declare const getDays: (d: Date) => number;
|
|
65
|
+
export declare const getHours: (d: Date) => number;
|
|
66
|
+
export declare const getMinutes: (d: Date) => number;
|
|
67
|
+
export declare const getSeconds: (d: Date) => number;
|
|
68
|
+
export declare const getMilliseconds: (d: Date) => number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ONE_DAY, ONE_HOUR, ONE_MINUTE } from '../constants/index.js';
|
|
1
2
|
export const changeYear = (date, year) => {
|
|
2
3
|
const newDate = new Date(date);
|
|
3
4
|
newDate.setFullYear(year);
|
|
@@ -155,3 +156,26 @@ export const isSecondsBefore = (a, b) => isMinutesBefore(a, b) || (isSameMinute(
|
|
|
155
156
|
export const isMillisecondsBefore = (a, b) => isSecondsBefore(a, b) || (isSameSecond(a, b) && a.getMilliseconds() < b.getMilliseconds());
|
|
156
157
|
export const isWithinInterval = (date, { start, end }, cmp = '[]') => (cmp.charAt(0) === '[' ? isEqual(date, start) || isAfter(date, start) : isAfter(date, start)) &&
|
|
157
158
|
(cmp.charAt(1) === ']' ? isEqual(date, end) || isBefore(date, end) : isBefore(date, end));
|
|
159
|
+
export const normalizeToLocalStartOfDay = (timestamp) => {
|
|
160
|
+
const d = new Date(timestamp);
|
|
161
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
162
|
+
};
|
|
163
|
+
export const normalizeToLocalStartOfHour = (timestamp) => {
|
|
164
|
+
const d = new Date(timestamp);
|
|
165
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours());
|
|
166
|
+
};
|
|
167
|
+
export const normalizeToLocalStartOfMinutes = (timestamp) => {
|
|
168
|
+
const d = new Date(timestamp);
|
|
169
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes());
|
|
170
|
+
};
|
|
171
|
+
export const normalizeToLocalStartOfSeconds = (timestamp) => {
|
|
172
|
+
const d = new Date(timestamp);
|
|
173
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds());
|
|
174
|
+
};
|
|
175
|
+
export const getYears = (d) => d.getFullYear();
|
|
176
|
+
export const getMonths = (d) => d.getFullYear() * 12 + d.getMonth();
|
|
177
|
+
export const getDays = (d) => Math.floor(normalizeToLocalStartOfDay(d).getTime() / ONE_DAY);
|
|
178
|
+
export const getHours = (d) => Math.floor(normalizeToLocalStartOfHour(d).getTime() / ONE_HOUR);
|
|
179
|
+
export const getMinutes = (d) => Math.floor(normalizeToLocalStartOfMinutes(d).getTime() / ONE_MINUTE);
|
|
180
|
+
export const getSeconds = (d) => Math.floor(normalizeToLocalStartOfSeconds(d).getTime() / 1000);
|
|
181
|
+
export const getMilliseconds = (d) => d.getTime();
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { EntityAccess, type EntityMembers, type EntityTeamsMemberUserData, type EntityUsersMemberUserData } from '../types/index.js';
|
|
1
|
+
import { EntityAccess, type EntityMembers } from '../types/index.js';
|
|
3
2
|
export declare const getDocumentAccess: (document: {
|
|
4
3
|
members: Pick<EntityMembers, "rankAdministrators" | "rankManagers" | "rankGuests" | "rankSpectators" | "rankParticipants">;
|
|
5
4
|
} | undefined) => EntityAccess;
|
|
6
|
-
export declare const isUserMember: (member: {
|
|
7
|
-
userId?: string;
|
|
8
|
-
teamId?: string;
|
|
9
|
-
}) => member is EntityUsersMemberUserData;
|
|
10
|
-
export declare const isTeamMember: (member: {
|
|
11
|
-
userId?: string;
|
|
12
|
-
teamId?: string;
|
|
13
|
-
}) => member is EntityTeamsMemberUserData;
|
|
14
|
-
export declare const toEntityMembersDTO: (members: EntityMembersResponseDTO) => EntityMembersDTO;
|
package/dist/helpers/document.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityAccess, EntityMembersRank
|
|
1
|
+
import { EntityAccess, EntityMembersRank } from '../types/index.js';
|
|
2
2
|
export const getDocumentAccess = (document) => {
|
|
3
3
|
const members = document?.members;
|
|
4
4
|
const adminRank = members?.rankAdministrators;
|
|
@@ -16,23 +16,3 @@ export const getDocumentAccess = (document) => {
|
|
|
16
16
|
return EntityAccess.RESTRICTED;
|
|
17
17
|
return EntityAccess.PRIVATE;
|
|
18
18
|
};
|
|
19
|
-
export const isUserMember = (member) => {
|
|
20
|
-
return typeof member.userId === 'string';
|
|
21
|
-
};
|
|
22
|
-
export const isTeamMember = (member) => {
|
|
23
|
-
return typeof member.teamId === 'string';
|
|
24
|
-
};
|
|
25
|
-
export const toEntityMembersDTO = (members) => {
|
|
26
|
-
return {
|
|
27
|
-
rankAdministrators: members.rankAdministrators,
|
|
28
|
-
administrators: Object.keys(members.administrators),
|
|
29
|
-
rankManagers: members.rankManagers,
|
|
30
|
-
managers: Object.keys(members.managers),
|
|
31
|
-
rankParticipants: members.rankParticipants,
|
|
32
|
-
participants: Object.keys(members.participants),
|
|
33
|
-
rankGuests: members.rankGuests,
|
|
34
|
-
guests: Object.keys(members.guests),
|
|
35
|
-
rankSpectators: members.rankSpectators,
|
|
36
|
-
spectators: Object.keys(members.spectators),
|
|
37
|
-
};
|
|
38
|
-
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export const splitTime = (timeRemaining) => {
|
|
2
|
+
const remaining = [];
|
|
3
|
+
const aSecondMilliseconds = 1000;
|
|
4
|
+
const aMinuteMilliseconds = aSecondMilliseconds * 60;
|
|
5
|
+
const aHourMilliseconds = aMinuteMilliseconds * 60;
|
|
6
|
+
const aDayMilliseconds = aHourMilliseconds * 24;
|
|
7
|
+
const aWeekMilliseconds = aDayMilliseconds * 7;
|
|
8
|
+
const remainingWeeks = Math.floor(timeRemaining / aWeekMilliseconds);
|
|
9
|
+
remaining.push({
|
|
10
|
+
remaining: remainingWeeks,
|
|
11
|
+
label: remainingWeeks === 1 ? 'week' : 'weeks',
|
|
12
|
+
abbreviatedLabel: 'w',
|
|
13
|
+
milliseconds: aWeekMilliseconds,
|
|
14
|
+
digits: 2,
|
|
15
|
+
});
|
|
16
|
+
const remainingDays = Math.floor((timeRemaining % aWeekMilliseconds) / aDayMilliseconds);
|
|
17
|
+
remaining.push({
|
|
18
|
+
remaining: remainingDays,
|
|
19
|
+
label: remainingDays === 1 ? 'day' : 'days',
|
|
20
|
+
abbreviatedLabel: 'd',
|
|
21
|
+
milliseconds: aDayMilliseconds,
|
|
22
|
+
digits: 2,
|
|
23
|
+
});
|
|
24
|
+
const remainingHours = Math.floor((timeRemaining % aDayMilliseconds) / aHourMilliseconds);
|
|
25
|
+
remaining.push({
|
|
26
|
+
remaining: remainingHours,
|
|
27
|
+
label: remainingHours === 1 ? 'hour' : 'hours',
|
|
28
|
+
abbreviatedLabel: 'h',
|
|
29
|
+
milliseconds: aHourMilliseconds,
|
|
30
|
+
digits: 2,
|
|
31
|
+
});
|
|
32
|
+
const remainingMinutes = Math.floor((timeRemaining % aHourMilliseconds) / aMinuteMilliseconds);
|
|
33
|
+
remaining.push({
|
|
34
|
+
remaining: remainingMinutes,
|
|
35
|
+
label: remainingMinutes === 1 ? 'minute' : 'minutes',
|
|
36
|
+
abbreviatedLabel: 'm',
|
|
37
|
+
milliseconds: aMinuteMilliseconds,
|
|
38
|
+
digits: 2,
|
|
39
|
+
});
|
|
40
|
+
const remainingSeconds = Math.floor((timeRemaining % aMinuteMilliseconds) / aSecondMilliseconds);
|
|
41
|
+
remaining.push({
|
|
42
|
+
remaining: remainingSeconds,
|
|
43
|
+
label: remainingSeconds === 1 ? 'second' : 'seconds',
|
|
44
|
+
abbreviatedLabel: 's',
|
|
45
|
+
milliseconds: aSecondMilliseconds,
|
|
46
|
+
digits: 2,
|
|
47
|
+
});
|
|
48
|
+
const remainingMilliseconds = Math.floor(timeRemaining % aSecondMilliseconds);
|
|
49
|
+
remaining.push({
|
|
50
|
+
remaining: remainingMilliseconds,
|
|
51
|
+
label: remainingMilliseconds === 1 ? 'millisecond' : 'milliseconds',
|
|
52
|
+
abbreviatedLabel: 'ms',
|
|
53
|
+
milliseconds: 1,
|
|
54
|
+
digits: 3,
|
|
55
|
+
});
|
|
56
|
+
return remaining;
|
|
57
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EntityMembersDTO, EntityMembersResponseDTO } from '../dto/index.js';
|
|
2
|
+
import type { EntityTeamsMemberUserData, EntityUsersMemberUserData } from '../types/index.js';
|
|
3
|
+
export declare const isUserMember: (member: {
|
|
4
|
+
userId?: string;
|
|
5
|
+
teamId?: string;
|
|
6
|
+
}) => member is EntityUsersMemberUserData;
|
|
7
|
+
export declare const isTeamMember: (member: {
|
|
8
|
+
userId?: string;
|
|
9
|
+
teamId?: string;
|
|
10
|
+
}) => member is EntityTeamsMemberUserData;
|
|
11
|
+
export declare const toEntityMembersDTO: (members: EntityMembersResponseDTO) => EntityMembersDTO;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const isUserMember = (member) => {
|
|
2
|
+
return typeof member.userId === 'string';
|
|
3
|
+
};
|
|
4
|
+
export const isTeamMember = (member) => {
|
|
5
|
+
return typeof member.teamId === 'string';
|
|
6
|
+
};
|
|
7
|
+
export const toEntityMembersDTO = (members) => {
|
|
8
|
+
return {
|
|
9
|
+
rankAdministrators: members.rankAdministrators,
|
|
10
|
+
administrators: Object.keys(members.administrators),
|
|
11
|
+
rankManagers: members.rankManagers,
|
|
12
|
+
managers: Object.keys(members.managers),
|
|
13
|
+
rankParticipants: members.rankParticipants,
|
|
14
|
+
participants: Object.keys(members.participants),
|
|
15
|
+
rankGuests: members.rankGuests,
|
|
16
|
+
guests: Object.keys(members.guests),
|
|
17
|
+
rankSpectators: members.rankSpectators,
|
|
18
|
+
spectators: Object.keys(members.spectators),
|
|
19
|
+
};
|
|
20
|
+
};
|
package/dist/helpers/file.d.ts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare const removeExtension: (fileName: string) => string;
|
|
2
|
+
/**
|
|
3
|
+
* Format bytes as human-readable text.
|
|
4
|
+
* Source: https://stackoverflow.com/questions/10420352/converting-file-size-in-bytes-to-human-readable-string
|
|
5
|
+
*/
|
|
6
|
+
export declare const humanFileSize: (bytes: number, si?: boolean, dp?: number) => string;
|
package/dist/helpers/file.js
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const removeExtension = (fileName) => {
|
|
2
2
|
const i = fileName.lastIndexOf('.');
|
|
3
3
|
return i !== -1 ? fileName.substring(0, i) : fileName;
|
|
4
|
-
}
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Format bytes as human-readable text.
|
|
7
|
+
* Source: https://stackoverflow.com/questions/10420352/converting-file-size-in-bytes-to-human-readable-string
|
|
8
|
+
*/
|
|
9
|
+
export const humanFileSize = (bytes, si = false, dp = 1) => {
|
|
10
|
+
const thresh = si ? 1000 : 1024;
|
|
11
|
+
if (Math.abs(bytes) < thresh) {
|
|
12
|
+
return `${bytes} B`;
|
|
13
|
+
}
|
|
14
|
+
const units = si
|
|
15
|
+
? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
16
|
+
: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
|
17
|
+
let u = -1;
|
|
18
|
+
let value = bytes;
|
|
19
|
+
const r = 10 ** dp;
|
|
20
|
+
do {
|
|
21
|
+
value /= thresh;
|
|
22
|
+
++u;
|
|
23
|
+
} while (Math.round(Math.abs(value) * r) / r >= thresh && u < units.length - 1);
|
|
24
|
+
return `${value.toFixed(dp)} ${units[u]}`;
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPlainText: (url: string) => Promise<string>;
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './array.js';
|
|
2
|
+
export * from './assignment.js';
|
|
2
3
|
export * from './comments.js';
|
|
3
|
-
export * from './
|
|
4
|
+
export * from './console.js';
|
|
4
5
|
export * from './contest.js';
|
|
6
|
+
export * from './date.js';
|
|
5
7
|
export * from './document.js';
|
|
8
|
+
export * from './duration.js';
|
|
9
|
+
export * from './entity.js';
|
|
10
|
+
export * from './errors.js';
|
|
6
11
|
export * from './file.js';
|
|
12
|
+
export * from './http.js';
|
|
7
13
|
export * from './interval.js';
|
|
14
|
+
export * from './json.js';
|
|
8
15
|
export * from './judging.js';
|
|
16
|
+
export * from './number.js';
|
|
9
17
|
export * from './object.js';
|
|
18
|
+
export * from './problem.js';
|
|
10
19
|
export * from './responses.js';
|
|
11
20
|
export * from './socket.js';
|
|
12
|
-
export * from './
|
|
21
|
+
export * from './string.js';
|
|
13
22
|
export * from './user.js';
|
|
14
23
|
export * from './worksheet.js';
|
package/dist/helpers/index.js
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './array.js';
|
|
2
|
+
export * from './assignment.js';
|
|
2
3
|
export * from './comments.js';
|
|
3
|
-
export * from './
|
|
4
|
+
export * from './console.js';
|
|
4
5
|
export * from './contest.js';
|
|
6
|
+
export * from './date.js';
|
|
5
7
|
export * from './document.js';
|
|
8
|
+
export * from './duration.js';
|
|
9
|
+
export * from './entity.js';
|
|
10
|
+
export * from './errors.js';
|
|
6
11
|
export * from './file.js';
|
|
12
|
+
export * from './http.js';
|
|
7
13
|
export * from './interval.js';
|
|
14
|
+
export * from './json.js';
|
|
8
15
|
export * from './judging.js';
|
|
16
|
+
export * from './number.js';
|
|
9
17
|
export * from './object.js';
|
|
18
|
+
export * from './problem.js';
|
|
10
19
|
export * from './responses.js';
|
|
11
20
|
export * from './socket.js';
|
|
12
|
-
export * from './
|
|
21
|
+
export * from './string.js';
|
|
13
22
|
export * from './user.js';
|
|
14
23
|
export * from './worksheet.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const isStringJson = (str) => {
|
|
2
|
+
try {
|
|
3
|
+
if (typeof str === 'string') {
|
|
4
|
+
JSON.parse(str);
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
};
|
|
13
|
+
export const safeJsonParse = (str) => {
|
|
14
|
+
try {
|
|
15
|
+
if (typeof str === 'string') {
|
|
16
|
+
return JSON.parse(str);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
24
|
+
export const isObjectJson = (obj) => {
|
|
25
|
+
try {
|
|
26
|
+
return typeof JSON.stringify(obj) === 'string';
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
};
|
package/dist/helpers/object.d.ts
CHANGED
package/dist/helpers/object.js
CHANGED
|
@@ -30,3 +30,31 @@ function sizeOf(obj) {
|
|
|
30
30
|
export function memorySizeOf(obj) {
|
|
31
31
|
return sizeOf(obj);
|
|
32
32
|
}
|
|
33
|
+
function mergeRecords(b, u) {
|
|
34
|
+
const mergeKeys = new Set([...Object.keys(b), ...Object.keys(u)]);
|
|
35
|
+
for (const key of mergeKeys) {
|
|
36
|
+
if (u[key] !== null && u[key] !== undefined && b[key] !== u[key]) {
|
|
37
|
+
b[key] = objectUpdate(b[key], u[key]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return b;
|
|
41
|
+
}
|
|
42
|
+
export function objectUpdate(base, update) {
|
|
43
|
+
if (JSON.stringify(base) === JSON.stringify(update)) {
|
|
44
|
+
return base;
|
|
45
|
+
}
|
|
46
|
+
if (base !== null && update !== null && !Array.isArray(base) && typeof base === 'object' && typeof update === 'object') {
|
|
47
|
+
return mergeRecords(base, update);
|
|
48
|
+
}
|
|
49
|
+
if (update !== null && update !== undefined) {
|
|
50
|
+
return update;
|
|
51
|
+
}
|
|
52
|
+
return base;
|
|
53
|
+
}
|
|
54
|
+
export function objectsUpdate(base, ...objects) {
|
|
55
|
+
let newObject = { ...base };
|
|
56
|
+
for (const update of objects) {
|
|
57
|
+
newObject = objectUpdate(newObject, update);
|
|
58
|
+
}
|
|
59
|
+
return newObject;
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const getProblemJudgeKey = (judge, key) => `${judge}-${key}`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { JkError } from '../errors/index.js';
|
|
2
1
|
import { type ContentResponse, type ContentsMeta, type ContentsResponse, type ErrorResponse } from '../types/index.js';
|
|
2
|
+
import { JkError } from './errors.js';
|
|
3
3
|
export declare function toJkError(err: unknown): JkError;
|
|
4
4
|
export declare function errorsResponse(message: string, ...errors: JkError[]): ErrorResponse;
|
|
5
5
|
export declare function contentResponse<T>(message: string, content: T): ContentResponse<T>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getErrorMessage } from '../constants/index.js';
|
|
2
|
-
import { JkError } from '../errors/index.js';
|
|
3
2
|
import { ErrorCode, } from '../types/index.js';
|
|
4
|
-
import { consoleError
|
|
3
|
+
import { consoleError } from './console.js';
|
|
4
|
+
import { JkError } from './errors.js';
|
|
5
|
+
import { isStringJson } from './json.js';
|
|
5
6
|
export function toJkError(err) {
|
|
6
7
|
const error = new Error();
|
|
7
8
|
let code = err?.code;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const indexToLetters: (index: number) => string;
|
|
2
|
+
export declare const lettersToIndex: (index: string) => number;
|
|
3
|
+
export declare const chunkString: (str: string, size: number) => string[];
|
|
4
|
+
export declare const getRandomString: (length: number) => string;
|
|
5
|
+
export declare const stringToArrayBuffer: (str: string) => ArrayBuffer;
|
|
6
|
+
export declare const join: (array: (string | null | Date)[]) => string;
|
|
7
|
+
export declare const split: (text: string) => string[];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { SEPARATOR_TOKEN, UPPERCASE_LETTERS } from '../constants/commons.js';
|
|
2
|
+
export const indexToLetters = (index) => {
|
|
3
|
+
const d = Math.ceil(index / 26);
|
|
4
|
+
if (d === 1) {
|
|
5
|
+
return UPPERCASE_LETTERS.charAt(index - 1);
|
|
6
|
+
}
|
|
7
|
+
return UPPERCASE_LETTERS.charAt(d - 2) + UPPERCASE_LETTERS.charAt(index - 26 * (d - 1) - 1);
|
|
8
|
+
};
|
|
9
|
+
export const lettersToIndex = (index) => {
|
|
10
|
+
if (index.length) {
|
|
11
|
+
if (index.length === 1) {
|
|
12
|
+
const d = UPPERCASE_LETTERS.indexOf(index);
|
|
13
|
+
if (d !== -1) {
|
|
14
|
+
return d + 1;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else if (index.length === 2) {
|
|
18
|
+
const a = index.charAt(0);
|
|
19
|
+
const b = index.charAt(1);
|
|
20
|
+
const numA = lettersToIndex(a);
|
|
21
|
+
const numB = lettersToIndex(b);
|
|
22
|
+
return numA * 26 + numB;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return 0;
|
|
26
|
+
};
|
|
27
|
+
export const chunkString = (str, size) => {
|
|
28
|
+
const numChunks = Math.ceil(str.length / size);
|
|
29
|
+
const chunks = new Array(numChunks);
|
|
30
|
+
for (let i = 0, o = 0; i < numChunks; ++i, o += size) {
|
|
31
|
+
chunks[i] = str.substr(o, size);
|
|
32
|
+
}
|
|
33
|
+
return chunks;
|
|
34
|
+
};
|
|
35
|
+
export const getRandomString = (length) => {
|
|
36
|
+
const charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
37
|
+
let retVal = '';
|
|
38
|
+
for (let i = 0; i < length; ++i) {
|
|
39
|
+
retVal += charset.charAt(Math.floor(Math.random() * charset.length));
|
|
40
|
+
}
|
|
41
|
+
return retVal;
|
|
42
|
+
};
|
|
43
|
+
export const stringToArrayBuffer = (str) => {
|
|
44
|
+
const buf = new ArrayBuffer(str.length);
|
|
45
|
+
const view = new Uint8Array(buf);
|
|
46
|
+
for (let i = 0; i < str.length; i++) {
|
|
47
|
+
view[i] = str.charCodeAt(i) & 0xff;
|
|
48
|
+
}
|
|
49
|
+
return buf;
|
|
50
|
+
};
|
|
51
|
+
export const join = (array) => array.join(SEPARATOR_TOKEN);
|
|
52
|
+
export const split = (text) => text.split(SEPARATOR_TOKEN);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
export * from './constants/index.js';
|
|
2
|
-
export * from './date/index.js';
|
|
3
2
|
export * from './dto/index.js';
|
|
4
|
-
export * from './errors/index.js';
|
|
5
3
|
export * from './helpers/index.js';
|
|
6
|
-
export * from './number/index.js';
|
|
7
4
|
export * from './prisma/enums/index.js';
|
|
8
5
|
export * from './types/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
export * from './constants/index.js';
|
|
2
|
-
export * from './date/index.js';
|
|
3
2
|
export * from './dto/index.js';
|
|
4
|
-
export * from './errors/index.js';
|
|
5
3
|
export * from './helpers/index.js';
|
|
6
|
-
export * from './number/index.js';
|
|
7
4
|
export * from './prisma/enums/index.js';
|
|
8
5
|
export * from './types/index.js';
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
export { AssignmentClassType } from './AssignmentClassType.js';
|
|
2
|
-
export { ContestStatus } from './ContestStatus.js';
|
|
3
|
-
export { ContestProblemPrerequisiteType } from './ContestProblemPrerequisiteType.js';
|
|
4
2
|
export { ContestEventAction } from './ContestEventAction.js';
|
|
3
|
+
export { ContestProblemPrerequisiteType } from './ContestProblemPrerequisiteType.js';
|
|
4
|
+
export { ContestRole } from './ContestRole.js';
|
|
5
|
+
export { ContestStatus } from './ContestStatus.js';
|
|
6
|
+
export { CourseRole } from './CourseRole.js';
|
|
5
7
|
export { EntityObjectType } from './EntityObjectType.js';
|
|
6
|
-
export { EntitySubjectType } from './EntitySubjectType.js';
|
|
7
8
|
export { EntityRole } from './EntityRole.js';
|
|
8
|
-
export {
|
|
9
|
+
export { EntitySubjectType } from './EntitySubjectType.js';
|
|
10
|
+
export { FileRole } from './FileRole.js';
|
|
9
11
|
export { FileType } from './FileType.js';
|
|
10
12
|
export { GroupType } from './GroupType.js';
|
|
11
13
|
export { JudgeType } from './JudgeType.js';
|
|
12
14
|
export { OrganizationPlan } from './OrganizationPlan.js';
|
|
13
|
-
export {
|
|
15
|
+
export { ProblemRole } from './ProblemRole.js';
|
|
14
16
|
export { ProblemScoringMode } from './ProblemScoringMode.js';
|
|
17
|
+
export { ProblemType } from './ProblemType.js';
|
|
15
18
|
export { ProblemVerdict } from './ProblemVerdict.js';
|
|
19
|
+
export { ShareLinkVisibility } from './ShareLinkVisibility.js';
|
|
16
20
|
export { SubmissionRunStatus } from './SubmissionRunStatus.js';
|
|
17
|
-
export { TelemetryType } from './TelemetryType.js';
|
|
18
|
-
export { UserRole } from './UserRole.js';
|
|
19
21
|
export { SystemRole } from './SystemRole.js';
|
|
20
|
-
export { ProblemRole } from './ProblemRole.js';
|
|
21
|
-
export { ContestRole } from './ContestRole.js';
|
|
22
22
|
export { TeamRole } from './TeamRole.js';
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
23
|
+
export { TelemetryType } from './TelemetryType.js';
|
|
24
|
+
export { UserRole } from './UserRole.js';
|
|
25
25
|
export { WorkingIn } from './WorkingIn.js';
|
|
26
26
|
export { WorksheetContentType } from './WorksheetContentType.js';
|