@juki-team/commons 0.1.32 → 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.
Files changed (97) hide show
  1. package/dist/constants/commons.d.ts +1 -1
  2. package/dist/constants/commons.js +1 -1
  3. package/dist/constants/index.d.ts +1 -1
  4. package/dist/constants/index.js +1 -1
  5. package/dist/dto/index.d.ts +2 -1
  6. package/dist/dto/index.js +2 -1
  7. package/dist/helpers/array.d.ts +3 -0
  8. package/dist/helpers/array.js +28 -0
  9. package/dist/helpers/console.d.ts +3 -0
  10. package/dist/helpers/console.js +9 -0
  11. package/dist/helpers/date.d.ts +68 -0
  12. package/dist/helpers/date.js +181 -0
  13. package/dist/helpers/document.d.ts +1 -11
  14. package/dist/helpers/document.js +1 -21
  15. package/dist/helpers/duration.d.ts +2 -0
  16. package/dist/helpers/duration.js +57 -0
  17. package/dist/helpers/entity.d.ts +11 -0
  18. package/dist/helpers/entity.js +20 -0
  19. package/dist/helpers/file.d.ts +6 -1
  20. package/dist/helpers/file.js +23 -2
  21. package/dist/helpers/http.d.ts +1 -0
  22. package/dist/helpers/http.js +8 -0
  23. package/dist/helpers/index.d.ts +12 -3
  24. package/dist/helpers/index.js +12 -3
  25. package/dist/helpers/json.d.ts +3 -0
  26. package/dist/helpers/json.js +31 -0
  27. package/dist/helpers/number.d.ts +2 -0
  28. package/dist/helpers/number.js +2 -0
  29. package/dist/helpers/object.d.ts +2 -0
  30. package/dist/helpers/object.js +28 -0
  31. package/dist/helpers/problem.d.ts +2 -0
  32. package/dist/helpers/problem.js +1 -0
  33. package/dist/helpers/responses.d.ts +1 -1
  34. package/dist/helpers/responses.js +3 -2
  35. package/dist/helpers/string.d.ts +7 -0
  36. package/dist/helpers/string.js +52 -0
  37. package/dist/index.d.ts +0 -1
  38. package/dist/index.js +0 -1
  39. package/dist/prisma/enums/index.d.ts +11 -11
  40. package/dist/prisma/enums/index.js +11 -11
  41. package/dist/types/assignment.d.ts +28 -0
  42. package/dist/types/assignment.js +7 -0
  43. package/dist/types/class.d.ts +1 -27
  44. package/dist/types/class.js +1 -7
  45. package/dist/types/code.d.ts +39 -0
  46. package/dist/types/{commons.js → code.js} +0 -28
  47. package/dist/types/contest.d.ts +2 -2
  48. package/dist/types/device.d.ts +7 -0
  49. package/dist/types/device.js +1 -0
  50. package/dist/types/duration.d.ts +7 -0
  51. package/dist/types/duration.js +1 -0
  52. package/dist/types/entity.d.ts +12 -0
  53. package/dist/types/entity.js +14 -0
  54. package/dist/types/id.d.ts +3 -0
  55. package/dist/types/id.js +1 -0
  56. package/dist/types/index.d.ts +10 -5
  57. package/dist/types/index.js +10 -5
  58. package/dist/types/judge.d.ts +1 -1
  59. package/dist/types/{problems.d.ts → problem.d.ts} +2 -1
  60. package/dist/types/services.d.ts +1 -1
  61. package/dist/types/socket.d.ts +1 -1
  62. package/dist/types/state.d.ts +12 -0
  63. package/dist/types/state.js +14 -0
  64. package/dist/types/teams.d.ts +1 -1
  65. package/dist/types/text.d.ts +4 -0
  66. package/dist/types/text.js +1 -0
  67. package/dist/types/{users.d.ts → user.d.ts} +1 -1
  68. package/dist/types/{users.js → user.js} +1 -1
  69. package/dist/types/worksheet.d.ts +105 -2
  70. package/dist/types/worksheet.js +16 -0
  71. package/package.json +21 -4
  72. package/dist/helpers/commons.d.ts +0 -33
  73. package/dist/helpers/commons.js +0 -191
  74. package/dist/helpers/time.d.ts +0 -13
  75. package/dist/helpers/time.js +0 -101
  76. package/dist/prototypes/Date.d.ts +0 -62
  77. package/dist/prototypes/Date.js +0 -218
  78. package/dist/prototypes/Number.d.ts +0 -7
  79. package/dist/prototypes/Number.js +0 -8
  80. package/dist/prototypes/index.d.ts +0 -3
  81. package/dist/prototypes/index.js +0 -3
  82. package/dist/types/commons.d.ts +0 -84
  83. package/dist/types/sheet.d.ts +0 -104
  84. package/dist/types/sheet.js +0 -16
  85. /package/dist/constants/{time.d.ts → duration.d.ts} +0 -0
  86. /package/dist/constants/{time.js → duration.js} +0 -0
  87. /package/dist/dto/{virtual-user.d.ts → virtualUser.d.ts} +0 -0
  88. /package/dist/dto/{virtual-user.js → virtualUser.js} +0 -0
  89. /package/dist/dto/{worksheet-submissions.d.ts → worksheetSubmission.d.ts} +0 -0
  90. /package/dist/dto/{worksheet-submissions.js → worksheetSubmission.js} +0 -0
  91. /package/dist/helpers/{class.d.ts → assignment.d.ts} +0 -0
  92. /package/dist/helpers/{class.js → assignment.js} +0 -0
  93. /package/dist/{prototypes/Error.d.ts → helpers/errors.d.ts} +0 -0
  94. /package/dist/{prototypes/Error.js → helpers/errors.js} +0 -0
  95. /package/dist/types/{problems.js → problem.js} +0 -0
  96. /package/dist/types/{account.d.ts → profile.d.ts} +0 -0
  97. /package/dist/types/{account.js → profile.js} +0 -0
@@ -31,7 +31,7 @@ export declare const CODE_LANGUAGE: {
31
31
  [Key in CodeLanguage]: CodeLanguageMeta;
32
32
  };
33
33
  export declare const PAGE_SIZES: string[];
34
- export declare const PALLETE: {
34
+ export declare const PALETTE: {
35
35
  vivos: {
36
36
  color: string;
37
37
  title: string;
@@ -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 PALLETE = {
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';
@@ -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';
@@ -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 './worksheet-submissions.js';
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 './worksheet-submissions.js';
25
+ export * from './worksheetSubmission.js';
@@ -0,0 +1,3 @@
1
+ export declare const mex: (array: number[]) => number;
2
+ export declare const range: (start: number, end: number) => number[];
3
+ export declare const areArraysDifferent: <T>(a: T[], b: T[]) => boolean;
@@ -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,3 @@
1
+ export declare const consoleWarn: (...warn: unknown[]) => void;
2
+ export declare const consoleInfo: (...info: unknown[]) => void;
3
+ export declare const consoleError: (...error: unknown[]) => void;
@@ -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
+ };
@@ -0,0 +1,68 @@
1
+ export declare const changeYear: (date: Date, year: number) => Date;
2
+ export declare const changeMonth: (date: Date, monthIndex: number) => Date;
3
+ export declare const changeDay: (date: Date, day: number) => Date;
4
+ export declare const changeHours: (date: Date, hours: number) => Date;
5
+ export declare const changeMinutes: (date: Date, minutes: number) => Date;
6
+ export declare const changeSeconds: (date: Date, seconds: number) => Date;
7
+ export declare const changeMilliseconds: (date: Date, milliseconds: number) => Date;
8
+ export declare const decreaseYear: (date: Date, count?: number) => Date;
9
+ export declare const increaseYear: (date: Date, count?: number) => Date;
10
+ export declare const decreaseMonth: (date: Date) => Date;
11
+ export declare const increaseMonth: (date: Date) => Date;
12
+ export declare const decreaseDay: (date: Date) => Date;
13
+ export declare const increaseDay: (date: Date) => Date;
14
+ export declare const startOfDay: (date: Date) => Date;
15
+ export declare const endOfDay: (date: Date) => Date;
16
+ export declare const startOfMonth: (date: Date) => Date;
17
+ export declare const endOfMonth: (date: Date) => Date;
18
+ export declare const startOfYear: (date: Date) => Date;
19
+ export declare const endOfYear: (date: Date) => Date;
20
+ export declare const startOfWeek: (date: Date) => Date;
21
+ export declare const endOfWeek: (date: Date) => Date;
22
+ export declare const startOfHour: (date: Date) => Date;
23
+ export declare const endOfHour: (date: Date) => Date;
24
+ export declare const startOfMinute: (date: Date) => Date;
25
+ export declare const endOfMinute: (date: Date) => Date;
26
+ export declare const startOfSecond: (date: Date) => Date;
27
+ export declare const endOfSecond: (date: Date) => Date;
28
+ export declare const isEqual: (a: Date, b: Date) => boolean;
29
+ export declare const isSameYear: (a: Date, b: Date) => boolean;
30
+ export declare const isSameMonth: (a: Date, b: Date) => boolean;
31
+ export declare const isSameDay: (a: Date, b: Date) => boolean;
32
+ export declare const isSameHour: (a: Date, b: Date) => boolean;
33
+ export declare const isSameMinute: (a: Date, b: Date) => boolean;
34
+ export declare const isSameSecond: (a: Date, b: Date) => boolean;
35
+ export declare const isSameMillisecond: (a: Date, b: Date) => boolean;
36
+ export declare const isToday: (date: Date) => boolean;
37
+ export declare const isValidDate: (date: unknown) => date is Date;
38
+ export declare const isAfter: (a: Date, b: Date) => boolean;
39
+ export declare const isBefore: (a: Date, b: Date) => boolean;
40
+ export declare const isYearAfter: (a: Date, b: Date) => boolean;
41
+ export declare const isMonthAfter: (a: Date, b: Date) => boolean;
42
+ export declare const isDayAfter: (a: Date, b: Date) => boolean;
43
+ export declare const isHoursAfter: (a: Date, b: Date) => boolean;
44
+ export declare const isMinutesAfter: (a: Date, b: Date) => boolean;
45
+ export declare const isSecondsAfter: (a: Date, b: Date) => boolean;
46
+ export declare const isMillisecondsAfter: (a: Date, b: Date) => boolean;
47
+ export declare const isYearBefore: (a: Date, b: Date) => boolean;
48
+ export declare const isMonthBefore: (a: Date, b: Date) => boolean;
49
+ export declare const isDayBefore: (a: Date, b: Date) => boolean;
50
+ export declare const isHoursBefore: (a: Date, b: Date) => boolean;
51
+ export declare const isMinutesBefore: (a: Date, b: Date) => boolean;
52
+ export declare const isSecondsBefore: (a: Date, b: Date) => boolean;
53
+ export declare const isMillisecondsBefore: (a: Date, b: Date) => boolean;
54
+ export declare const isWithinInterval: (date: Date, { start, end }: {
55
+ start: Date;
56
+ end: Date;
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;
@@ -0,0 +1,181 @@
1
+ import { ONE_DAY, ONE_HOUR, ONE_MINUTE } from '../constants/index.js';
2
+ export const changeYear = (date, year) => {
3
+ const newDate = new Date(date);
4
+ newDate.setFullYear(year);
5
+ return newDate;
6
+ };
7
+ export const changeMonth = (date, monthIndex) => {
8
+ const newDate = new Date(date);
9
+ newDate.setMonth(monthIndex);
10
+ return newDate;
11
+ };
12
+ export const changeDay = (date, day) => {
13
+ const newDate = new Date(date);
14
+ newDate.setDate(day);
15
+ return newDate;
16
+ };
17
+ export const changeHours = (date, hours) => {
18
+ const newDate = new Date(date);
19
+ newDate.setHours(hours);
20
+ return newDate;
21
+ };
22
+ export const changeMinutes = (date, minutes) => {
23
+ const newDate = new Date(date);
24
+ newDate.setMinutes(minutes);
25
+ return newDate;
26
+ };
27
+ export const changeSeconds = (date, seconds) => {
28
+ const newDate = new Date(date);
29
+ newDate.setSeconds(seconds);
30
+ return newDate;
31
+ };
32
+ export const changeMilliseconds = (date, milliseconds) => {
33
+ const newDate = new Date(date);
34
+ newDate.setMilliseconds(milliseconds);
35
+ return newDate;
36
+ };
37
+ export const decreaseYear = (date, count = 1) => changeYear(date, date.getFullYear() - count);
38
+ export const increaseYear = (date, count = 1) => changeYear(date, date.getFullYear() + count);
39
+ export const decreaseMonth = (date) => {
40
+ const newDate = new Date(date);
41
+ newDate.setMonth(newDate.getMonth() - 1);
42
+ return newDate;
43
+ };
44
+ export const increaseMonth = (date) => {
45
+ const newDate = new Date(date);
46
+ newDate.setMonth(newDate.getMonth() + 1);
47
+ return newDate;
48
+ };
49
+ export const decreaseDay = (date) => {
50
+ const newDate = new Date(date);
51
+ newDate.setDate(newDate.getDate() - 1);
52
+ return newDate;
53
+ };
54
+ export const increaseDay = (date) => {
55
+ const newDate = new Date(date);
56
+ newDate.setDate(newDate.getDate() + 1);
57
+ return newDate;
58
+ };
59
+ export const startOfDay = (date) => {
60
+ const newDate = new Date(date);
61
+ newDate.setHours(0, 0, 0, 0);
62
+ return newDate;
63
+ };
64
+ export const endOfDay = (date) => {
65
+ const newDate = new Date(date);
66
+ newDate.setHours(23, 59, 59, 999);
67
+ return newDate;
68
+ };
69
+ export const startOfMonth = (date) => {
70
+ const newDate = new Date(date);
71
+ newDate.setDate(1);
72
+ return startOfDay(newDate);
73
+ };
74
+ export const endOfMonth = (date) => {
75
+ const nextMonth = startOfMonth(increaseMonth(date));
76
+ return new Date(nextMonth.getTime() - 1);
77
+ };
78
+ export const startOfYear = (date) => {
79
+ const newDate = new Date(date);
80
+ newDate.setMonth(0);
81
+ return startOfMonth(newDate);
82
+ };
83
+ export const endOfYear = (date) => {
84
+ const nextYear = startOfYear(increaseYear(date));
85
+ return new Date(nextYear.getTime() - 1);
86
+ };
87
+ export const startOfWeek = (date) => {
88
+ const newDate = new Date(date);
89
+ while (newDate.getDay()) {
90
+ newDate.setDate(newDate.getDate() - 1);
91
+ }
92
+ return startOfDay(newDate);
93
+ };
94
+ export const endOfWeek = (date) => {
95
+ const newDate = new Date(date);
96
+ while (newDate.getDay() < 6) {
97
+ newDate.setDate(newDate.getDate() + 1);
98
+ }
99
+ return endOfDay(newDate);
100
+ };
101
+ export const startOfHour = (date) => {
102
+ const newDate = new Date(date);
103
+ newDate.setMinutes(0, 0, 0);
104
+ return newDate;
105
+ };
106
+ export const endOfHour = (date) => {
107
+ const newDate = new Date(date);
108
+ newDate.setMinutes(59, 59, 999);
109
+ return newDate;
110
+ };
111
+ export const startOfMinute = (date) => {
112
+ const newDate = new Date(date);
113
+ newDate.setSeconds(0, 0);
114
+ return newDate;
115
+ };
116
+ export const endOfMinute = (date) => {
117
+ const newDate = new Date(date);
118
+ newDate.setSeconds(59, 999);
119
+ return newDate;
120
+ };
121
+ export const startOfSecond = (date) => {
122
+ const newDate = new Date(date);
123
+ newDate.setMilliseconds(0);
124
+ return newDate;
125
+ };
126
+ export const endOfSecond = (date) => {
127
+ const newDate = new Date(date);
128
+ newDate.setMilliseconds(999);
129
+ return newDate;
130
+ };
131
+ export const isEqual = (a, b) => a.getTime() === b.getTime();
132
+ export const isSameYear = (a, b) => a.getFullYear() === b.getFullYear();
133
+ export const isSameMonth = (a, b) => isSameYear(a, b) && a.getMonth() === b.getMonth();
134
+ export const isSameDay = (a, b) => isSameMonth(a, b) && a.getDate() === b.getDate();
135
+ export const isSameHour = (a, b) => isSameDay(a, b) && a.getHours() === b.getHours();
136
+ export const isSameMinute = (a, b) => isSameHour(a, b) && a.getMinutes() === b.getMinutes();
137
+ export const isSameSecond = (a, b) => isSameMinute(a, b) && a.getSeconds() === b.getSeconds();
138
+ export const isSameMillisecond = (a, b) => isEqual(a, b);
139
+ export const isToday = (date) => isSameDay(date, new Date());
140
+ export const isValidDate = (date) => date instanceof Date && !Number.isNaN(date.getTime());
141
+ export const isAfter = (a, b) => a.getTime() > b.getTime();
142
+ export const isBefore = (a, b) => a.getTime() < b.getTime();
143
+ export const isYearAfter = (a, b) => a.getFullYear() > b.getFullYear();
144
+ export const isMonthAfter = (a, b) => isYearAfter(a, b) || (isSameYear(a, b) && a.getMonth() > b.getMonth());
145
+ export const isDayAfter = (a, b) => isMonthAfter(a, b) || (isSameMonth(a, b) && a.getDate() > b.getDate());
146
+ export const isHoursAfter = (a, b) => isDayAfter(a, b) || (isSameDay(a, b) && a.getHours() > b.getHours());
147
+ export const isMinutesAfter = (a, b) => isHoursAfter(a, b) || (isSameHour(a, b) && a.getMinutes() > b.getMinutes());
148
+ export const isSecondsAfter = (a, b) => isMinutesAfter(a, b) || (isSameMinute(a, b) && a.getSeconds() > b.getSeconds());
149
+ export const isMillisecondsAfter = (a, b) => isSecondsAfter(a, b) || (isSameSecond(a, b) && a.getMilliseconds() > b.getMilliseconds());
150
+ export const isYearBefore = (a, b) => a.getFullYear() < b.getFullYear();
151
+ export const isMonthBefore = (a, b) => isYearBefore(a, b) || (isSameYear(a, b) && a.getMonth() < b.getMonth());
152
+ export const isDayBefore = (a, b) => isMonthBefore(a, b) || (isSameMonth(a, b) && a.getDate() < b.getDate());
153
+ export const isHoursBefore = (a, b) => isDayBefore(a, b) || (isSameDay(a, b) && a.getHours() < b.getHours());
154
+ export const isMinutesBefore = (a, b) => isHoursBefore(a, b) || (isSameHour(a, b) && a.getMinutes() < b.getMinutes());
155
+ export const isSecondsBefore = (a, b) => isMinutesBefore(a, b) || (isSameMinute(a, b) && a.getSeconds() < b.getSeconds());
156
+ export const isMillisecondsBefore = (a, b) => isSecondsBefore(a, b) || (isSameSecond(a, b) && a.getMilliseconds() < b.getMilliseconds());
157
+ export const isWithinInterval = (date, { start, end }, cmp = '[]') => (cmp.charAt(0) === '[' ? isEqual(date, start) || isAfter(date, start) : isAfter(date, start)) &&
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 type { EntityMembersDTO, EntityMembersResponseDTO } from '../dto/index.js';
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;
@@ -1,4 +1,4 @@
1
- import { EntityAccess, EntityMembersRank, } from '../types/index.js';
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,2 @@
1
+ import type { SplitTime } from '../types/index.js';
2
+ export declare const splitTime: (timeRemaining: number) => [SplitTime, SplitTime, SplitTime, SplitTime, SplitTime, SplitTime];
@@ -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
+ };
@@ -1 +1,6 @@
1
- export declare function removeExtension(fileName: string): string;
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;
@@ -1,4 +1,25 @@
1
- export function removeExtension(fileName) {
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>;
@@ -0,0 +1,8 @@
1
+ export const getPlainText = async (url) => {
2
+ return await fetch(url)
3
+ .then((data) => data.text())
4
+ .catch((error) => {
5
+ console.error('ERROR:', error);
6
+ return '';
7
+ });
8
+ };
@@ -1,14 +1,23 @@
1
- export * from './class.js';
1
+ export * from './array.js';
2
+ export * from './assignment.js';
2
3
  export * from './comments.js';
3
- export * from './commons.js';
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 './time.js';
21
+ export * from './string.js';
13
22
  export * from './user.js';
14
23
  export * from './worksheet.js';
@@ -1,14 +1,23 @@
1
- export * from './class.js';
1
+ export * from './array.js';
2
+ export * from './assignment.js';
2
3
  export * from './comments.js';
3
- export * from './commons.js';
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 './time.js';
21
+ export * from './string.js';
13
22
  export * from './user.js';
14
23
  export * from './worksheet.js';
@@ -0,0 +1,3 @@
1
+ export declare const isStringJson: (str: unknown) => str is string;
2
+ export declare const safeJsonParse: (str: unknown) => unknown;
3
+ export declare const isObjectJson: (obj: unknown) => boolean;
@@ -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
+ };
@@ -0,0 +1,2 @@
1
+ export declare const padStart: (n: number, maxLength: number, fillString?: string) => string;
2
+ export declare const padEnd: (n: number, maxLength: number, fillString?: string) => string;