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=120&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 29385 results for "function"(3481ms)

Townieauth.ts1 match

@shecthrivesโ€ขUpdated 5 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

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

markdownBlogStarterLayout.tsx1 match

@meme20โ€ขUpdated 5 days ago
2import type { ReactNode } from "npm:react@18.2.0";
3
4export function Layout({ children }: { children: ReactNode }) {
5 return (
6 <html lang="en">

markdownBlogStarterindex.tsx3 matches

@meme20โ€ขUpdated 5 days ago
5import { Layout } from "./Layout.tsx";
6
7function PostComponent({ markdown, link }: { markdown: string; link?: string }) {
8 return (
9 <div style={{ border: "1px solid gray", padding: "10px", marginBottom: "20px", borderRadius: "5px" }}>
14}
15
16export default async function(req: Request): Promise<Response> {
17 const url = new URL(req.url);
18 if (url.pathname === "/") {
44}
45
46function html(children: React.ReactNode) {
47 return new Response(
48 renderToString(

JsonViewerindex.ts11 matches

@wolfโ€ขUpdated 5 days ago
6 */
7
8export default async function (req: Request) {
9 const html = `<!DOCTYPE html>
10<html lang="en">
172 let hasValidJSON = false;
173
174 document.addEventListener('DOMContentLoaded', function() {
175 // Initialize preview editor
176 const previewContainer = document.getElementById('json-preview');
178 mode: 'tree',
179 modes: ['tree', 'view', 'form', 'code', 'text'],
180 onError: function(err) {
181 showError(err.toString());
182 }
191 mode: 'tree',
192 modes: ['tree', 'view', 'form', 'code', 'text'],
193 onError: function(err) {
194 showError(err.toString());
195 }
219 });
220
221 function switchTab(tabId) {
222 // Update tab active states
223 document.getElementById('input-tab').classList.toggle('active', tabId === 'input');
236 }
237
238 function formatJSON() {
239 const jsonInput = document.getElementById('json-input').value.trim();
240 if (!jsonInput) {
261 }
262
263 function clearJSON() {
264 document.getElementById('json-input').value = '';
265 previewEditor.set({});
270 }
271
272 function copyJSON() {
273 try {
274 const jsonData = viewerEditor.get();
290 }
291
292 function showError(message) {
293 const errorContainer = document.getElementById('error-container');
294 errorContainer.textContent = message;
296 }
297
298 function hideError() {
299 const errorContainer = document.getElementById('error-container');
300 errorContainer.textContent = '';
302 }
303
304 function loadSampleData(index) {
305 let sampleJSON = {};
306

readlocalfilenew-file-2413.tsx2 matches

@vnatarajaโ€ขUpdated 5 days ago
24 const output = document.getElementById('output');
25
26 function log(msg) {
27 output.textContent += msg + '\\n';
28 }
31
32 try {
33 const test = new Function("return require('fs')");
34 test();
35 log("๐Ÿšจ Sandbox likely disabled: 'require' is accessible");

Towniesystem_prompt.txt12 matches

@KhadijahAleeyuAโ€ขUpdated 5 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
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

TownieValTownLogo.tsx1 match

@KhadijahAleeyuAโ€ขUpdated 5 days ago
1/** @jsxImportSource https://esm.sh/react@18.2.0?dev */
2
3export function ValTownLogo () {
4 return (
5 <svg

TownieuseUser.tsx1 match

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

TownieuseUsageStats.ts1 match

@KhadijahAleeyuAโ€ขUpdated 5 days ago
1import { useEffect } from "react";
2
3export function useUsageStats(messages: any[], usages: any[]) {
4 useEffect(() => {
5 if (!messages?.length) return;
tuna

tuna9 file matches

@jxnblkโ€ขUpdated 2 days 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.