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?q=function&page=29&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 33018 results for "function"(1954ms)

create-safehash-serversql.ts7 matches

@ianmenethil•Updated 2 days ago
21
22// // One SQL query
23// export async function execute(sql: string, args: SqlParam[] = []): Promise<ResultSet> {
24// return await sqlite.execute(sql, args);
25// }
26
27// // Batch of queries
28// export async function batch(
29// statements: { sql: string; args: SqlParam[] }[],
30// mode: "write" | "read" | "deferred" = "write",
34
35// // Insert
36// export async function insert(table: string, data: Record<string, SqlParam>): Promise<ResultSet> {
37// const columns = Object.keys(data);
38// const placeholders = columns.map(() => "?").join(", ");
43
44// // Update
45// export async function update(
46// table: string,
47// data: Record<string, SqlParam>,
57
58// // Delete
59// export async function remove(
60// table: string,
61// where: string,
67
68// // Select
69// export async function select(
70// table: string,
71// columns: string[] = ["*"],
79// }
80
81// function sanitizeIdent(ident: string): string {
82// if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(ident)) {
83// throw new Error(`Invalid SQL identifier: ${ident}`);

valetmain.tsx4 matches

@join•Updated 2 days ago
62// --- FRONTEND GENERATION ---
63
64// FIX: The function signature is updated to accept an optional errorMessage.
65function generateHtml(sourceUrl: string, errorMessage?: string) {
66 return `<!DOCTYPE html>
67<html lang="en">
296
297<script>
298(async function() {
299 // If an error message is present, the app is in a failure state. Do not run the script.
300 if (${!!errorMessage}) return;
428 };
429
430 async function initialize() {
431 showLoading(true);
432 try {

untitled-6822main.tsx1 match

@jdeal•Updated 2 days ago
1export default async function (req: Request): Promise<Response> {
2 return Response.json({ ok: true })
3}

blorpmain.tsx20 matches

@join•Updated 2 days ago
55
56// --- HTML & FRONTEND ---
57function generateHtml(sourceUrl: string) {
58 return `<!DOCTYPE html>
59<html lang="en">
323 const idleAnimations = ["E:blink", "B:1.05,0.95@400 R:all@600", "E:0.9@500 R:all@500"];
324
325 function resizeCanvas() { canvas.width = window.innerWidth; canvas.height = window.innerHeight; }
326 resizeCanvas();
327 window.addEventListener('resize', resizeCanvas);
328
329 function particleLoop() {
330 ctx.clearRect(0, 0, canvas.width, canvas.height);
331 particles.forEach((p, index) => {
351 }
352
353 function emitParticles(type, amount) {
354 const monsterRect = monster.getBoundingClientRect();
355 const startX = monsterRect.left + monsterRect.width / 2;
364 });
365
366 function updateParallax() {
367 const faceOffsetX = mouse.x * -15, faceOffsetY = mouse.y * -15;
368 monsterFace.style.transform = \`translate3d(\${faceOffsetX}px, \${faceOffsetY}px, 50px)\`;
378 }
379
380 function resetIdleTimer() {
381 clearTimeout(idleTimer);
382 if (!isAnimating) idleTimer = setTimeout(() => parseAndEnqueue(idleAnimations[Math.floor(Math.random() * idleAnimations.length)]), 7000);
383 }
384
385 function parseAndEnqueue(script) {
386 resetIdleTimer();
387 animationQueue.push(...script.trim().split(/\\s+/));
389 }
390
391 async function processQueue() {
392 if (animationQueue.length === 0) { isAnimating = false; resetIdleTimer(); return; }
393 isAnimating = true;
415 }
416
417 function setMouthShape(shape) {
418 monsterMouth.className = 'monster__mouth ' + shape;
419 let yOffset = '0px';
424 }
425
426 function setEyeState(value) {
427 root.style.setProperty('--eye-scale', value === 'blink' ? 0.1 : parseFloat(value));
428 if (value === 'blink') setTimeout(() => root.style.setProperty('--eye-scale', 1), 150);
429 }
430
431 function setBodyState(value, duration) {
432 const [scaleY, scaleX] = value.split(',').map(parseFloat);
433 monster.style.transitionDuration = \`\${duration / 1000}s\`;
437 }
438
439 function setColorScheme(name, duration) {
440 const scheme = colorSchemes[name]; if (!scheme) return;
441 root.style.transition = \`--monster-color-hsl \${duration / 1000}s ease, --bg-color-hsl \${duration / 1000}s ease\`;
444 }
445
446 function setTextureState(name) {
447 if (!name) return;
448 const url = \`https://www.transparenttextures.com/patterns/\${name}.png\`;
451 }
452
453 function setFx(value, duration) {
454 const [type, strength] = value.split(',');
455 const s = parseFloat(strength);
470 }
471
472 function setDiscoMode(state) {
473 if (state === 'on') {
474 discoBall.classList.add('active');
485 }
486
487 function resetState(duration) { setBodyState("1,1", duration); root.style.setProperty('--eye-scale', 1); }
488
489 function playSound(value, duration) {
490 if (!audioContext || !value) return;
491 const [type, freqStr] = value.split(',');
533 });
534
535 function setTypingIndicator(isTyping, text = "...") {
536 chatBubble.classList.remove('visible');
537 // A short delay to allow the fade out transition to complete before changing text or starting fade-in
549 }
550
551 function initialGreeting() {
552 setTypingIndicator(false, "Hi friend! Me Blorp. I have learned a few new tricks.");
553 parseAndEnqueue("W:500 B:0.9,1.1@300 E:1.2@200 R:all@500 M:smile@2000");
566// --- VAL TOWN SERVER-SIDE LOGIC ---
567
568export default async function(req: Request) {
569 const url = new URL(req.url);
570

claude-apimain.tsx1 match

@ziyanwould•Updated 2 days ago
1export default async function(req: Request): Promise<Response> {
2 try {
3 // Create a new URL object from the incoming request URL

adventofcode2015solutions.ts6 matches

@gueejla•Updated 2 days ago
1export function day1(input: string) {
2 let currentFloor = 0;
3 let currentChar = 0;
21}
22
23export function day2(input: string) {
24 let sqFtPaper = 0;
25 let ftRibbon = 0;
60}
61
62export function day3(input: string) {
63 // Part uno
64 const visitedLocs = new Set(["0,0"]);
66
67 // Check where santa be shmooving and store new location if its a new casa
68 function updateAndCheckLoc(coordinateToUpdate: number, incrementOrDecrement: number) {
69 const currentCoordinates = currentLoc.split(",");
70 const newCoordinate = Number(currentCoordinates[coordinateToUpdate]) + incrementOrDecrement;
107
108 // Check where santa be shmooving and store new location if its a new casa with added logic for mr roboto santa
109 function updateAndCheckLocDups(coordinateToUpdate: number, incrementOrDecrement: number, whichSanta: number) {
110 const currentCoordinates = currentLocNthSanta[whichSanta].split(",");
111 const newCoordinate = Number(currentCoordinates[coordinateToUpdate]) + incrementOrDecrement;
144}
145
146async function getAnswer() {
147 // Import the readFile utility from Val Town's standard library
148 const { readFile } = await import("https://esm.town/v/std/utils/index.ts");

puppetmain.tsx11 matches

@join•Updated 2 days ago
62
63// --- HTML & FRONTEND ---
64function generateHtml(sourceUrl: string) {
65 return `<!DOCTYPE html>
66<html lang="en">
208
209<script>
210(function() {
211 const API_URL = '${sourceUrl}';
212 const speakBtn = document.getElementById('speakBtn');
225 let animationStartTime;
226
227 function setViseme(visemeClass) {
228 mouth.className = 'monster__mouth ' + visemeClass;
229 }
230
231 function applyHeadTilt(degrees) {
232 monster.style.transform = \`rotate(\${degrees}deg)\`;
233 }
234
235 function applyHeadNod(distance) {
236 monsterFace.style.transform = \`translateY(\${distance}px) translateX(-50%)\`;
237 }
238
239 function applyEyeDart(x, y) {
240 eyesContainer.style.transform = \`translate(\${x}px, \${y}px)\`;
241 }
242
243 function applyBlink(start) {
244 if (start) {
245 allEyes.forEach(eye => eye.style.height = '2px');
249 }
250
251 function applyEyebrows(position) {
252 let lTransform = '', rTransform = '';
253 switch(position) {
274 }
275
276 function stopAnimation() {
277 if (animationFrameId) {
278 cancelAnimationFrame(animationFrameId);
286 }
287
288 function animationLoop(plan) {
289 const elapsed = performance.now() - animationStartTime;
290
332 }
333
334 async function getAndPlayAnimation() {
335 const text = speechText.value.trim();
336 if (!text) return;

python_clockindex.ts1 match

@flymaster•Updated 2 days ago
1export default async function(req: Request) {
2 const now = new Date();
3 const timeString = now.toLocaleTimeString("en-US", {

MiniAppStarterui.tsx8 matches

@arseniy•Updated 2 days ago
3import { useEffect, useState } from "https://esm.sh/react@19";
4
5export function Section({ children, ...props }: any) {
6 const sectionClass = `p-5 rounded-3xl bg-neutral-400/15 ${props.className || ""}`;
7 return <div class={sectionClass}>{children}</div>;
93};
94
95// export function Input(props: any) {
96// const inputClass = "dark:bg-white dark:text-black bg-black text-white rounded-md px-3 py-1 ";
97// return <input class={inputClass} {...props} />;
98// }
99
100// export function Button(props: any) {
101// const buttonClass = "dark:bg-white dark:text-black bg-black text-white rounded-md px-3 py-1 ";
102// return <button class={buttonClass} {...props} />;
103// }
104
105export function MonoButton(props: any) {
106 return (
107 <Button {...props}>
111}
112
113export function MonoButtonWithStatus(props: any) {
114 const [status, setStatus] = useState<any>();
115 const handleClick = async () => {
132}
133
134export function formatJSON(json: any) {
135 return JSON.stringify(json, null, 2);
136}
146};
147
148export function BackButton({}) {
149 return <ArrowLeft className="w-5 h-5 m-2 cursor-pointer opacity-50" onClick={() => window.location.href = "/"} />;
150}
151
152export function ShareButton({ onClick }) {
153 return <Share className="w-5 h-5 m-2 cursor-pointer opacity-50" onClick={onClick} />;
154}

MiniAppStartersupabase.ts1 match

@arseniy•Updated 2 days ago
6)
7
8export async function sendAnalyticsEvent(payload: {
9 event: string
10 param?: string

discordWebhook2 file matches

@stevekrouse•Updated 1 day ago
Helper function to send Discord messages
tuna

tuna9 file matches

@jxnblk•Updated 3 weeks 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.