Skip to content

Commit

Permalink
more validation
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunpat committed May 8, 2022
1 parent a6f0a8c commit db784e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
14 changes: 6 additions & 8 deletions Validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,19 @@ class Validator {
this.schoolError(`"${each}" is not a valid event name. It includes invalid characters`);
}

const nameRegEx = /^[a-zA-Z-/0-9\(\) ]+$/;
for (let key in school) {
obj.presets[key] = {
n: (() => {
if (typeof school[key].name !== 'string') {
if (typeof school[key].name !== 'string' || !nameRegEx.test(school[key].name)) {
this.schoolError(`Preset "${key}" does not have a valid name: a valid name must be a string`);
}
return school[key].name;
})(),
s: (() => {
if (!school[key].schedule) {
if (typeof school[key].schedule === 'undefined') {
this.schoolError(`Preset "${key}" does not have a schedule; please add a schedule field.`)
} else if (!school[key].schedule) {
return [];
} else if (school[key].schedule instanceof Array) {
this.checkScheduleArray(school[key].schedule, key, validEvents);
Expand All @@ -128,12 +131,7 @@ class Validator {
}

parseScheduleArray(arr) {
let data = [];

for (let str of arr)
data.push(this.getEvent(str));

return data;
return arr.map(this.getEvent);
}

checkScheduleArray(scheduleArr, presetName, validEvents) {
Expand Down
1 change: 1 addition & 0 deletions data/mvhs/school.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ finals-june-2022-tues:

finals-june-2022-wed:
name: Wednesday Finals
schedule:
- 8:40 Period 6
- 10:25 Free

Expand Down

0 comments on commit db784e2

Please sign in to comment.