1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { calendarItemForLine } from "https://esm.town/v/tal/calendarItemForLine";
type Line = Parameters<typeof calendarItemForLine>[1];
type Context = Parameters<typeof calendarItemForLine>[0];
export async function buildDoeMenuCalendar(context: Context, storeValue) {
const ical = await import("npm:ical-generator");
let dailyOfferings: Line | undefined;
let events = [];
const calendar = ical.default({
name: `NYC DoE Lunch Menu ${context.menuType}`,
});
for (let line of storeValue.lines) {
if (line.date.type === "Daily Offerings") {
context.dailyOfferings = line;
}
let eventData = await calendarItemForLine(context, line);
if (eventData) {
events.push(eventData);
calendar.createEvent(eventData);
}
}
return calendar;
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.
Comments
neverstew avatar

Nice! I can really see generating calendars could be a great/easily-wrapped-up use case for vals. events seems to be unecessary - it doesn't go anywhere!

tal avatar

I wouldn't call this a staple of high quality code lol