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/$%7Burl%7D?q=function&page=92&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 28929 results for "function"(4388ms)

Towniedashboard.ts1 match

@apiryโ€ขUpdated 3 days ago
15}
16
17export function renderDashboard(data: UserSummaryRow[]): string {
18 // Calculate totals
19 const totalUsers = data.length;

Townie.cursorrules12 matches

@apiryโ€ขUpdated 3 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}
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

TownieChatRouteSingleColumn.tsx3 matches

@apiryโ€ขUpdated 3 days ago
18
19// alt single-column version of /chat route
20export function ChatRouteSingleColumn () {
21 const { projectId, branchId } = useParams() as {
22 projectId: string;
55}
56
57function Conversation ({
58 project,
59 files,
194}
195
196function shouldRefetch (message) {
197 for (let i = 0; i < message?.parts?.length; i++) {
198 let part = message.parts[i];

TowniecalculateCost.tsx1 match

@apiryโ€ขUpdated 3 days ago
5const CACHE_WRITE_RATE = 3.75; // $3.75 per M cache-write tokens
6
7export function calculateCost({
8 input_tokens,
9 output_tokens,

TownieBranchSelect.tsx1 match

@apiryโ€ขUpdated 3 days ago
7const NEW_BRANCH_VAL = "__NEW_BRANCH__";
8
9export function BranchSelect() {
10 const { projectId, branchId } = useParams() as {
11 projectId: string;

Townieauth.ts1 match

@apiryโ€ขUpdated 3 days ago
5 * Returns null if authentication is successful, or a Response if it fails
6 */
7export async function basicAuthMiddleware(req: Request): Promise<Response | null> {
8 const realm = "Usage Dashboard";
9 const unauthorizedResponse = new Response("Unauthorized", {

TownieApp.tsx1 match

@apiryโ€ขUpdated 3 days ago
17});
18
19export function App() {
20 const [audio, setAudio] = useLocalStorage("AUDIO", false);
21 const user = useUser();

Homepageindex.ts5 matches

@dukkyโ€ขUpdated 3 days ago
1export default async function(req: Request) {
2 const html = `<!DOCTYPE html>
3<html lang="en">
245
246 <script>
247 // Theme toggle functionality
248 const themeToggle = document.getElementById('theme-toggle');
249 const themeIcon = document.getElementById('theme-icon');
264 });
265
266 function updateThemeIcon(theme) {
267 themeIcon.textContent = theme === 'dark' ? 'โ˜€๏ธ' : '๐ŸŒ™';
268 }
269
270 // Add some interactive animations
271 document.addEventListener('DOMContentLoaded', function() {
272 // Smooth scroll for any internal links
273 document.querySelectorAll('a[href^="#"]').forEach(anchor => {
274 anchor.addEventListener('click', function (e) {
275 e.preventDefault();
276 const target = document.querySelector(this.getAttribute('href'));

Appiah200main.tsx1 match

@APPIAHโ€ขUpdated 3 days ago
2import { renderToString } from "npm:react-dom/server";
3
4export default async function(req: Request) {
5 return new Response(
6 renderToString(

linkInBioTemplatemain.tsx1 match

@APPIAHโ€ขUpdated 3 days ago
2import { renderToString } from "npm:react-dom/server";
3
4export default async function(req: Request) {
5 return new Response(
6 renderToString(
tuna

tuna9 file matches

@jxnblkโ€ขUpdated 14 hours 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.