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/$%7Bart_info.art.src%7D?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 27136 results for "function"(845ms)

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

HTTP99 words

https://docs.val.town/vals/http/
Peko. These handlers need to export a function that takes a Request object as the first parameter and returns a Response object. The function can be asynchronous. Basic examples Routing

Sections

HTTP

Peko. These handlers need to export a function that takes a Request object as the first parameter and returns a Response object. The function can be asynchronous. Basic examples Routing

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

Early Return478 words

https://docs.val.town/vals/http/early-return/
set up a queue” In your early-returning HTTP file: early-returning.tsRun in Val Town ↗ async function handle(request: Request) { // Send off the relevant data a queue HTTP file. //

Sections

How to set up a queue

a queue” In your early-returning HTTP file: early-returning.tsRun in Val Town ↗ async function handle(request: Request) { // Send off the relevant data a queue HTTP file. // This `fetch`

Promises should otherwise be awaited

- besides this narrow use-case, errors that occur in promises won’t be properly handled and functions may run out-of-order. For example, if you use fetch to request some resource, but

Your first scheduled cron628 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

Step 3Run in Val Town ↗ 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

untitled-4618App.tsx1 match

@Mo5•Updated 9 mins ago
4import ChatRoom from './ChatRoom.tsx';
5
6export default function App() {
7 const [activeTab, setActiveTab] = useState<'yoga' | 'chat'>('yoga');
8

untitled-4618ChatRoom.tsx1 match

@Mo5•Updated 9 mins ago
3import type { ChatMessage } from '../../shared/types.ts';
4
5export default function ChatRoom() {
6 const [username, setUsername] = useState('');
7 const [isLoggedIn, setIsLoggedIn] = useState(false);

getFileEmail4 file matches

@shouser•Updated 1 month ago
A helper function to build a file's email
tuna

tuna8 file matches

@jxnblk•Updated 1 month ago
Simple functional CSS library for Val Town
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.