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=524&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 20407 results for "function"(2898ms)

stevensDemogenerateFunFacts.ts8 matches

@swriddleโ€ขUpdated 3 weeks ago
11 * @returns Array of previous fun facts
12 */
13async function getPreviousFunFacts() {
14 try {
15 const result = await sqlite.execute(
32 * @param dates Array of date strings in ISO format
33 */
34async function deleteExistingFunFacts(dates) {
35 try {
36 for (const date of dates) {
51 * @param factText The fun fact text
52 */
53async function insertFunFact(date, factText) {
54 try {
55 await sqlite.execute(
75 * @returns Array of generated fun facts
76 */
77async function generateFunFacts(previousFacts) {
78 try {
79 // Get API key from environment
197 * @returns Array of parsed facts
198 */
199function parseFallbackFacts(responseText, expectedDates) {
200 // Try to extract facts using regex
201 const factPattern = /(\d{4}-\d{2}-\d{2})["']?[,:]?\s*["']?(.*?)["']?[,}]/gs;
260
261/**
262 * Main function to generate and store fun facts for the next 7 days
263 */
264export async function generateAndStoreFunFacts() {
265 try {
266 // Get previous fun facts
301 * Intended to be used as a Val Town cron job
302 */
303export default async function() {
304 console.log("Running fun facts generation cron job...");
305 return await generateAndStoreFunFacts();

stevensDemo.cursorrules15 matches

@swriddleโ€ขUpdated 3 weeks ago
8### 1. Script Vals
9
10- Basic JavaScript/TypeScript functions
11- Can be imported by other vals
12- Example structure:
13
14```typescript
15export function myFunction() {
16 // Your code here
17}
25
26```typescript
27export default async function (req: Request) {
28 return new Response("Hello World");
29}
37
38```typescript
39export default async function () {
40 // Scheduled task code
41}
49
50```typescript
51export default async function (email: Email) {
52 // Process email
53}
57
58- Ask clarifying questions when requirements are ambiguous
59- Provide complete, functional solutions rather than skeleton implementations
60- Test your logic against edge cases before presenting the final solution
61- Ensure all code follows Val Town's specific platform requirements
70- **Never bake in secrets into the code** - always use environment variables
71- Include comments explaining complex logic (avoid commenting obvious operations)
72- Follow modern ES6+ conventions and functional programming practices if possible
73
74## Val Town Standard Libraries
75
76Val Town provides several hosted services and utility functions.
77
78### Blob Storage
124```
125
126## Val Town Utility Functions
127
128Val Town provides several utility functions to help with common project tasks.
129
130### Importing Utilities
176 {
177 name: "should add numbers correctly",
178 function: () => {
179 expect(1 + 1).toBe(2);
180 },
210โ”‚ โ”œโ”€โ”€ database/
211โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
212โ”‚ โ”‚ โ”œโ”€โ”€ queries.ts # DB query functions
213โ”‚ โ”‚ โ””โ”€โ”€ README.md
214โ”‚ โ”œโ”€โ”€ index.ts # Main entry point
226โ””โ”€โ”€ shared/
227 โ”œโ”€โ”€ README.md
228 โ””โ”€โ”€ utils.ts # Shared types and functions
229```
230
232- Hono is the recommended API framework (similar to Express, Flask, or Sinatra)
233- Main entry point should be `backend/index.ts`
234- **Static asset serving:** Use the utility functions to read and serve project files:
235 ```ts
236 // Use the serveFile utility to handle content types automatically
273- Run migrations on startup or comment out for performance
274- Change table names when modifying schemas rather than altering
275- Export clear query functions with proper TypeScript typing
276- Follow the queries and migrations pattern from the example
277

stevensDemocronDailyBrief.ts1 match

@swriddleโ€ขUpdated 3 weeks ago
1import { sendDailyBriefing } from "./sendDailyBrief.ts";
2
3export async function cronDailyBrief() {
4 try {
5 const chatId = Deno.env.get("TELEGRAM_CHAT_ID");

aab65694896_.cursorrules12 matches

@vtclitestsโ€ขUpdated 3 weeks 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

vtEditorFiles.cursorrules12 matches

@wolfโ€ขUpdated 3 weeks 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

FarcasterMiniAppStoreimage.tsx3 matches

@moeโ€ขUpdated 4 weeks ago
5import satori from "npm:satori";
6
7export function handleImageEndpoints(app: Hono) {
8 const headers = {
9 "Content-Type": "image/png",
15}
16
17export async function homeImage() {
18 return await ogImage(
19 <div
53//////////
54
55export async function ogImage(body) {
56 const svg = await satori(
57 body,

OpenTowniexuseProjectFiles.ts1 match

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

OpenTowniexuseChatLogic.ts1 match

@tallesjpโ€ขUpdated 4 weeks ago
13}
14
15export function useChatLogic({
16 project,
17 branchId,

OpenTowniextext-editor.ts7 matches

@tallesjpโ€ขUpdated 4 weeks ago
3import fileWithLinesNumbers from "../utils/fileWithLinesNumbers.ts";
4
5function printFileType(file: any){
6 if (file.type === "interval")
7 return " (cron)"
14 * View a file or directory in a Val Town project
15 */
16async function view(
17 vt: ValTown,
18 project: any,
71 * Replace a string in a file in a Val Town project
72 */
73async function str_replace(
74 vt: ValTown,
75 project: any,
133 * Create a new file in a Val Town project
134 */
135async function create(vt: ValTown, project: any, branch_id: string | undefined, path: string, file_text?: string) {
136 let type_: "file" | "http" | "script";
137 if (path.includes("backend/index.ts")) type_ = "http";
167 * Insert a string at a specific line in a file in a Val Town project
168 */
169async function insert(
170 vt: ValTown,
171 project: any,
210 * Undo the last edit to a file in a Val Town project (not implemented)
211 */
212async function undo_edit(vt: ValTown, project: any, branch_id: string | undefined) {
213 return {
214 type: "error",
220 * Creates a text editor tool for editing files in a Val Town project
221 */
222export function getTextEditorTool(bearerToken: string, project: any, branch_id: string | undefined) {
223 const vt = new ValTown({ bearerToken });
224 return anthropic.tools.textEditor_20250124({

OpenTowniexsystem_prompt.txt12 matches

@tallesjpโ€ขUpdated 4 weeks 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
220- Hono is the recommended API framework
221- Main entry point should be `backend/index.ts`
222- **Static asset serving:** Use the utility functions to read and serve project files:
223 ```ts
224 import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
254- Run migrations on startup or comment out for performance
255- Change table names when modifying schemas rather than altering
256- Export clear query functions with proper TypeScript typing
257
258## Common Gotchas and Solutions

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.