node-event-bot/server/helper/typeFind.ts
mightypanders 180c467826
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
refactoring and adding capability to recognize more schedules
2022-04-13 21:38:59 +02:00

14 lines
531 B
TypeScript

import { scheduleNames, supportedSchedule } from "../types/scheduledEventTypes";
export function findInScheduleTypes(inputString: string): supportedSchedule {
const maybeScheduleName: unknown = JSON.parse(`"${inputString.toLowerCase()}"`);
const scheduleName = scheduleNames.find((validName: supportedSchedule) => validName === maybeScheduleName);
if (scheduleName) {
// `sheepName` comes from the list of `sheepNames` so the compiler is happy.
return scheduleName;
}
throw new Error('That is not a schedule name.');
}