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/%7Bresult.originalUrl%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 40467 results for "function"(768ms)

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.

untitled-8264Main2.ts12 matches

@ziggyware•Updated 19 mins ago
1export default async function (req: Request): Promise<Response> {
2 const fftSize = 2048;
3 const TWO_PI = 2.0 * 3.141592653579;
56 const errorBox = document.getElementById("errorBox");
57
58 function showError(e) {
59 console.error(e);
60 errorBox.style.display = "block";
63
64 // DPR-aware resize
65 function resize() {
66 const dpr = Math.min(window.devicePixelRatio || 1, 2);
67 const w = Math.floor(window.innerWidth * dpr);
178 \`;
179
180 function compileShader(type, src) {
181 const s = gl.createShader(type);
182 gl.shaderSource(s, src);
204 gl.bindVertexArray(vao);
205
206 function createAttrib(data, attribName, usage) {
207 const loc = gl.getAttribLocation(program, attribName);
208 if (loc === -1) throw new Error("Attrib not found or optimized out: " + attribName);
230
231 // Matrices
232 function mat4Perspective(fovDeg, aspect, near, far) {
233 const f = 1.0 / Math.tan((fovDeg * Math.PI) / 360);
234 const nf = 1 / (near - far);
241 return out;
242 }
243 function subtract(a, b) { return [a[0]-b[0], a[1]-b[1], a[2]-b[2]]; }
244 function normalize(v) {
245 const l = Math.hypot(v[0], v[1], v[2]) || 1;
246 return [v[0]/l, v[1]/l, v[2]/l];
247 }
248 function cross(a, b) {
249 return [a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]];
250 }
251 function dot(a, b) { return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; }
252 function mat4LookAt(eye, target, up) {
253 const z = normalize(subtract(eye, target));
254 const x = normalize(cross(up, z));
296
297 // Render loop
298 function render(ts) {
299 // Update audio only if ready
300 if (analyser) {

vtEditorFilesAGENTS.md12 matches

@jrmann100•Updated 1 hour ago
4
5- Ask clarifying questions when requirements are ambiguous
6- Provide complete, functional solutions rather than skeleton implementations
7- Test your logic against edge cases before presenting the final solution
8- Ensure all code follows Val Town's specific platform requirements
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
19- Follow modern ES6+ conventions and functional programming practices if possible
20
21## Types of triggers
28
29```ts
30export default async function (req: Request) {
31 return new Response("Hello World");
32}
42
43```ts
44export default async function () {
45 // Scheduled task code
46}
56
57```ts
58export default async function (email: Email) {
59 // Process email
60}
66## Val Town Standard Libraries
67
68Val Town provides several hosted services and utility functions.
69
70### Blob Storage
120```
121
122## Val Town Utility Functions
123
124Val Town provides several utility functions to help with common project tasks.
125
126### Importing Utilities
200│ ├── database/
201│ │ ├── migrations.ts # Schema definitions
202│ │ ├── queries.ts # DB query functions
203│ │ └── README.md
204│ └── routes/ # Route modules
219└── shared/
220 ├── README.md
221 └── utils.ts # Shared types and functions
222```
223
226- Hono is the recommended API framework
227- Main entry point should be `backend/index.ts`
228- **Static asset serving:** Use the utility functions to read and serve project files:
229 ```ts
230 import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
262- Export clear query functions with proper TypeScript typing
263
264## Common Gotchas and Solutions

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