parse-comcigan 0.0.3 → 0.0.5

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 CHANGED
@@ -31,7 +31,7 @@ import Comcigan from 'parse-comcigan';
31
31
 
32
32
  const comci = new Comcigan({
33
33
  "cacheMs": 10000, // 10초동안 캐시됩니다.
34
- "doNotThrow": true, // true일때, status가 4 또는 5로 시작하면 throw 됩니다.
34
+ "doNotThrow": false, // false일때, status가 4 또는 5로 시작하면 throw 됩니다.
35
35
  "debug": (msg) => console.log(msg) // 모듈에서 디버그 메시지를 보내면 콘솔에 출력합니다.
36
36
  });
37
37
  ```
@@ -70,17 +70,27 @@ comci.SearchSchool("서울").then(data => {
70
70
 
71
71
  |파라메터|타입|필수|설명|
72
72
  |------|------|------|-----------|
73
- |schoolCode|number|Yes|학교 코드|
74
- |criteria|"weekday" or "period"|Yes|리스트 반환을 어떻게 할지 여부입니다.|
75
- |grade|number|Yes|학년|
76
- |classN|number|Yes|반|
73
+ |options|[GetTimetableOptions](#gettimetableoptions)|Yes|옵션|
77
74
 
78
75
  ```typescript
79
- comci.GetTimetable(96211, "period", 3, 5).then(data => {
80
- console.log(data[0][5]); // [요일][교시] 월요일 5교시
76
+ comci.GetTimetable({
77
+ "schoolCode": 96211,
78
+ "criteria": "period",
79
+ "grade": 3,
80
+ "classN": 5,
81
+ "without8th": false
82
+ }).then(data => {
83
+ console.log(data.timetable[0][7]); // [요일][교시] 월요일 8교시
81
84
  });
82
- comci.GetTimetable(96211, "weekday", 3, 5).then(data => {
83
- console.log(data[5][0]); // [교시][요일] 월요일 5교시
85
+ comci.GetTimetable({
86
+ "schoolCode": 96211,
87
+ "criteria": "weekday",
88
+ "grade": 3,
89
+ "classN": 5,
90
+ "without8th": true
91
+ }).then(data => {
92
+ console.log(data.timetable[4][0]); // [교시][요일] 월요일 5교시
93
+ console.log(data.timetable[7]); // undefined
84
94
  });
85
95
  ```
86
96
 
@@ -120,8 +130,31 @@ comci.GetClassList(96211).then(data => {
120
130
  |changed|string|교사|Yes|
121
131
  |original|여기서 original만 빠진 오브젝트|원래 시간표|No|
122
132
 
133
+ ### GetTimetableOptions
134
+
135
+ |파라메터|타입|필수|설명|
136
+ |------|------|------|-----------|
137
+ |schoolCode|number|Yes|학교 코드|
138
+ |criteria|"weekday" or "period"|Yes|리스트 반환을 어떻게 할지 여부입니다.|
139
+ |grade|number|Yes|학년|
140
+ |classN|number|Yes|반|
141
+
123
142
  ## 업데이트 로그
124
143
 
144
+ ### 0.0.5
145
+
146
+ - 문서의 많은 오류 수정
147
+ - 8교시 제외 추가
148
+
149
+ ### 0.0.4
150
+
151
+ - 모듈이 불러와지지 않던 버그 수정
152
+
153
+ ### 0.0.3
154
+
155
+ - undefined 참조 버그 수정
156
+ - 문서 잘못되어있던 버그 수정
157
+
125
158
  ### 0.0.2
126
159
 
127
160
  - package.json 수정
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "parse-comcigan",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "컴시간 알리미에서 시간표를 가져오는 라이브러리입니다.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "dev": "nodemon --exec ts-node src/index.ts"
15
15
  },
16
16
  "devDependencies": {
17
- "@types/node": "^22.14.1",
17
+ "@types/node": "^22.15.30",
18
18
  "nodemon": "^3.1.9",
19
19
  "ts-node": "^10.9.2",
20
20
  "typescript": "^5.8.3"
@@ -36,4 +36,4 @@
36
36
  "bugs": {
37
37
  "url": "https://github.com/Pro203S/parse-comcigan/issues"
38
38
  }
39
- }
39
+ }
package/src/cache.ts ADDED
@@ -0,0 +1,32 @@
1
+ export default class Cache {
2
+ private _cacheStorage: Collection<{
3
+ "timeout": NodeJS.Timeout;
4
+ "data": any;
5
+ }> = {};
6
+
7
+ public register(id: string, data: any, duration: number) {
8
+ this._cacheStorage[id] = {
9
+ "timeout": setTimeout(() => {
10
+ delete this._cacheStorage[id];
11
+ }, duration),
12
+ "data": data
13
+ };
14
+ }
15
+ public delete(id: string) {
16
+ clearTimeout(this._cacheStorage[id].timeout);
17
+ delete this._cacheStorage[id];
18
+ }
19
+ public clear() {
20
+ const caches = Object.keys(this._cacheStorage);
21
+ for (let cache of caches) {
22
+ clearTimeout(this._cacheStorage[cache].timeout);
23
+ delete this._cacheStorage[cache];
24
+ }
25
+ }
26
+ public has(id: string) {
27
+ return Boolean(this._cacheStorage[id]);
28
+ }
29
+ public get(id: string) {
30
+ return this._cacheStorage[id]?.data;
31
+ }
32
+ }
package/src/index.ts CHANGED
@@ -1,84 +1,33 @@
1
1
  import axios from 'axios';
2
2
  import iconv from 'iconv-lite';
3
+ import Cache from './cache.js';
3
4
 
4
- class Cache {
5
- private _cacheStorage: {
6
- [id: string]: {
7
- "timeout": NodeJS.Timeout;
8
- "data": any;
9
- }
10
- } = {};
11
-
12
- public register(id: string, data: any, duration: number) {
13
- this._cacheStorage[id] = {
14
- "timeout": setTimeout(() => {
15
- delete this._cacheStorage[id];
16
- }, duration),
17
- "data": data
18
- };
19
- }
20
- public delete(id: string) {
21
- clearTimeout(this._cacheStorage[id].timeout);
22
- delete this._cacheStorage[id];
23
- }
24
- public clear() {
25
- const caches = Object.keys(this._cacheStorage);
26
- for (let cache of caches) {
27
- clearTimeout(this._cacheStorage[cache].timeout);
28
- delete this._cacheStorage[cache];
29
- }
30
- }
31
- public has(id: string) {
32
- return Boolean(this._cacheStorage[id]);
33
- }
34
- public get(id: string) {
35
- return this._cacheStorage[id]?.data;
36
- }
37
- }
38
-
39
- //#region 내부 타입
40
- type RawComciganSearched = {
41
- "학교검색": [
42
- number,
43
- string,
44
- string,
45
- number
46
- ][];
47
- };
48
- type RawComciganTimetable = {
49
- 교사수: number;
50
- 성명: string[];
51
- 학급수: number[];
52
- 요일별시수: number[][];
53
- 과목명: any[];
54
- 시간표: any;
55
- 전일제: number[];
56
- 버젼: string;
57
- 동시수업수: number;
58
- 담임: number[][];
59
- 가상학급수: number[];
60
- 특별실수: number;
61
- 열람제한일: string;
62
- 저장일: string;
63
- 학기시작일자: string;
64
- 학교명: string;
65
- 지역명: string;
66
- 학년도: number;
67
- 분리?: number;
68
- 강의실: number;
69
- 시작일: string;
70
- 일과시간: string[];
71
- 일자자료: [number, string][];
72
- 오늘r: number;
73
- 학급시간표: any;
74
- 교사시간표: any[];
75
- 강의실시간표: any;
76
- 동시그룹: number[][];
77
- 컴시간?: string;
5
+ //#region 타입 export
6
+ export type GetTimetableOptions = {
7
+ /**
8
+ * 컴시간 학교 코드입니다.
9
+ */
10
+ "schoolCode": number,
11
+ /**
12
+ * 구분을 어떻게 할지 여부입니다.
13
+ *
14
+ * - weekday로 설정하면 시간표[교시][요일]로 과목과 선생님을 불러옵니다.
15
+ * - period로 설정하면 시간표[요일][교시]로 과목과 선생님을 불러옵니다.
16
+ */
17
+ "criteria": "weekday" | "period",
18
+ /**
19
+ * 학년입니다.
20
+ */
21
+ "grade": number,
22
+ /**
23
+ * 반입니다.
24
+ */
25
+ "classN": number,
26
+ /**
27
+ * 8교시를 빼고 리턴할지 여부입니다.
28
+ */
29
+ "without8th"?: boolean,
78
30
  };
79
- //#endregion
80
-
81
- //#region 외부 타입
82
31
  export interface ComciganInitializeType {
83
32
  /**
84
33
  * 이 기간동안 컴시간과 통신한 데이터가 캐시됩니다.
@@ -230,7 +179,9 @@ export default class Comcigan {
230
179
  * @param schoolCode
231
180
  * @param criteria
232
181
  */
233
- public async GetTimetable(schoolCode: number, criteria: "weekday" | "period", grade: number, classN: number): Promise<ComciganTimetable | undefined> {
182
+ public async GetTimetable(options: GetTimetableOptions): Promise<ComciganTimetable | undefined> {
183
+ const { schoolCode, criteria, grade, classN, without8th } = options;
184
+
234
185
  const str = `36174_${schoolCode}_1_4_0_3_1.00`;
235
186
  const route = (str.substring(9) + str.substring(0, 9)).split("").reverse().join("");
236
187
  const data = await this.request<string>(`7813?${route}`, true);
@@ -254,7 +205,7 @@ export default class Comcigan {
254
205
  if (criteria === "period") {
255
206
  for (let weekday = 1; weekday < WEEKDAY.length + 1; weekday++) {
256
207
  const weekdayList: ComciganTimetableObject[] = [];
257
- for (let period = 1; period < 9; period++) {
208
+ for (let period = 1; period < (without8th ? 8 : 9); period++) {
258
209
  const o = origin[weekday][period];
259
210
  const t = today[weekday][period];
260
211
 
@@ -292,7 +243,7 @@ export default class Comcigan {
292
243
  toReturn.push(weekdayList);
293
244
  }
294
245
  } else {
295
- for (let period = 1; period < 9; period++) {
246
+ for (let period = 1; period < (without8th ? 8 : 9); period++) {
296
247
  const periodList: ComciganTimetableObject[] = [];
297
248
  for (let weekday = 1; weekday < WEEKDAY.length + 1; weekday++) {
298
249
  const o = origin[weekday][period];
@@ -356,9 +307,9 @@ export default class Comcigan {
356
307
  const json: RawComciganTimetable = JSON.parse(step2.slice(0, step2.indexOf("}") + 1));
357
308
  const rawClasses = json.학급수;
358
309
  if (!rawClasses) return [];
359
-
310
+
360
311
  const toReturn: string[] = [];
361
-
312
+
362
313
  for (let g = 1; g < rawClasses.length; g++) {
363
314
  for (let c = 1; c < rawClasses[g] + 1; c++) {
364
315
  toReturn.push(`${g}-${c}`);
@@ -0,0 +1,45 @@
1
+ declare global {
2
+ type Collection<V = any> = { [key: string]: V };
3
+
4
+ type RawComciganSearched = {
5
+ "학교검색": [
6
+ number,
7
+ string,
8
+ string,
9
+ number
10
+ ][];
11
+ };
12
+ type RawComciganTimetable = {
13
+ 교사수: number;
14
+ 성명: string[];
15
+ 학급수: number[];
16
+ 요일별시수: number[][];
17
+ 과목명: any[];
18
+ 시간표: any;
19
+ 전일제: number[];
20
+ 버젼: string;
21
+ 동시수업수: number;
22
+ 담임: number[][];
23
+ 가상학급수: number[];
24
+ 특별실수: number;
25
+ 열람제한일: string;
26
+ 저장일: string;
27
+ 학기시작일자: string;
28
+ 학교명: string;
29
+ 지역명: string;
30
+ 학년도: number;
31
+ 분리?: number;
32
+ 강의실: number;
33
+ 시작일: string;
34
+ 일과시간: string[];
35
+ 일자자료: [number, string][];
36
+ 오늘r: number;
37
+ 학급시간표: any;
38
+ 교사시간표: any[];
39
+ 강의실시간표: any;
40
+ 동시그룹: number[][];
41
+ 컴시간?: string;
42
+ };
43
+ }
44
+
45
+ export { }
package/tsconfig.json CHANGED
@@ -11,7 +11,14 @@
11
11
  "esModuleInterop": true,
12
12
  "declaration": true,
13
13
  "strict": true,
14
- "sourceMap": true
14
+ "sourceMap": true,
15
+ "types": [
16
+ "node"
17
+ ],
18
+ "typeRoots": [
19
+ "./src/types",
20
+ "./node_modules/@types"
21
+ ]
15
22
  },
16
23
  "include": [
17
24
  "src/**/*"