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/?q=function&page=11&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 30401 results for "function"(3020ms)

Townie2useLoadingFavicon.ts3 matches

@charmaineโ€ขUpdated 12 hours ago
1import { useEffect } from "react";
2
3function setLoadingFavicon() {
4 document.querySelector('link[rel="icon"]').href = "/favicon-loading.svg";
5}
6function resetFavicon() {
7 document.querySelector('link[rel="icon"]').href = "/favicon.svg";
8}
9
10export function useLoadingFavicon(loading: boolean) {
11 useEffect(() => {
12 if (loading) setLoadingFavicon();

Townie2useCreditBalance.tsx1 match

@charmaineโ€ขUpdated 12 hours ago
2import { useState, useEffect } from "react";
3
4export function useCreditBalance() {
5 const [balance, setBalance] = useState<number | null>(null);
6 const [loading, setLoading] = useState(true);

Townie2useCreateProject.tsx1 match

@charmaineโ€ขUpdated 12 hours ago
3const ENDPOINT = "/api/create-project";
4
5export function useCreateProject() {
6 const [data, setData] = useState<any>(null);
7 const [loading, setLoading] = useState(false);

Townie2useCreateBranch.tsx1 match

@charmaineโ€ขUpdated 12 hours ago
3const ENDPOINT = "/api/create-branch";
4
5export function useCreateBranch(projectId: string) {
6 const [data, setData] = useState<any>(null);
7 const [loading, setLoading] = useState(false);

Townie2useChatLogic.ts1 match

@charmaineโ€ขUpdated 12 hours ago
14const LIMIT_RE = /You have reached/;
15
16export function useChatLogic({
17 project,
18 branchId,

Townie2useBranches.tsx1 match

@charmaineโ€ขUpdated 12 hours 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);

Townie2usage-detail.ts1 match

@charmaineโ€ขUpdated 12 hours ago
43}
44
45export function renderUsageDetail(
46 usage: UsageDetail,
47 inferenceCalls: InferenceCall[],

Townie2text-editor.ts1 match

@charmaineโ€ขUpdated 12 hours ago
4import fileWithLinesNumbers from "../utils/fileWithLinesNumbers.ts";
5
6function printFileType(file: any) {
7 if (file.type === "interval")
8 return " (cron)";

Townie2system_prompt.txt12 matches

@charmaineโ€ขUpdated 12 hours 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
176โ”‚ โ”œโ”€โ”€ database/
177โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
178โ”‚ โ”‚ โ”œโ”€โ”€ queries.ts # DB query functions
179โ”‚ โ”‚ โ””โ”€โ”€ README.md
180โ”‚ โ””โ”€โ”€ routes/ # Route modules
195โ””โ”€โ”€ shared/
196 โ”œโ”€โ”€ README.md
197 โ””โ”€โ”€ utils.ts # Shared types and functions
198```
199
203- Main entry point should be `backend/index.ts`
204- Do NOT use Hono serveStatic middleware
205- **Static asset serving:** Use the utility functions to read and serve project files:
206 ```ts
207 import { readFile, serveFile } from "https://esm.town/v/std/utils/index.ts";
237- Run migrations on startup or comment out for performance
238- Change table names when modifying schemas rather than altering
239- Export clear query functions with proper TypeScript typing
240
241## Common Gotchas and Solutions

Townie2styles.css2 matches

@charmaineโ€ขUpdated 12 hours ago
161 transition-property: background-color;
162 transition-duration: 400ms;
163 transition-timing-function: linear;
164}
165
861 transition-property: color, background-color, border-color, opacity;
862 transition-duration: 200ms;
863 transition-timing-function: ease-in-out;
864}
865
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.