1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { eval_ } from "https://esm.town/v/stevekrouse/eval_";
import { fetchTweet } from "https://esm.town/v/dpetrouk/fetchTweet?v=35";
export let xeval = async (req: Request) => {
let tweet, code, result;
try {
tweet = await fetchTweet(req.url);
code = tweet.text.split("```")[1]
.trim()
.replaceAll(/&lt;/g, "<")
.replaceAll(/&gt;/g, ">")
.replaceAll(/&amp;/g, "&");
result = await eval_(code, [req]);
return result;
}
catch (e) {
return Response.json({ code, tweet, result }, { status: 500 });
}
};
๐Ÿ‘† 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.