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/$%7Bsuccess?q=function&page=65&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 19855 results for "function"(1984ms)

view-9448view-1227.tsx1 match

@fwdโ€ขUpdated 2 days ago
1import { email } from "https://esm.town/v/std/email";
2
3export default async function(req: Request): Promise<Response> {
4 const xForwardedFor = req.headers.get("X-Forwarded-For") ?? "n/a";
5 const trueClientIP = req.headers.get("True-Client-IP") ?? "n/a";

buildindex.ts2 matches

@charmaineโ€ขUpdated 2 days ago
1export default async function (req: Request) {
2 const html = `<!DOCTYPE html>
3<html lang="en">
130
131 // Update the countdown every 1 second
132 const countdownTimer = setInterval(function() {
133 // Get current date and time
134 const now = new Date().getTime();

appindex.ts1 match

@charmaineโ€ขUpdated 2 days ago
1import { readFile } from "https://esm.town/v/std/utils@85-main/index.ts";
2
3export default async function(req: Request): Promise<Response> {
4 const url = new URL(req.url);
5 const path = url.pathname;

appscript.js12 matches

@charmaineโ€ขUpdated 2 days ago
19
20 // Create a new orange element
21 function createOrange() {
22 const orange = document.createElement('div');
23 orange.className = 'orange w-12 h-12 bg-orange-500 rounded-full flex items-center justify-center';
41
42 // Add an orange to the basket
43 function addOrange() {
44 const orange = createOrange();
45 orangeBasket.appendChild(orange);
54
55 // Start dragging an orange
56 function startDrag(e) {
57 isDragging = true;
58 currentOrange = this;
72
73 // Handle touch events for mobile
74 function handleTouchStart(e) {
75 isDragging = true;
76 currentOrange = this;
91
92 // Drag the orange
93 function drag(e) {
94 if (!isDragging) return;
95
103
104 // Handle touch move for mobile
105 function handleTouchMove(e) {
106 if (!isDragging) return;
107
118
119 // Drop the orange
120 function drop(e) {
121 if (!isDragging) return;
122
142
143 // Handle touch end for mobile
144 function handleTouchEnd(e) {
145 if (!isDragging) return;
146
166
167 // Squeeze the orange
168 function squeezeOrange() {
169 // Animate the bear squeezing
170 bear.classList.add('squeezing');
234
235 // Check for achievements based on juice amount
236 function checkAchievements() {
237 const achievements = [
238 { threshold: 100, message: "๐ŸŽ‰ First Cup Filled!" },
250
251 // Show achievement notification
252 function showAchievement(message) {
253 const notification = document.createElement('div');
254 notification.className = 'fixed top-4 left-1/2 transform -translate-x-1/2 bg-orange-600 text-white px-4 py-2 rounded-lg shadow-lg z-50';
267
268 // Reset the game
269 function resetGame() {
270 // Clear all oranges
271 orangeBasket.innerHTML = '';

town-hallAttendeeForm.tsx2 matches

@stevekrouseโ€ขUpdated 2 days ago
27}
28
29export function AttendeeForm({ onSubmitSuccess, onSubmitError }: AttendeeFormProps) {
30 const [formData, setFormData] = useState<FormData>({
31 name: "",
108 };
109
110 // Helper function to check if an interest is selected
111 const isInterestSelected = (interestLabel: string) => {
112 return formData.interests.includes(interestLabel);

Townie-02App.tsx1 match

@jxnblkโ€ขUpdated 2 days ago
26});
27
28export function App() {
29 const [audio, setAudio] = useLocalStorage("AUDIO", false);
30 const user = useUser();

town-hallindex.ts1 match

@stevekrouseโ€ขUpdated 2 days ago
14
15// Create the attendees table if it doesn't exist
16async function initializeDatabase() {
17 console.log("Initializing database...");
18 try {

Townie-02useUser.tsx1 match

@jxnblkโ€ขUpdated 2 days ago
3const USER_ENDPOINT = "/api/user";
4
5export function useUser () {
6 const [data, setData] = useState<any>(null);
7 const [loading, setLoading] = useState(true);

Townie-02system_prompt.txt12 matches

@jxnblkโ€ขUpdated 2 days 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}
40
41```ts
42export default async function () {
43 // Scheduled task code
44}
52
53```ts
54export default async function (email: Email) {
55 // Process email
56}
60## Val Town Standard Libraries
61
62Val Town provides several hosted services and utility functions.
63
64### Blob Storage
114```
115
116## Val Town Utility Functions
117
118Val Town provides several utility functions to help with common project tasks.
119
120### Importing Utilities
194โ”‚ โ”œโ”€โ”€ database/
195โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
196โ”‚ โ”‚ โ”œโ”€โ”€ queries.ts # DB query functions
197โ”‚ โ”‚ โ””โ”€โ”€ README.md
198โ”‚ โ””โ”€โ”€ routes/ # Route modules
213โ””โ”€โ”€ shared/
214 โ”œโ”€โ”€ README.md
215 โ””โ”€โ”€ utils.ts # Shared types and functions
216```
217
221- Main entry point should be `backend/index.ts`
222- Do NOT use Hono serveStatic middleware
223- **Static asset serving:** Use the utility functions to read and serve project files:
224 ```ts
225 import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
255- Run migrations on startup or comment out for performance
256- Change table names when modifying schemas rather than altering
257- Export clear query functions with proper TypeScript typing
258
259## Common Gotchas and Solutions

Townie-02useBranches.tsx1 match

@jxnblkโ€ขUpdated 2 days ago
3const ENDPOINT = "/api/project-branches";
4
5export function useBranches (projectId: string) {
6 const [data, setData] = useState<any>(null);
7 const [loading, setLoading] = useState(true);

getFileEmail4 file matches

@shouserโ€ขUpdated 3 weeks ago
A helper function to build a file's email
tuna

tuna8 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.