31// // Write Data
32// // ---------
33// function addTodo(text) {
34// db.transact([tx.messages[id()].update({ text: 'what' })]);
35// // db.transact(
42// }
43
44// function deleteTodoItem(message) {
45// db.transact(tx.messages[message.id].delete());
46// }
47
48// function toggleDone(message) {
49// db.transact(tx.messages[message.id].update({ done: !message.done }));
50// }
51
52// function deleteCompleted(messages) {
53// const completed = messages.filter((message) => message.done);
54// const txs = completed.map((message) => tx.messages[message.id].delete());
56// }
57
58// function toggleAllTodos(messages) {
59// const newVal = !messages.every((message) => message.done);
60// db.transact(messages.map((message) => tx.messages[message.id].update({ done: newVal })));
62
63
64// function query(q = { messages: {} }) {
65// const { isLoading, error, data } = db.subscribeQuery({ messages: {} });
66// console.log('data', data);
68
69
70// function renderError(error) {
71// console.error(error);
72// }
73
74// function render(data) {
75// console.log(data);
76// }
21}
22
23function App() {
24 const [templates, setTemplates] = useState<MemeTemplate[]>([]);
25 const [selectedTemplate, setSelectedTemplate] = useState<string>("");
94 const [topPosition, bottomPosition] = getTextPositions(image.width, image.height, selectedTemplate);
95
96 // Function to draw text with word wrap
97 const drawText = (text: string, position: TextPosition) => {
98 ctx.fillStyle = position.color;
172}
173
174function client() {
175 createRoot(document.getElementById("root")).render(<App />);
176}
178if (typeof document !== "undefined") { client(); }
179
180async function server(request: Request): Promise<Response> {
181 const url = new URL(request.url);
182
3import { newRSSItems } from "https://esm.town/v/stevekrouse/newRSSItems";
4
5export async function pollRSSFeeds({ lastRunAt }: Interval) {
6 return Promise.all(
7 Object.entries(rssFeeds).map(async ([name, url]) => {
2import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI?v=5";
3
4export async function aqi(interval: Interval) {
5 const location = "Camden, London"; // <-- change to place, city, or zip code
6 const data = await easyAQI({ location });
2import { renderToString } from "npm:react-dom/server";
3
4export default async function(req: Request) {
5 return new Response(
6 renderToString(
17import jsQR from "https://esm.sh/jsqr";
18
19function App() {
20 const videoRef = useRef<HTMLVideoElement>(null);
21 const canvasRef = useRef<HTMLCanvasElement>(null);
133}
134
135function client() {
136 createRoot(document.getElementById("root")!).render(<App />);
137}
141}
142
143async function server(request: Request): Promise<Response> {
144 return new Response(`
145 <!DOCTYPE html>
3import { email } from "https://esm.town/v/std/email";
4
5export default async function(interval: Interval) {
6 let weather = await getWeather("Brooklyn, NY");
7 let feelsLike = weather.current_condition[0].FeelsLikeF;
12export type Handler = (req: Request) => Response | Promise<Response>;
13
14export function pwa(handler: Handler, manifest: Partial<ManifestOptions>): Handler {
15 return async (req: Request) => {
16 const url = new URL(req.url);
16];
17
18// Function to fetch recent questions from Stack Overflow for multiple topics
19async function fetchRecentQuestions(): Promise<StackExchange.Question[]> {
20 const allQuestions: StackExchange.Question[] = [];
21
34}
35
36// Function to format questions into HTML
37function formatQuestionsHtml(questions: StackExchange.Question[]): string {
38 return questions.map(q => `
39 <h2><a href="${q.link}">${q.title}</a></h2>
44}
45
46// Main cron job function
47async function cronJob() {
48 const { email } = await import("https://esm.town/v/std/email");
49
69}
70
71export default async function(interval: Interval) {
72 await cronJob();
73}
49### Linking to the val
50
51These functions infer the val using the call stack or the request URL. If the inference isn't working, or if you want to ensure it links to a specific val, pass the `val` argument:
52
53- `modifyFetchHandler(handler, {val: { handle: "andre", name: "foo" }})`
A helper function to build a file's email
Simple functional CSS library for Val Town
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.