Public
Script
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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
type LineType = "header" | "Daily Offerings" | "date";
export async function parseMenuDate(text: string) {
const dateFns = await import("npm:date-fns");
let type: LineType;
let firstBreakAt = text.indexOf("?");
if (firstBreakAt == -1) {
if (text === "Daily Offerings") {
type = "Daily Offerings";
}
else {
type = "header";
}
return { type };
}
let prefix = text.substring(0, firstBreakAt);
let suffix = text.substring(firstBreakAt + 1);
const date = dateFns.parse(prefix, "MMMM d; yyyy", new Date());
type = "date";
return {
type,
date,
prefix,
suffix,
};
}
October 23, 2023