File size: 997 Bytes
c4be319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function formatTitle(title) {
    if (!title) return 'Unknown Assignment';
    // Remove newline characters and invisible spaces common in scraped text
    title = title.replace(/[\r\n\t]+/g, ' ').trim();
    if (title.startsWith('"') && title.endsWith('"')) {
        title = title.substring(1, title.length - 1);
    }
    title = title.replace(/\s*is due$/i, '');
    return title.trim();
}

function formatCourse(courseStr) {
    if (!courseStr) return 'Unknown Course';
    // Moodle course strings often come with the title injected first due to HTML structure
    const lines = courseStr.split('\n').map(l => l.replace(/[\r\n\t]+/g, ' ').trim()).filter(l => l.length > 0);
    
    let courseLine = lines.length >= 2 ? lines[1] : lines[0];
    
    if (courseLine.startsWith('"') && courseLine.endsWith('"')) {
        courseLine = courseLine.substring(1, courseLine.length - 1);
    }
    return courseLine.trim();
}

module.exports = { formatTitle, formatCourse };