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=646&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 15180 results for "function"(1265ms)

utilsexample.test.ts4 matches

@MitP1997โ€ขUpdated 1 month ago
8 {
9 name: "no-op",
10 function: () => {
11 return true;
12 },
14 {
15 name: "passing test",
16 function: () => {
17 expect(1).toBe(1);
18 },
20 {
21 name: "Failing test",
22 function: () => {
23 expect(1).toBe(2);
24 },
31 {
32 name: "passing test 2",
33 function: () => {
34 expect(1).toBe(1);
35 },

trAIderAgentagent.ts1 match

@kamalnrfโ€ขUpdated 1 month ago
62});
63
64export async function trAIderAgent(conversation: { role: string; content: string }[]): Promise<Response> {
65 const metaDetails = `
66 \n

magnificentCopperOrcamain.tsx3 matches

@rkrakibk2โ€ขUpdated 1 month ago
3import React, { useEffect, useState } from "https://esm.sh/react@18.2.0";
4
5function App() {
6 const [statuses, setStatuses] = useState([]);
7 const [copiedStatus, setCopiedStatus] = useState(null);
94}
95
96function client() {
97 const link = document.createElement("link");
98 link.href = "https://fonts.googleapis.com/css2?family=Hind+Siliguri&display=swap";
105if (typeof document !== "undefined") { client(); }
106
107export default async function server(request: Request): Promise<Response> {
108 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
109 const KEY = "magnificentCopperOrca";

FixItWandSignIn.tsx1 match

@wolfโ€ขUpdated 1 month ago
4type SignInState = "idle" | "loading" | "sent";
5
6export function SignIn() {
7 const [email, setEmail] = useState<null | string>(null);
8 const [state, setState] = useState<SignInState>("idle");

imagegeneratormain.tsx4 matches

@youssef1527โ€ขUpdated 1 month ago
8const CANVAS_HEIGHT = 400;
9
10function SnakeGame() {
11 const canvasRef = useRef(null);
12 const [score, setScore] = useState(0);
23
24 // Generate random food position
25 function generateFood() {
26 return {
27 x: Math.floor(Math.random() * (CANVAS_WIDTH / GRID_SIZE)) * GRID_SIZE,
205}
206
207function client() {
208 createRoot(document.getElementById("root")).render(<SnakeGame />);
209}
210if (typeof document !== "undefined") { client(); }
211
212export default async function server(request: Request): Promise<Response> {
213 return new Response(
214 `

OpenTownieuseProjectFiles.ts1 match

@k7dโ€ขUpdated 1 month ago
17 * Custom hook to fetch and manage project files
18 */
19export function useProjectFiles({
20 projectId,
21 branchId,

OpenTownieuseChatLogic.ts1 match

@k7dโ€ขUpdated 1 month ago
13}
14
15export function useChatLogic({
16 project,
17 branchId,

OpenTownietext-editor.ts6 matches

@k7dโ€ขUpdated 1 month ago
5 * View a file or directory in a Val Town project
6 */
7async function view(
8 vt: ValTown,
9 project: any,
70 * Replace a string in a file in a Val Town project
71 */
72async function str_replace(
73 vt: ValTown,
74 project: any,
132 * Create a new file in a Val Town project
133 */
134async function create(vt: ValTown, project: any, branch_id: string | undefined, path: string, file_text?: string) {
135 let type_: "file" | "http" | "script";
136 if (path.includes("backend/index.ts")) type_ = "http";
166 * Insert a string at a specific line in a file in a Val Town project
167 */
168async function insert(
169 vt: ValTown,
170 project: any,
209 * Undo the last edit to a file in a Val Town project (not implemented)
210 */
211async function undo_edit(vt: ValTown, project: any, branch_id: string | undefined) {
212 return {
213 type: "error",
219 * Creates a text editor tool for editing files in a Val Town project
220 */
221export function getTextEditorTool(bearerToken: string, project: any, branch_id: string | undefined) {
222 const vt = new ValTown({ bearerToken });
223 return anthropic.tools.textEditor_20250124({

OpenTowniesystem_prompt.txt9 matches

@k7dโ€ขUpdated 1 month ago
7- Respond in a friendly and concise manner
8- Ask clarifying questions when requirements are ambiguous
9- Provide complete, functional solutions rather than skeleton implementations
10- Test your logic against edge cases before presenting the final solution
11- Ensure all code follows Val Town's specific platform requirements
30- **Never bake in secrets into the code** - always use environment variables
31- Include comments explaining complex logic (avoid commenting obvious operations)
32- Follow modern ES6+ conventions and functional programming practices where appropriate
33
34### Val Town Utility Functions
35
36Val Town provides several utility functions to help with common project tasks. These utilities handle file management, project information, and testing.
37
38### Importing Utilities
84 {
85 name: "should add numbers correctly",
86 function: () => {
87 expect(1 + 1).toBe(2);
88 },
168โ”‚ โ”œโ”€โ”€ database/
169โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
170โ”‚ โ”‚ โ”œโ”€โ”€ queries.ts # DB query functions
171โ”‚ โ”‚ โ””โ”€โ”€ README.md
172โ”‚ โ”œโ”€โ”€ index.ts # Main entry point
184โ””โ”€โ”€ shared/
185 โ”œโ”€โ”€ README.md
186 โ””โ”€โ”€ utils.ts # Shared types and functions
187```
188
190- Hono is the recommended API framework (similar to Express, Flask, or Sinatra)
191- Main entry point should be `backend/index.ts`
192- **Static asset serving:** Use the utility functions to read and serve project files:
193 ```ts
194 // Use the serveFile utility to handle content types automatically
231- Run migrations on startup or comment out for performance
232- Change table names when modifying schemas rather than altering
233- Export clear query functions with proper TypeScript typing
234- Follow the queries and migrations pattern from the example
235

OpenTowniesoundEffects.ts3 matches

@k7dโ€ขUpdated 1 month ago
1/**
2 * Sound effects utility functions for the application
3 */
4
7 * @returns A Promise that resolves when the sound has started playing
8 */
9export function playBellSound(): Promise<void> {
10 return new Promise((resolve) => {
11 try {
69 * @returns A Promise that resolves when the sound has started playing
70 */
71export function playSimpleNotification(): Promise<void> {
72 return new Promise((resolve) => {
73 try {

getFileEmail4 file matches

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

tuna8 file matches

@jxnblkโ€ขUpdated 1 week 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": "*",