chuvsu-js 2.2.1 → 2.3.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.
- package/README.md +4 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/tt/schedule.d.ts +4 -1
- package/dist/tt/schedule.js +7 -2
- package/dist/tt/utils.d.ts +15 -0
- package/dist/tt/utils.js +26 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,6 +5,10 @@ Node.js библиотека для работы с порталами ЧувГ
|
|
|
5
5
|
- **tt.chuvsu.ru** — расписание занятий (факультеты, группы, преподаватели)
|
|
6
6
|
- **lk.chuvsu.ru** — личный кабинет студента (персональные данные)
|
|
7
7
|
|
|
8
|
+
> [!WARNING]
|
|
9
|
+
> Пока не доработана, код говно, замены занятий пока не парсит.
|
|
10
|
+
> Не надейтесь на правильный вывод расписания.
|
|
11
|
+
|
|
8
12
|
## Установка
|
|
9
13
|
|
|
10
14
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ export { LkClient } from "./lk/client.js";
|
|
|
2
2
|
export { TtClient } from "./tt/client.js";
|
|
3
3
|
export { Schedule } from "./tt/schedule.js";
|
|
4
4
|
export type { CacheEntry } from "./common/cache.js";
|
|
5
|
-
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, } from "./tt/utils.js";
|
|
5
|
+
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, isHoliday, RUSSIAN_HOLIDAYS, } from "./tt/utils.js";
|
|
6
|
+
export type { Holiday } from "./tt/utils.js";
|
|
6
7
|
export { Period, EducationType, AuthError, ParseError } from "./common/types.js";
|
|
7
8
|
export type { Time, WeekRange, Teacher, } from "./common/types.js";
|
|
8
9
|
export type { PersonalData, } from "./lk/types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { LkClient } from "./lk/client.js";
|
|
2
2
|
export { TtClient } from "./tt/client.js";
|
|
3
3
|
export { Schedule } from "./tt/schedule.js";
|
|
4
|
-
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, } from "./tt/utils.js";
|
|
4
|
+
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, isHoliday, RUSSIAN_HOLIDAYS, } from "./tt/utils.js";
|
|
5
5
|
export { AuthError, ParseError } from "./common/types.js";
|
package/dist/tt/schedule.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { FullScheduleDay, SemesterWeek, Lesson } from "./types.js";
|
|
2
2
|
import { Period, EducationType } from "../common/types.js";
|
|
3
|
+
import { type Holiday } from "./utils.js";
|
|
3
4
|
export declare class Schedule {
|
|
4
5
|
readonly groupId: number;
|
|
5
6
|
readonly scheduleMap: Map<number, FullScheduleDay[]>;
|
|
6
7
|
readonly educationType: EducationType;
|
|
8
|
+
/** List of holidays to exclude from schedule queries. Pass `[]` to disable. */
|
|
9
|
+
readonly holidays: Holiday[];
|
|
7
10
|
private _period?;
|
|
8
|
-
constructor(groupId: number, scheduleMap: Map<number, FullScheduleDay[]>, period?: Period, educationType?: EducationType);
|
|
11
|
+
constructor(groupId: number, scheduleMap: Map<number, FullScheduleDay[]>, period?: Period, educationType?: EducationType, holidays?: Holiday[] | null);
|
|
9
12
|
/** Current (or fixed) period for this schedule. */
|
|
10
13
|
get period(): Period;
|
|
11
14
|
/** Days for the current period. */
|
package/dist/tt/schedule.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { getCurrentPeriod, isSessionPeriod, getWeekdayName, getMonday, getSemesterStart, getSemesterWeeks, getWeekNumber, getAdjacentSemester, filterSlots, slotsToLessons, sortLessons, } from "./utils.js";
|
|
1
|
+
import { getCurrentPeriod, isSessionPeriod, getWeekdayName, getMonday, getSemesterStart, getSemesterWeeks, getWeekNumber, getAdjacentSemester, filterSlots, slotsToLessons, sortLessons, isHoliday, RUSSIAN_HOLIDAYS, } from "./utils.js";
|
|
2
2
|
export class Schedule {
|
|
3
3
|
groupId;
|
|
4
4
|
scheduleMap;
|
|
5
5
|
educationType;
|
|
6
|
+
/** List of holidays to exclude from schedule queries. Pass `[]` to disable. */
|
|
7
|
+
holidays;
|
|
6
8
|
_period;
|
|
7
|
-
constructor(groupId, scheduleMap, period, educationType) {
|
|
9
|
+
constructor(groupId, scheduleMap, period, educationType, holidays) {
|
|
8
10
|
this.groupId = groupId;
|
|
9
11
|
this.scheduleMap = scheduleMap;
|
|
10
12
|
this.educationType = educationType ?? 1 /* EducationType.HigherEducation */;
|
|
11
13
|
this._period = period;
|
|
14
|
+
this.holidays = holidays ?? RUSSIAN_HOLIDAYS;
|
|
12
15
|
}
|
|
13
16
|
/** Current (or fixed) period for this schedule. */
|
|
14
17
|
get period() {
|
|
@@ -77,6 +80,8 @@ export class Schedule {
|
|
|
77
80
|
return slotsToLessons(slots, date);
|
|
78
81
|
}
|
|
79
82
|
forDate(date, opts) {
|
|
83
|
+
if (isHoliday(date, this.holidays))
|
|
84
|
+
return [];
|
|
80
85
|
const period = getCurrentPeriod({ date });
|
|
81
86
|
const lessons = [];
|
|
82
87
|
// 1. Check all periods for date-based (session) entries matching this date
|
package/dist/tt/utils.d.ts
CHANGED
|
@@ -41,3 +41,18 @@ export declare function slotsToLessons(slots: FullScheduleSlot[], date: Date): L
|
|
|
41
41
|
export declare function getTimeSlots(educationType: EducationType): LessonTimeSlot[];
|
|
42
42
|
export declare function getLessonNumber(time: Time, educationType: EducationType): number;
|
|
43
43
|
export declare function getAdjacentSemester(session: Period): Period;
|
|
44
|
+
export interface Holiday {
|
|
45
|
+
/** Month number, 1–12. */
|
|
46
|
+
month: number;
|
|
47
|
+
/** Day of month. */
|
|
48
|
+
day: number;
|
|
49
|
+
/** Human-readable name. */
|
|
50
|
+
name: string;
|
|
51
|
+
}
|
|
52
|
+
/** Russian non-working public holidays (Статья 112 ТК РФ). */
|
|
53
|
+
export declare const RUSSIAN_HOLIDAYS: Holiday[];
|
|
54
|
+
/**
|
|
55
|
+
* Returns true if the given date falls on a holiday.
|
|
56
|
+
* Pass an empty array to disable holiday checking.
|
|
57
|
+
*/
|
|
58
|
+
export declare function isHoliday(date: Date, holidays?: Holiday[]): boolean;
|
package/dist/tt/utils.js
CHANGED
|
@@ -251,3 +251,29 @@ export function getAdjacentSemester(session) {
|
|
|
251
251
|
? 1 /* Period.FallSemester */
|
|
252
252
|
: 3 /* Period.SpringSemester */;
|
|
253
253
|
}
|
|
254
|
+
/** Russian non-working public holidays (Статья 112 ТК РФ). */
|
|
255
|
+
export const RUSSIAN_HOLIDAYS = [
|
|
256
|
+
{ month: 1, day: 1, name: "Новый год" },
|
|
257
|
+
{ month: 1, day: 2, name: "Новогодние каникулы" },
|
|
258
|
+
{ month: 1, day: 3, name: "Новогодние каникулы" },
|
|
259
|
+
{ month: 1, day: 4, name: "Новогодние каникулы" },
|
|
260
|
+
{ month: 1, day: 5, name: "Новогодние каникулы" },
|
|
261
|
+
{ month: 1, day: 6, name: "Новогодние каникулы" },
|
|
262
|
+
{ month: 1, day: 7, name: "Рождество Христово" },
|
|
263
|
+
{ month: 1, day: 8, name: "Новогодние каникулы" },
|
|
264
|
+
{ month: 2, day: 23, name: "День защитника Отечества" },
|
|
265
|
+
{ month: 3, day: 8, name: "Международный женский день" },
|
|
266
|
+
{ month: 5, day: 1, name: "Праздник Весны и Труда" },
|
|
267
|
+
{ month: 5, day: 9, name: "День Победы" },
|
|
268
|
+
{ month: 6, day: 12, name: "День России" },
|
|
269
|
+
{ month: 11, day: 4, name: "День народного единства" },
|
|
270
|
+
];
|
|
271
|
+
/**
|
|
272
|
+
* Returns true if the given date falls on a holiday.
|
|
273
|
+
* Pass an empty array to disable holiday checking.
|
|
274
|
+
*/
|
|
275
|
+
export function isHoliday(date, holidays = RUSSIAN_HOLIDAYS) {
|
|
276
|
+
const month = date.getMonth() + 1;
|
|
277
|
+
const day = date.getDate();
|
|
278
|
+
return holidays.some((h) => h.month === month && h.day === day);
|
|
279
|
+
}
|