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/$%7BsvgDataUrl%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 30462 results for "function"(2598ms)

molarmessengermain.tsx1 match

@Dentalabcsβ€’Updated 41 mins ago
1export default async function(req: Request): Promise<Response> {
2 if (req.method !== "POST") {
3 return new Response("Only POST allowed", { status: 405 });

huyhieudemo.html1 match

@lanlyβ€’Updated 56 mins ago
20 <div id="demo-badges"></div>
21 <script>
22 function toggleBg() {
23 document.body.classList.toggle('dark')
24 const btn = document.querySelector('.toggle-btn');

honeydewmain.tsx23 matches

@legalβ€’Updated 1 hour ago
87 `;
88
89function generateHtmlShell(sourceUrl: string): string {
90 return `
91 <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Honeydew</title>
107 <template id="review-task-template"><div class="review-task-item"><input type="text" class="review-task-content" placeholder="Task description" required><input type="date" class="review-task-due-date" title="Due Date"><select class="review-task-load" title="Cognitive Load"><option value="Low">Low</option><option value="Medium" selected>Medium</option><option value="High">High</option></select><button type="button" class="review-task-delete-btn" title="Remove Task">&times;</button></div></template>
108 <script>
109 (function() {
110 const API_URL = '${sourceUrl}';
111 const STORE_KEYS = { projects: 'honeydew_projects_v1', tasks: 'honeydew_tasks_v1' };
117 const genId = () => Date.now().toString(36) + Math.random().toString(36).substr(2, 9);
118
119 function loadState() {
120 projects = getStore(STORE_KEYS.projects);
121 tasks = getStore(STORE_KEYS.tasks);
126 }
127
128 function render() {
129 renderSidebar();
130 renderTaskList();
132 }
133
134 function toggleLoading(btn, show) {
135 if (!btn) return;
136 btn.disabled = show;
138 }
139
140 function updateUIElements() {
141 const todayStr = new Date().toISOString().split("T")[0];
142 const todayTasks = tasks.filter(t => !t.isCompleted && t.dueDate === todayStr);
156 }
157
158 function renderSidebar() {
159 const mainViews = [
160 {id:'today',name:'Today',icon:'M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1z'},
165 }
166
167 function renderTaskList() {
168 const container = $("#task-list");
169 let filteredTasks = [], title = 'Tasks';
188 }
189
190 function renderChatLog() {
191 const log = $("#chat-log");
192 log.innerHTML = conversationHistory.map(msg => {
263 // --- MANUAL TOOL COMMAND LOGIC ---
264
265 function executeManualCommand(command) {
266 if (!command || !command.tool_name) return;
267
296 }
297
298 async function handleChatSubmit(e) {
299 e.preventDefault();
300 const input = $("#chat-input"), userMessage = input.value.trim();
345
346 // --- Standard Event Handlers ---
347 function handleAddTask(e) {
348 e.preventDefault();
349 const input = $("#new-task-input"), content = input.value.trim();
354 }
355
356 function handleTaskClick(e) {
357 const target = e.target, taskItem = target.closest(".task-item");
358 if (!taskItem) return;
369 }
370
371 function openEditModal(task) {
372 $("#edit-task-id").value = task.id;
373 $("#edit-task-content").value = task.content;
378 }
379
380 function handleUpdateTask(e) {
381 e.preventDefault();
382 const taskId = $("#edit-task-id").value, task = tasks.find(t => t.id === taskId);
390 }
391
392 async function triggerProjectSynthesisFromButton() {
393 const goal = prompt("Describe your new project or goal:", "Plan a launch party for a new product");
394 if (!goal) return;
407 }
408
409 async function triggerDailyRebalance() {
410 const todayStr = new Date().toISOString().split("T")[0];
411 const todayTasks = tasks.filter(t => !t.isCompleted && t.dueDate === todayStr);
433 }
434
435 function handleOpenChat() {
436 const mainInput = $('#new-task-input');
437 const text = mainInput.value.trim();
446 }
447
448 function addReviewTaskRow(taskData = {}) {
449 const template = $('#review-task-template');
450 const clone = template.content.cloneNode(true);
457 }
458
459 function openProjectReviewModal(data) {
460 const { projectName, tasks: aiTasks } = data;
461 $('#review-project-name').value = projectName;
468 }
469
470 function handleProjectReviewSubmit(e) {
471 e.preventDefault();
472 const projectName = $('#review-project-name').value.trim();
490 }
491
492 function bindEventListeners() {
493 document.body.addEventListener('click', e => {
494 if (e.target.closest('[data-view]')) {
546}
547
548export default async function(req: Request): Promise<Response> {
549 const openai = new OpenAI();
550 const url = new URL(req.url);

cardamonparse.ts4 matches

@connnollyβ€’Updated 2 hours ago
9// PDF parsing is now handled by unpdf library
10
11// Function to validate and clean recipe data
12function validateAndCleanRecipe(recipe: any): Recipe {
13 // Ensure required fields exist
14 if (!recipe.title || typeof recipe.title !== "string") {
75}
76
77// Function to convert fractional Unicode characters to decimal values
78function convertFractionsToDecimals(text: string): string {
79 const fractionMap: { [key: string]: string } = {
80 "ΒΌ": "0.25",

cardamonval-town.mdc12 matches

@connnollyβ€’Updated 2 hours ago
9
10- Ask clarifying questions when requirements are ambiguous
11- Provide complete, functional solutions rather than skeleton implementations
12- Test your logic against edge cases before presenting the final solution
13- Ensure all code follows Val Town's specific platform requirements
22- **Never bake in secrets into the code** - always use environment variables
23- Include comments explaining complex logic (avoid commenting obvious operations)
24- Follow modern ES6+ conventions and functional programming practices if possible
25
26## Types of triggers
33
34```ts
35export default async function (req: Request) {
36 return new Response("Hello World");
37}
45
46```ts
47export default async function () {
48 // Scheduled task code
49}
57
58```ts
59export default async function (email: Email) {
60 // Process email
61}
65## Val Town Standard Libraries
66
67Val Town provides several hosted services and utility functions.
68
69### Blob Storage
119```
120
121## Val Town Utility Functions
122
123Val Town provides several utility functions to help with common project tasks.
124
125### Importing Utilities
181β”‚ β”œβ”€β”€ database/
182β”‚ β”‚ β”œβ”€β”€ migrations.ts # Schema definitions
183β”‚ β”‚ β”œβ”€β”€ queries.ts # DB query functions
184β”‚ β”‚ └── README.md
185β”‚ └── routes/ # Route modules
200└── shared/
201 β”œβ”€β”€ README.md
202 └── utils.ts # Shared types and functions
203```
204
208- Main entry point should be `backend/index.ts`
209- Do NOT use Hono serveStatic middleware
210- **Static asset serving:** Use the utility functions to read and serve project files:
211 ```ts
212 import { readFile, serveFile } from "https://esm.town/v/std/utils/index.ts";
242- Run migrations on startup or comment out for performance
243- Change table names when modifying schemas rather than altering
244- Export clear query functions with proper TypeScript typing
245
246## Common Gotchas and Solutions

emailtesttrigger3 matches

@universeβ€’Updated 3 hours ago
4import { OpenAI } from "npm:openai";
5
6function pm(...lines: string[]): string {
7 return lines.join("\n");
8}
9
10export async function emailValHandler(inboundEmail: Email) {
11 const userPrompt = pm(
12 `From: ${inboundEmail.from}`,
23}
24
25export default async function(interval: Interval) {
26 const today = new Intl.DateTimeFormat("en-US", {
27 month: "short",

strategoindex.ts2 matches

@gueejlaβ€’Updated 5 hours ago
20const wss = new WebSocketServer({ noServer: true });
21
22// Helper function to broadcast messages to all connected clients
23function broadcastToAll(data: any, excludeClient?: WebSocket) {
24 const message = JSON.stringify(data);
25 clients.forEach((client) => {

GlancerdemoCache.ts1 match

@lightweightβ€’Updated 6 hours ago
9});
10
11export default async function (interval: Interval) {
12 // this cron runs every minute
13 // it saves a blob for every page in the "Glancer demos" database

GlancerrelatedPages.controller.ts1 match

@lightweightβ€’Updated 6 hours ago
7});
8
9export async function getRelatedPagesFromDatabase(pageId: string) {
10 try {
11 const response = await notion.databases.query({

demoSDKmain.tsx1 match

@chadparkerβ€’Updated 6 hours ago
1import ValTown from "npm:@valtown/sdk";
2
3export default async function(req: Request) {
4 try {
5 const vt = new ValTown();
tuna

tuna9 file matches

@jxnblkβ€’Updated 1 week ago
Simple functional CSS library for Val Town

getFileEmail4 file matches

@shouserβ€’Updated 1 month ago
A helper function to build a file's email
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.