-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.js
More file actions
42 lines (37 loc) · 1.16 KB
/
helper.js
File metadata and controls
42 lines (37 loc) · 1.16 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import hyphenopoly from "hyphenopoly";
import fs from "fs";
import { fileURLToPath } from "url";
import { dirname } from "path";
const hyphenator = hyphenopoly.config({
"require": ["de", "en-us"],
"hyphen": "•",
"loaderSync": file => {
const cwd = dirname(fileURLToPath(import.meta.url));
return fs.readFileSync(`${cwd}/node_modules/hyphenopoly/patterns/${file}`);
},
"sync": true
}).get("de");
export const hyphenate = (str, token) => hyphenator(str).replace(/•/g, token);
export const periods = fs.readFileSync("period_list.txt", "utf-8").replace(/\r/g, "").split("\n").map(e => ({
period: parseInt(e.split("|")[0]),
startTime: parseInt(e.split("|")[1]),
lowestClass: parseInt(e.split("|")[2])
}));
export function getPeriod(time) {
let currPeriod;
for (let period of periods) {
if (time >= period.startTime) {
currPeriod = period.period;
break;
}
}
return currPeriod;
}
export function getPeriodFromClass(classID) {
for (let period of periods) {
if (parseInt(classID) >= period.lowestClass) {
return period;
}
}
return periods[0];
}