@kuroson/cse-students 0.3.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/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +144 -0
- package/dist/index.cjs +57 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +59 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/package.json +81 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @kuroson/cse-students
|
|
2
|
+
|
|
3
|
+
## 0.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 61adb1e: Updated dependency `@typescript-eslint/eslint-plugin` to `8.50.1`.
|
|
8
|
+
Updated dependency `@typescript-eslint/parser` to `8.50.1`.
|
|
9
|
+
Updated dependency `typescript-eslint` to `8.50.1`.
|
|
10
|
+
Updated dependency `next` to `16.1.1`.
|
|
11
|
+
Updated dependency `eslint-config-next` to `16.1.1`.
|
|
12
|
+
Updated dependency `@next/third-parties` to `16.1.1`.
|
|
13
|
+
Updated dependency `ldapts` to `8.0.31`.
|
|
14
|
+
Updated dependency `@next/eslint-plugin-next` to `16.1.1`.
|
|
15
|
+
Updated dependency `eslint-plugin-jest` to `29.10.1`.
|
|
16
|
+
Updated dependency `nodemailer` to `7.0.12`.
|
|
17
|
+
|
|
18
|
+
## 0.3.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- cdb0acc: Initial release
|
|
23
|
+
|
|
24
|
+
## 0.2.0
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
- Initial public release
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Alvin Cherk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @kuroson/cse-students
|
|
2
|
+
|
|
3
|
+
Student enrolment parser for UNSW CSE courses.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @kuroson/cse-students
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @kuroson/cse-students
|
|
11
|
+
# or
|
|
12
|
+
yarn add @kuroson/cse-students
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Students, cleanUpName } from "@kuroson/cse-students";
|
|
19
|
+
import type { StudentEnrolment, TimetableInformation } from "@kuroson/cse-students";
|
|
20
|
+
|
|
21
|
+
// Parse students from a file
|
|
22
|
+
const students = new Students({
|
|
23
|
+
pathToFile: "./enrolments.txt",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Or parse from a string
|
|
27
|
+
const students = new Students({
|
|
28
|
+
givenInput: "zID|name|class\n1234567|Smith, John|T09A",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// With timetable information for class code mapping
|
|
32
|
+
const timetable: TimetableInformation = [
|
|
33
|
+
{
|
|
34
|
+
classCode: "T09",
|
|
35
|
+
expandedClassCode: "T09A",
|
|
36
|
+
tuteLabLocation: ["1-5", "Mon 10:00", "K17-101", "1-5", "Mon 11:00", "K17-102"],
|
|
37
|
+
tutors: [{ zID: "z1234567", name: "John Smith" }],
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const students = new Students({
|
|
42
|
+
pathToFile: "./enrolments.txt",
|
|
43
|
+
timeTable: timetable,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// With optional winston logger
|
|
47
|
+
import { createLogger } from "winston";
|
|
48
|
+
const logger = createLogger();
|
|
49
|
+
|
|
50
|
+
const students = new Students({
|
|
51
|
+
pathToFile: "./enrolments.txt",
|
|
52
|
+
winstonLogger: logger,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Get parsed students
|
|
56
|
+
const studentList = students.getStudents();
|
|
57
|
+
// Returns: StudentEnrolment[]
|
|
58
|
+
|
|
59
|
+
// Get timetable key mappings
|
|
60
|
+
const keys = students.getTimeTableKeys();
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## API
|
|
64
|
+
|
|
65
|
+
### `Students`
|
|
66
|
+
|
|
67
|
+
Main class for parsing student enrolments.
|
|
68
|
+
|
|
69
|
+
#### Constructor Options
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
type InputOptions = {
|
|
73
|
+
timeTable?: TimetableInformation;
|
|
74
|
+
winstonLogger?: Logger;
|
|
75
|
+
} & ({ givenInput: string; pathToFile?: never } | { pathToFile: string; givenInput?: never });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- `givenInput` - Raw enrolment data as a string (mutually exclusive with `pathToFile`)
|
|
79
|
+
- `pathToFile` - Path to enrolment file (mutually exclusive with `givenInput`)
|
|
80
|
+
- `timeTable` - Optional timetable information for class code mapping
|
|
81
|
+
- `winstonLogger` - Optional winston logger instance
|
|
82
|
+
|
|
83
|
+
#### Methods
|
|
84
|
+
|
|
85
|
+
- `getStudents()` - Returns array of parsed student enrolments
|
|
86
|
+
- `getTimeTableKeys()` - Returns mapping of expanded class codes to class codes
|
|
87
|
+
|
|
88
|
+
### `cleanUpName(name: string)`
|
|
89
|
+
|
|
90
|
+
Utility function to clean up student names from "Last, First" format.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
cleanUpName("Smith, John"); // Returns: "John Smith"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Types
|
|
97
|
+
|
|
98
|
+
#### `StudentEnrolment`
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
type StudentEnrolment = {
|
|
102
|
+
zID: string;
|
|
103
|
+
name: string;
|
|
104
|
+
class: string;
|
|
105
|
+
classCode?: string;
|
|
106
|
+
};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### `TimetableInformation`
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
type TimetableInformation = Array<{
|
|
113
|
+
classCode: string;
|
|
114
|
+
expandedClassCode: string;
|
|
115
|
+
otherExpandedClassCode?: string;
|
|
116
|
+
tuteLabLocation: [
|
|
117
|
+
tuteWeeks: string,
|
|
118
|
+
tuteTime: string,
|
|
119
|
+
tuteLocation: string,
|
|
120
|
+
labWeeks: string,
|
|
121
|
+
labTime: string,
|
|
122
|
+
labLocation: string,
|
|
123
|
+
];
|
|
124
|
+
tutors: Array<{ zID: string; name: string }>;
|
|
125
|
+
}>;
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Input Format
|
|
129
|
+
|
|
130
|
+
The expected input format is pipe-delimited with a header row:
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
zID|name|class
|
|
134
|
+
1234567|Smith, John|T09A
|
|
135
|
+
7654321|Doe, Jane|T10B
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Requirements
|
|
139
|
+
|
|
140
|
+
- Node.js >= 22
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('winston');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
|
|
6
|
+
// src/Students.ts
|
|
7
|
+
var readFileFrom = (path, encoding = "utf-8") => {
|
|
8
|
+
if (fs.existsSync(path)) {
|
|
9
|
+
return fs.readFileSync(path, encoding);
|
|
10
|
+
}
|
|
11
|
+
throw new Error(`Failed to read file from expected directory: ${path}`);
|
|
12
|
+
};
|
|
13
|
+
var cleanUpName = (name) => {
|
|
14
|
+
const [last, first] = name.trim().split(",");
|
|
15
|
+
let finalName = `${first.trim()} ${last.trim()}`.replace(/'/g, "");
|
|
16
|
+
if (finalName.startsWith(".")) {
|
|
17
|
+
finalName = finalName.slice(1).trim();
|
|
18
|
+
}
|
|
19
|
+
return finalName.trim();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/Students.ts
|
|
23
|
+
var Students = class {
|
|
24
|
+
students;
|
|
25
|
+
timeTableKeys = {};
|
|
26
|
+
constructor(inputOptions) {
|
|
27
|
+
const { timeTable, givenInput, pathToFile, winstonLogger: logger } = inputOptions;
|
|
28
|
+
this.timeTableKeys = timeTable?.reduce((acc, curr) => {
|
|
29
|
+
acc[curr.expandedClassCode] = curr.classCode;
|
|
30
|
+
return acc;
|
|
31
|
+
}, {}) ?? {};
|
|
32
|
+
const input = givenInput ?? readFileFrom(pathToFile, "utf-8");
|
|
33
|
+
const lines = input.split("\n").slice(1).filter((x) => x.length !== 0);
|
|
34
|
+
const students = lines.map((line) => {
|
|
35
|
+
const [zID, name, classCode] = line.split("|");
|
|
36
|
+
const alternativeClass = timeTable?.find((x) => x.otherExpandedClassCode === classCode);
|
|
37
|
+
return {
|
|
38
|
+
zID: `z${zID.trim()}`,
|
|
39
|
+
name: cleanUpName(name),
|
|
40
|
+
class: alternativeClass?.otherExpandedClassCode?.trim() ?? classCode?.trim() ?? "N/A",
|
|
41
|
+
classCode: alternativeClass?.classCode?.trim() ?? (classCode !== void 0 ? this.timeTableKeys[classCode.trim()] ?? "N/A" : "N/A")
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
logger?.verbose(`Read ${students.length} students`);
|
|
45
|
+
this.students = students.sort((a, b) => a.zID.localeCompare(b.zID));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the students as an array
|
|
49
|
+
*/
|
|
50
|
+
getStudents = () => [...this.students];
|
|
51
|
+
getTimeTableKeys = () => ({ ...this.timeTableKeys });
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
exports.Students = Students;
|
|
55
|
+
exports.cleanUpName = cleanUpName;
|
|
56
|
+
//# sourceMappingURL=index.cjs.map
|
|
57
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/Students.ts"],"names":["existsSync","readFileSync"],"mappings":";;;;;;AAQO,IAAM,YAAA,GAAe,CAAC,IAAA,EAAc,QAAA,GAA2B,OAAA,KAAoB;AACxF,EAAA,IAAIA,aAAA,CAAW,IAAI,CAAA,EAAG;AACpB,IAAA,OAAOC,eAAA,CAAa,MAAM,QAAQ,CAAA;AAAA,EACpC;AACA,EAAA,MAAM,IAAI,KAAA,CAAM,CAAA,6CAAA,EAAgD,IAAI,CAAA,CAAE,CAAA;AACxE,CAAA;AAMO,IAAM,WAAA,GAAc,CAAC,IAAA,KAA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EAAM,SAAS,CAAA,GAAI,IAAA,CAAK,MAAM,GAAG,CAAA;AAK7C,MAAA,MAAM,mBAAmB,SAAA,EAAW,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,2BAA2B,SAAS,CAAA;AAEtF,MAAA,OAAO;AAAA,QACL,GAAA,EAAK,CAAA,CAAA,EAAI,GAAA,CAAI,IAAA,EAAM,CAAA,CAAA;AAAA,QACnB,IAAA,EAAM,YAAY,IAAI,CAAA;AAAA,QACtB,OAAO,gBAAA,EAAkB,sBAAA,EAAwB,MAAK,IAAK,SAAA,EAAW,MAAK,IAAK,KAAA;AAAA,QAChF,SAAA,EACE,gBAAA,EAAkB,SAAA,EAAW,IAAA,EAAK,KACjC,SAAA,KAAc,MAAA,GAAa,IAAA,CAAK,aAAA,CAAc,SAAA,CAAU,IAAA,EAAM,KAAK,KAAA,GAAS,KAAA;AAAA,OACjF;AAAA,IACF,CAAC,CAAA;AACD,IAAA,MAAA,EAAQ,OAAA,CAAQ,CAAA,KAAA,EAAQ,QAAA,CAAS,MAAM,CAAA,SAAA,CAAW,CAAA;AAClD,IAAA,IAAA,CAAK,QAAA,GAAW,QAAA,CAAS,IAAA,CAAK,CAAC,CAAA,EAAG,CAAA,KAAM,CAAA,CAAE,GAAA,CAAI,aAAA,CAAc,CAAA,CAAE,GAAG,CAAC,CAAA;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA,EAKO,WAAA,GAAc,MAAM,CAAC,GAAG,KAAK,QAAQ,CAAA;AAAA,EACrC,gBAAA,GAAmB,OAAO,EAAE,GAAG,KAAK,aAAA,EAAc,CAAA;AAC3D","file":"index.cjs","sourcesContent":["import { existsSync, readFileSync } from 'fs';\n\n/**\n * Reads input from a file and returns a string\n * @throws { Error } if the file does not exist\n * @param path path of file\n * @param encoding encoding, defaulted to \"utf-8\"\n */\nexport const readFileFrom = (path: string, encoding: BufferEncoding = 'utf-8'): string => {\n if (existsSync(path)) {\n return readFileSync(path, encoding);\n }\n throw new Error(`Failed to read file from expected directory: ${path}`);\n};\n\n/**\n * Cleans up the name by removing leading/trailing spaces and removing any leading periods\n * @param name in the format \"Last, First\"\n */\nexport const cleanUpName = (name: string): string => {\n const [last, first] = name.trim().split(',') as [string, string];\n let finalName = `${first.trim()} ${last.trim()}`.replace(/'/g, '');\n if (finalName.startsWith('.')) {\n finalName = finalName.slice(1).trim();\n }\n return finalName.trim();\n};\n","import { type Logger } from 'winston';\nimport type { StudentEnrolment, TimetableInformation } from './types';\nimport { cleanUpName, readFileFrom } from './utils';\n\ntype InputOptions = {\n timeTable?: TimetableInformation;\n winstonLogger?: Logger;\n} & ({ givenInput: string; pathToFile?: never } | { pathToFile: string; givenInput?: never });\n\nexport class Students {\n private readonly students: StudentEnrolment[];\n private readonly timeTableKeys: { [key: string]: string | undefined } = {};\n\n public constructor(inputOptions: InputOptions) {\n const { timeTable, givenInput, pathToFile, winstonLogger: logger } = inputOptions;\n\n this.timeTableKeys =\n timeTable?.reduce((acc: typeof this.timeTableKeys, curr) => {\n acc[curr.expandedClassCode] = curr.classCode;\n return acc;\n }, {}) ?? {};\n\n const input = givenInput ?? readFileFrom(pathToFile, 'utf-8');\n const lines = input\n .split('\\n')\n .slice(1)\n .filter((x) => x.length !== 0);\n const students: StudentEnrolment[] = lines.map((line) => {\n const [zID, name, classCode] = line.split('|') as [string, string, string | undefined];\n\n /**\n * This is in case teaching decides to combine classes but not update the fucking enrolments\n */\n const alternativeClass = timeTable?.find((x) => x.otherExpandedClassCode === classCode);\n\n return {\n zID: `z${zID.trim()}`,\n name: cleanUpName(name),\n class: alternativeClass?.otherExpandedClassCode?.trim() ?? classCode?.trim() ?? 'N/A',\n classCode:\n alternativeClass?.classCode?.trim() ??\n (classCode !== undefined ? (this.timeTableKeys[classCode.trim()] ?? 'N/A') : 'N/A'),\n };\n });\n logger?.verbose(`Read ${students.length} students`);\n this.students = students.sort((a, b) => a.zID.localeCompare(b.zID));\n }\n\n /**\n * Get the students as an array\n */\n public getStudents = () => [...this.students];\n public getTimeTableKeys = () => ({ ...this.timeTableKeys });\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Logger } from 'winston';
|
|
2
|
+
|
|
3
|
+
type StudentEnrolment = {
|
|
4
|
+
zID: string;
|
|
5
|
+
name: string;
|
|
6
|
+
class: string;
|
|
7
|
+
classCode?: string;
|
|
8
|
+
};
|
|
9
|
+
type TimetableInformation = Array<{
|
|
10
|
+
classCode: string;
|
|
11
|
+
expandedClassCode: string;
|
|
12
|
+
/**
|
|
13
|
+
* This is in case teaching decides to combine classes but not update the fucking enrolments
|
|
14
|
+
*/
|
|
15
|
+
otherExpandedClassCode?: string;
|
|
16
|
+
tuteLabLocation: [
|
|
17
|
+
tuteWeeks: string,
|
|
18
|
+
tuteTime: string,
|
|
19
|
+
tuteLocation: string,
|
|
20
|
+
labWeeks: string,
|
|
21
|
+
labTime: string,
|
|
22
|
+
labLocation: string
|
|
23
|
+
];
|
|
24
|
+
tutors: Array<{
|
|
25
|
+
zID: string;
|
|
26
|
+
name: string;
|
|
27
|
+
}>;
|
|
28
|
+
}>;
|
|
29
|
+
|
|
30
|
+
type InputOptions = {
|
|
31
|
+
timeTable?: TimetableInformation;
|
|
32
|
+
winstonLogger?: Logger;
|
|
33
|
+
} & ({
|
|
34
|
+
givenInput: string;
|
|
35
|
+
pathToFile?: never;
|
|
36
|
+
} | {
|
|
37
|
+
pathToFile: string;
|
|
38
|
+
givenInput?: never;
|
|
39
|
+
});
|
|
40
|
+
declare class Students {
|
|
41
|
+
private readonly students;
|
|
42
|
+
private readonly timeTableKeys;
|
|
43
|
+
constructor(inputOptions: InputOptions);
|
|
44
|
+
/**
|
|
45
|
+
* Get the students as an array
|
|
46
|
+
*/
|
|
47
|
+
getStudents: () => StudentEnrolment[];
|
|
48
|
+
getTimeTableKeys: () => {
|
|
49
|
+
[key: string]: string | undefined;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Cleans up the name by removing leading/trailing spaces and removing any leading periods
|
|
55
|
+
* @param name in the format "Last, First"
|
|
56
|
+
*/
|
|
57
|
+
declare const cleanUpName: (name: string) => string;
|
|
58
|
+
|
|
59
|
+
export { type StudentEnrolment, Students, type TimetableInformation, cleanUpName };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Logger } from 'winston';
|
|
2
|
+
|
|
3
|
+
type StudentEnrolment = {
|
|
4
|
+
zID: string;
|
|
5
|
+
name: string;
|
|
6
|
+
class: string;
|
|
7
|
+
classCode?: string;
|
|
8
|
+
};
|
|
9
|
+
type TimetableInformation = Array<{
|
|
10
|
+
classCode: string;
|
|
11
|
+
expandedClassCode: string;
|
|
12
|
+
/**
|
|
13
|
+
* This is in case teaching decides to combine classes but not update the fucking enrolments
|
|
14
|
+
*/
|
|
15
|
+
otherExpandedClassCode?: string;
|
|
16
|
+
tuteLabLocation: [
|
|
17
|
+
tuteWeeks: string,
|
|
18
|
+
tuteTime: string,
|
|
19
|
+
tuteLocation: string,
|
|
20
|
+
labWeeks: string,
|
|
21
|
+
labTime: string,
|
|
22
|
+
labLocation: string
|
|
23
|
+
];
|
|
24
|
+
tutors: Array<{
|
|
25
|
+
zID: string;
|
|
26
|
+
name: string;
|
|
27
|
+
}>;
|
|
28
|
+
}>;
|
|
29
|
+
|
|
30
|
+
type InputOptions = {
|
|
31
|
+
timeTable?: TimetableInformation;
|
|
32
|
+
winstonLogger?: Logger;
|
|
33
|
+
} & ({
|
|
34
|
+
givenInput: string;
|
|
35
|
+
pathToFile?: never;
|
|
36
|
+
} | {
|
|
37
|
+
pathToFile: string;
|
|
38
|
+
givenInput?: never;
|
|
39
|
+
});
|
|
40
|
+
declare class Students {
|
|
41
|
+
private readonly students;
|
|
42
|
+
private readonly timeTableKeys;
|
|
43
|
+
constructor(inputOptions: InputOptions);
|
|
44
|
+
/**
|
|
45
|
+
* Get the students as an array
|
|
46
|
+
*/
|
|
47
|
+
getStudents: () => StudentEnrolment[];
|
|
48
|
+
getTimeTableKeys: () => {
|
|
49
|
+
[key: string]: string | undefined;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Cleans up the name by removing leading/trailing spaces and removing any leading periods
|
|
55
|
+
* @param name in the format "Last, First"
|
|
56
|
+
*/
|
|
57
|
+
declare const cleanUpName: (name: string) => string;
|
|
58
|
+
|
|
59
|
+
export { type StudentEnrolment, Students, type TimetableInformation, cleanUpName };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import 'winston';
|
|
2
|
+
import { existsSync, readFileSync } from 'fs';
|
|
3
|
+
|
|
4
|
+
// src/Students.ts
|
|
5
|
+
var readFileFrom = (path, encoding = "utf-8") => {
|
|
6
|
+
if (existsSync(path)) {
|
|
7
|
+
return readFileSync(path, encoding);
|
|
8
|
+
}
|
|
9
|
+
throw new Error(`Failed to read file from expected directory: ${path}`);
|
|
10
|
+
};
|
|
11
|
+
var cleanUpName = (name) => {
|
|
12
|
+
const [last, first] = name.trim().split(",");
|
|
13
|
+
let finalName = `${first.trim()} ${last.trim()}`.replace(/'/g, "");
|
|
14
|
+
if (finalName.startsWith(".")) {
|
|
15
|
+
finalName = finalName.slice(1).trim();
|
|
16
|
+
}
|
|
17
|
+
return finalName.trim();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/Students.ts
|
|
21
|
+
var Students = class {
|
|
22
|
+
students;
|
|
23
|
+
timeTableKeys = {};
|
|
24
|
+
constructor(inputOptions) {
|
|
25
|
+
const { timeTable, givenInput, pathToFile, winstonLogger: logger } = inputOptions;
|
|
26
|
+
this.timeTableKeys = timeTable?.reduce((acc, curr) => {
|
|
27
|
+
acc[curr.expandedClassCode] = curr.classCode;
|
|
28
|
+
return acc;
|
|
29
|
+
}, {}) ?? {};
|
|
30
|
+
const input = givenInput ?? readFileFrom(pathToFile, "utf-8");
|
|
31
|
+
const lines = input.split("\n").slice(1).filter((x) => x.length !== 0);
|
|
32
|
+
const students = lines.map((line) => {
|
|
33
|
+
const [zID, name, classCode] = line.split("|");
|
|
34
|
+
const alternativeClass = timeTable?.find((x) => x.otherExpandedClassCode === classCode);
|
|
35
|
+
return {
|
|
36
|
+
zID: `z${zID.trim()}`,
|
|
37
|
+
name: cleanUpName(name),
|
|
38
|
+
class: alternativeClass?.otherExpandedClassCode?.trim() ?? classCode?.trim() ?? "N/A",
|
|
39
|
+
classCode: alternativeClass?.classCode?.trim() ?? (classCode !== void 0 ? this.timeTableKeys[classCode.trim()] ?? "N/A" : "N/A")
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
logger?.verbose(`Read ${students.length} students`);
|
|
43
|
+
this.students = students.sort((a, b) => a.zID.localeCompare(b.zID));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get the students as an array
|
|
47
|
+
*/
|
|
48
|
+
getStudents = () => [...this.students];
|
|
49
|
+
getTimeTableKeys = () => ({ ...this.timeTableKeys });
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { Students, cleanUpName };
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/Students.ts"],"names":[],"mappings":";;;;AAQO,IAAM,YAAA,GAAe,CAAC,IAAA,EAAc,QAAA,GAA2B,OAAA,KAAoB;AACxF,EAAA,IAAI,UAAA,CAAW,IAAI,CAAA,EAAG;AACpB,IAAA,OAAO,YAAA,CAAa,MAAM,QAAQ,CAAA;AAAA,EACpC;AACA,EAAA,MAAM,IAAI,KAAA,CAAM,CAAA,6CAAA,EAAgD,IAAI,CAAA,CAAE,CAAA;AACxE,CAAA;AAMO,IAAM,WAAA,GAAc,CAAC,IAAA,KAAyB;AACnD,EAAA,MAAM,CAAC,MAAM,KAAK,CAAA,GAAI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AA;AAK7C,MAAA,MAAM,mBAAmB,SAAA,EAAW,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,2BAA2B,SAAS,CAAA;AAEtF,MAAA,OAAO;AAAA,QACL,GAAA,EAAK,CAAA,CAAA,EAAI,GAAA,CAAI,IAAA,EAAM,CAAA,CAAA;AAAA,QACnB,IAAA,EAAM,YAAY,IAAI,CAAA;AAAA,QACtB,OAAO,gBAAA,EAAkB,sBAAA,EAAwB,MAAK,IAAK,SAAA,EAAW,MAAK,IAAK,KAAA;AAAA,QAChF,SAAA,EACE,gBAAA,EAAkB,SAAA,EAAW,IAAA,EAAK,KACjC,SAAA,KAAc,MAAA,GAAa,IAAA,CAAK,aAAA,CAAc,SAAA,CAAU,IAAA,EAAM,KAAK,KAAA,GAAS,KAAA;AAAA,OACjF;AAAA,IACF,CAAC,CAAA;AACD,IAAA,MAAA,EAAQ,OAAA,CAAQ,CAAA,KAAA,EAAQ,QAAA,CAAS,MAAM,CAAA,SAAA,CAAW,CAAA;AAClD,IAAA,IAAA,CAAK,QAAA,GAAW,QAAA,CAAS,IAAA,CAAK,CAAC,CAAA,EAAG,CAAA,KAAM,CAAA,CAAE,GAAA,CAAI,aAAA,CAAc,CAAA,CAAE,GAAG,CAAC,CAAA;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA,EAKO,WAAA,GAAc,MAAM,CAAC,GAAG,KAAK,QAAQ,CAAA;AAAA,EACrC,gBAAA,GAAmB,OAAO,EAAE,GAAG,KAAK,aAAA,EAAc,CAAA;AAC3D","file":"index.js","sourcesContent":["import { existsSync, readFileSync } from 'fs';\n\n/**\n * Reads input from a file and returns a string\n * @throws { Error } if the file does not exist\n * @param path path of file\n * @param encoding encoding, defaulted to \"utf-8\"\n */\nexport const readFileFrom = (path: string, encoding: BufferEncoding = 'utf-8'): string => {\n if (existsSync(path)) {\n return readFileSync(path, encoding);\n }\n throw new Error(`Failed to read file from expected directory: ${path}`);\n};\n\n/**\n * Cleans up the name by removing leading/trailing spaces and removing any leading periods\n * @param name in the format \"Last, First\"\n */\nexport const cleanUpName = (name: string): string => {\n const [last, first] = name.trim().split(',') as [string, string];\n let finalName = `${first.trim()} ${last.trim()}`.replace(/'/g, '');\n if (finalName.startsWith('.')) {\n finalName = finalName.slice(1).trim();\n }\n return finalName.trim();\n};\n","import { type Logger } from 'winston';\nimport type { StudentEnrolment, TimetableInformation } from './types';\nimport { cleanUpName, readFileFrom } from './utils';\n\ntype InputOptions = {\n timeTable?: TimetableInformation;\n winstonLogger?: Logger;\n} & ({ givenInput: string; pathToFile?: never } | { pathToFile: string; givenInput?: never });\n\nexport class Students {\n private readonly students: StudentEnrolment[];\n private readonly timeTableKeys: { [key: string]: string | undefined } = {};\n\n public constructor(inputOptions: InputOptions) {\n const { timeTable, givenInput, pathToFile, winstonLogger: logger } = inputOptions;\n\n this.timeTableKeys =\n timeTable?.reduce((acc: typeof this.timeTableKeys, curr) => {\n acc[curr.expandedClassCode] = curr.classCode;\n return acc;\n }, {}) ?? {};\n\n const input = givenInput ?? readFileFrom(pathToFile, 'utf-8');\n const lines = input\n .split('\\n')\n .slice(1)\n .filter((x) => x.length !== 0);\n const students: StudentEnrolment[] = lines.map((line) => {\n const [zID, name, classCode] = line.split('|') as [string, string, string | undefined];\n\n /**\n * This is in case teaching decides to combine classes but not update the fucking enrolments\n */\n const alternativeClass = timeTable?.find((x) => x.otherExpandedClassCode === classCode);\n\n return {\n zID: `z${zID.trim()}`,\n name: cleanUpName(name),\n class: alternativeClass?.otherExpandedClassCode?.trim() ?? classCode?.trim() ?? 'N/A',\n classCode:\n alternativeClass?.classCode?.trim() ??\n (classCode !== undefined ? (this.timeTableKeys[classCode.trim()] ?? 'N/A') : 'N/A'),\n };\n });\n logger?.verbose(`Read ${students.length} students`);\n this.students = students.sort((a, b) => a.zID.localeCompare(b.zID));\n }\n\n /**\n * Get the students as an array\n */\n public getStudents = () => [...this.students];\n public getTimeTableKeys = () => ({ ...this.timeTableKeys });\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kuroson/cse-students",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Student enrolment parser for UNSW CSE courses",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Alvin Cherk <a.cherk@unsw.edu.au>",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.cts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"main": "./dist/index.cjs",
|
|
22
|
+
"module": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"package.json",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"CHANGELOG.md"
|
|
30
|
+
],
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@eslint/js": "9.39.2",
|
|
33
|
+
"@types/jest": "30.0.0",
|
|
34
|
+
"@types/node": "24.10.4",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "8.50.1",
|
|
36
|
+
"depcheck": "1.4.7",
|
|
37
|
+
"eslint": "9.39.2",
|
|
38
|
+
"eslint-config-prettier": "10.1.8",
|
|
39
|
+
"eslint-plugin-jest": "29.10.1",
|
|
40
|
+
"eslint-plugin-prettier": "5.5.4",
|
|
41
|
+
"eslint-plugin-unused-imports": "4.3.0",
|
|
42
|
+
"jest": "30.2.0",
|
|
43
|
+
"prettier": "3.7.4",
|
|
44
|
+
"ts-jest": "29.4.6",
|
|
45
|
+
"tsup": "8.5.1",
|
|
46
|
+
"typescript": "5.9.3",
|
|
47
|
+
"typescript-eslint": "8.50.1",
|
|
48
|
+
"winston": "3.19.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"typescript": ">=5.0.0",
|
|
52
|
+
"winston": ">=3.0.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependenciesMeta": {
|
|
55
|
+
"typescript": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"winston": {
|
|
59
|
+
"optional": true
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=22"
|
|
64
|
+
},
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public"
|
|
67
|
+
},
|
|
68
|
+
"depcheck": {
|
|
69
|
+
"ignores": [],
|
|
70
|
+
"skip-missing": true
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build:all": "tsup",
|
|
74
|
+
"depcheck": "depcheck",
|
|
75
|
+
"lint": "eslint './**/*.{ts,js}'",
|
|
76
|
+
"lint:fix": "eslint './**/*.{ts,js}' --fix",
|
|
77
|
+
"test": "jest",
|
|
78
|
+
"test:cov": "jest --coverage",
|
|
79
|
+
"typecheck": "tsc --noEmit"
|
|
80
|
+
}
|
|
81
|
+
}
|