18const ValTownOfficeDeviceId = "CD6F3A810848";
1920async function switchbotRequest(path, args) {
21const token = Deno.env.get("SWITCHBOT_TOKEN");
22const secret = Deno.env.get("SWITCHBOT_KEY");
42}
4344function botPress(device) {
45return switchbotRequest(`v1.1/devices/${device}/commands`, {
46method: "POST",
18const ValTownOfficeDeviceId = "CD6F3A810848";
1920async function switchbotRequest(path, args) {
21const token = Deno.env.get("SWITCHBOT_TOKEN");
22const secret = Deno.env.get("SWITCHBOT_KEY");
42}
4344function botPress(device) {
45return switchbotRequest(`v1.1/devices/${device}/commands`, {
46method: "POST",
whenfilmedmain.tsx7 matches
13}
1415async function fetchRandomMovies() {
16const currentYear = new Date().getFullYear()
17const movies = []
35}
3637function generateQuizHTML(movies, uuid) {
38const currentYear = new Date().getFullYear()
39return `
52</style>
53<script>
54function updateInputs(index, value) {
55document.getElementById('guess' + index).value = value;
56document.getElementById('guessInput' + index).value = value;
91}
9293function calculateScore(movies, guesses) {
94return movies.reduce((score, movie, index) => {
95const actualYear = new Date(movie.release_date).getFullYear()
102}
103104function generateResultsHTML(movies, guesses, score) {
105return `
106<html>
152}
153154function generateAllGuessesHTML(allGuesses) {
155return `
156<html>
198}
199200export default async function main(req: Request): Promise<Response> {
201const { author, name } = extractValInfo(import.meta.url)
202const guessesKey = `${author}.${name}.guesses`
hardwarebingomain.tsx1 match
97if (typeof document !== "undefined") { createRoot(document.getElementById("root")).render(<App />); }
9899export default async function(req: Request): Promise<Response> {
100return new Response(
101renderToString(
12* The email address(es) to send the email to. Only available to Val Town Pro subscribers.
13* Can be a single string, IAddress object, or an array of strings/IAddress objects.
14* @default the email of the logged user calling this function.
15*/
16to?: (IAddress | string)[] | IAddress | string;
azureCheetahmain.tsx14 matches
16import { renderToString } from "npm:react-dom/server";
1718export default function(
19{ tempValsParentFolderId }: { tempValsParentFolderId: string },
20) {
38the simplest way to achieve the goal, though you can add some inline comments to explain your
39reasoning (not for every line, but for major groups of lines). Don't use any environment variables
40unless strictly necessary, for example use APIs that don't require a key, prefer internal function
41imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno
42functions where possible. Unless specified, don't add error handling,
43make sure that errors bubble up to the caller.
44Avoid external images or base64 images, use emojis, unicode symtols, or icon fonts/libraries instead, unless that's
51\`\`\`
52There should be no comments like "more content here", it should be complete and directly runnable.
53The val should create a "export default async function main" which is the main function that gets
54executed on every HTTP request.
55`.replace("\n", " ");
5657// Your response should start with \`\`\`ts and end with \`\`\`.
58// The val should create a "export default async function main() {" which
59// is the main function that gets executed, without any arguments. Don't return a Response object,
60// just return a plain Javascript object, array, or string.
6198const writer = writable.getWriter();
99const textEncoder = new TextEncoder();
100function write(text) {
101writer.write(textEncoder.encode(text));
102}
174</div>
175<script>
176function updateValName(valName) {
177const valUrl = valName ? \`https://val.town/v/${username}/\${valName}\` : "";
178const previewUrl = valName ? \`https://${username}-\${valName}.web.val.run\` : "";
182document.getElementById('open-link').href = previewUrl;
183}
184function saveVal() {
185if (window.codeMirrorEditor) {
186document.getElementById("save-icon").classList.remove("hidden");
202return false;
203})
204function openTab(tab) {
205const tabButtonCode = document.getElementById("tab-button-code");
206const tabButtonPreview = document.getElementById("tab-button-preview");
222}
223}
224function toggleTab() {
225openTab(document.getElementById("tab-panel-code").style.visibility === "visible" ? "preview" : "code");
226}
281(() => {
282const scrollingElement = document.getElementById("conversation-container");
283const callback = function (mutationsList, observer) {
284scrollingElement.scrollTo({ left: 0, top: scrollingElement.scrollHeight, behavior: "instant" });
285};
390window.setCodeMirrorContent({ doc: '', old: ''});
391let fullStr = "";
392window.addToken = function(str) {
393fullStr += str;
394const code = fullStr.replaceAll("\`\`\`ts\\n", "").replaceAll("\`\`\`", "").replace(/^ts\\n/, '');
429},
430);
431(async function() {
432try {
433await sleep(300);
16import { renderToString } from "npm:react-dom/server";
1718export default function(
19{ tempValsParentFolderId }: { tempValsParentFolderId: string },
20) {
38the simplest way to achieve the goal, though you can add some inline comments to explain your
39reasoning (not for every line, but for major groups of lines). Don't use any environment variables
40unless strictly necessary, for example use APIs that don't require a key, prefer internal function
41imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno
42functions where possible. Unless specified, don't add error handling,
43make sure that errors bubble up to the caller.
44Avoid external images or base64 images, use emojis, unicode symtols, or icon fonts/libraries instead, unless that's
51\`\`\`
52There should be no comments like "more content here", it should be complete and directly runnable.
53The val should create a "export default async function main" which is the main function that gets
54executed on every HTTP request.
55`.replace("\n", " ");
5657// Your response should start with \`\`\`ts and end with \`\`\`.
58// The val should create a "export default async function main() {" which
59// is the main function that gets executed, without any arguments. Don't return a Response object,
60// just return a plain Javascript object, array, or string.
6198const writer = writable.getWriter();
99const textEncoder = new TextEncoder();
100function write(text) {
101writer.write(textEncoder.encode(text));
102}
174</div>
175<script>
176function updateValName(valName) {
177const valUrl = valName ? \`https://val.town/v/${username}/\${valName}\` : "";
178const previewUrl = valName ? \`https://${username}-\${valName}.web.val.run\` : "";
182document.getElementById('open-link').href = previewUrl;
183}
184function saveVal() {
185if (window.codeMirrorEditor) {
186document.getElementById("save-icon").classList.remove("hidden");
202return false;
203})
204function openTab(tab) {
205const tabButtonCode = document.getElementById("tab-button-code");
206const tabButtonPreview = document.getElementById("tab-button-preview");
222}
223}
224function toggleTab() {
225openTab(document.getElementById("tab-panel-code").style.visibility === "visible" ? "preview" : "code");
226}
281(() => {
282const scrollingElement = document.getElementById("conversation-container");
283const callback = function (mutationsList, observer) {
284scrollingElement.scrollTo({ left: 0, top: scrollingElement.scrollHeight, behavior: "instant" });
285};
390window.setCodeMirrorContent({ doc: '', old: ''});
391let fullStr = "";
392window.addToken = function(str) {
393fullStr += str;
394const code = fullStr.replaceAll("\`\`\`ts\\n", "").replaceAll("\`\`\`", "").replace(/^ts\\n/, '');
429},
430);
431(async function() {
432try {
433await sleep(300);
ReactStream_migratedREADME.md4 matches
7import { render, React } from "https://esm.town/v/jxnblk/ReactStream";
89function App() {
10const [count, setCount] = React.useState(0);
11return (
62```tsx
63// example middleware
64async function api (req: Request, res: Response, next): Promise<Response> {
65if (req.pathname !== "/api") return next();
66if (req.method === "POST") {
78```tsx
79// example middleware
80async function getInitialProps (req: Request, res: Response, next) {
81// fetch data or do async work to pass as props to the component
82req.data = {
95import { render } from "https://esm.town/v/jxnblk/ReactStream";
9697function App () {
98return (
99<html>
valleGetValsContextWindowmain.tsx7 matches
1export default async function getValsContextWindow(model: any) {
2const readmeVals: any = await (await fetch("https://janpaul123-readmevals.web.val.run/")).json();
3183import { render } from "npm:preact-render-to-string";
184
185export default async function(req: Request) {
186return new Response(
187render(
212const FLAT_TEMPLATES = sections.flatMap((section) => section.templates);
213214function tsResponse(code) {
215return "```ts\n" + code + "\n```";
216}
383### Utilities
384
385Our Blob SDK also includes some utility functions to make working with blobs easier.
386
387##### Copy
507role: "assistant",
508content:
509"\n```ts\nexport default async function (req: Request): Promise<Response> {\n return Response.json(\"Hello world\")\n}\n```",
510},
511{
516role: "assistant",
517content:
518"\n```ts\nexport default async function(req: Request): Promise<Response> {\n const query = new URL(req.url).searchParams;\n\n // Read name from the querystring or body. Defaults to \"you\" if not present.\n const name = query.get(\"name\") || (await req.json().catch(() => ({}))).name || \"you\";\n\n // Returns the HTML response\n return new Response(`<h1>Hi ${name}!</h1>`, {\n headers: { \"Content-Type\": \"text/html\" },\n });\n}\n```",
519},
520{
533role: "assistant",
534content:
535"```ts\nexport default async function(req: Request): Promise<Response> {\n const apiKey = Deno.env.get(\"METEO_KEY\");\n const apiUrl = `https://api.open-meteo.com/v1/forecast?latitude=40.6782&longitude=-73.9442&hourly=temperature_2m¤t_weather=true&apikey=${apiKey}`;\n\n const response = await fetch(apiUrl);\n const weatherData = await response.json();\n\n return new Response(JSON.stringify(weatherData), { headers: { \"Content-Type\": \"application/json\" } });\n}\n```",
536},
537{
infiniteSVGGraphmain.tsx6 matches
35// Database querying.
3637function parseResultSet<T>(row: ResultSet): T[] {
38return row.rows.map((r) => Object.fromEntries(r.map((c, i) => [row.columns[i], c]))) as T[];
39}
67};
6869// Client side javascript and template functions.
7071const clientJavascript = async () => {
135});
136137function createHeartBurst(event) {
138const button = event.currentTarget;
139const buttonContainer = button.closest(".heart-button-container");
174};
175176function escapeHTML(html: string): string {
177const escapeChars: { [char: string]: string } = {
178"&": "&",
408let encoder = new TextEncoder();
409410function isValidSVG(svgString) {
411const parser = new DOMParser({
412errorHandler: {
488489app.get("/:id/img.svg", async (c) => {
490function addSVGNamespace(svgString) {
491if (!/^<\?xml/.test(svgString)) svgString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + svgString;
492if (!/xmlns="http:\/\/www.w3.org\/2000\/svg"/.test(svgString))