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/$%7BsvgDataUrl%7D?q=function&page=82&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 31574 results for "function"(4185ms)

middleranger-stevensgenerateFunFacts.ts8 matches

@middlerangerโ€ขUpdated 5 days 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();

middleranger-stevens.cursorrules15 matches

@middlerangerโ€ขUpdated 5 days 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
1import { sendDailyBriefing } from "./sendDailyBrief.ts";
2
3export async function cronDailyBrief() {
4 try {
5 const chatId = Deno.env.get("TELEGRAM_CHAT_ID");

middleranger-stevensApp.tsx2 matches

@middlerangerโ€ขUpdated 5 days ago
62};
63
64export function App() {
65 const [memories, setMemories] = useState<Memory[]>([]);
66 const [loading, setLoading] = useState(true);
139 const data = await response.json();
140
141 // Change the sorting function to show memories in chronological order
142 const sortedMemories = [...data].sort((a, b) => {
143 const dateA = a.createdDate || 0;

ChatmcpPrompts.ts7 matches

@c15rโ€ขUpdated 5 days ago
16 * @returns Promise<MCPPromptsResult>
17 */
18export async function fetchMCPPrompts(clientPool: MCPClientPool): Promise<MCPPromptsResult> {
19 try {
20 return await clientPool.fetchPrompts();
35 * @returns Promise<MCPPromptsResult>
36 */
37export async function fetchMCPPromptsWithCache(
38 clientPool: MCPClientPool,
39 cacheKey: string = "mcp_prompts_cache",
100 * @param cacheKey - Cache key to clear
101 */
102export function clearMCPPromptsCache(cacheKey: string = "mcp_prompts_cache"): void {
103 localStorage.removeItem(cacheKey);
104}
105
106/**
107 * Legacy function for backward compatibility - uses direct fetch
108 * @deprecated Use fetchMCPPrompts with clientPool instead
109 */
110export async function fetchMCPPromptsDirect(servers: MCPServerConfig[]): Promise<MCPPromptsResult> {
111 try {
112 if (!servers || !Array.isArray(servers)) {
161
162/**
163 * Legacy function - fetch prompts from a single MCP server using direct fetch
164 * @deprecated Use client pool instead
165 */
166async function fetchPromptsFromServerDirect(server: MCPServerConfig): Promise<MCPPrompt[]> {
167 if (!server.enabled || !server.url) {
168 return [];

ChatmcpTools.ts7 matches

@c15rโ€ขUpdated 5 days ago
16 * @returns Promise<MCPToolsResult>
17 */
18export async function fetchMCPTools(clientPool: MCPClientPool): Promise<MCPToolsResult> {
19 try {
20 return await clientPool.fetchTools();
35 * @returns Promise<MCPToolsResult>
36 */
37export async function fetchMCPToolsWithCache(
38 clientPool: MCPClientPool,
39 cacheKey: string = "mcp_tools_cache",
100 * @param cacheKey - Cache key to clear
101 */
102export function clearMCPToolsCache(cacheKey: string = "mcp_tools_cache"): void {
103 localStorage.removeItem(cacheKey);
104}
105
106/**
107 * Legacy function for backward compatibility - uses direct fetch
108 * @deprecated Use fetchMCPTools with clientPool instead
109 */
110export async function fetchMCPToolsDirect(servers: MCPServerConfig[]): Promise<MCPToolsResult> {
111 try {
112 if (!servers || !Array.isArray(servers)) {
148
149/**
150 * Legacy function - fetch tools from a single MCP server using direct fetch
151 * @deprecated Use client pool instead
152 */
153async function fetchToolsFromServerDirect(server: MCPServerConfig): Promise<MCPTool[]> {
154 if (!server.enabled || !server.url) {
155 return [];

ChatuseMCPClients.tsx3 matches

@c15rโ€ขUpdated 5 days ago
15 * Hook to manage MCP client instances based on server configurations
16 */
17export default function useMCPClients(serverConfigs: MCPServerConfig[]) {
18 const [clientStates, setClientStates] = useState<Map<string, MCPClientState>>(new Map());
19
101 }, [serverConfigs]);
102
103 // Helper function to connect a client
104 const connectClient = useCallback(async (id: string, client: MCPClient, initialState: MCPClientState) => {
105 try {
166 }, [connectedClients, serverConfigs]);
167
168 // Get connected clients (legacy function for backward compatibility)
169 const getConnectedClients = useCallback((): MCPClient[] => {
170 return connectedClients;

ChatResourceViewer-README.md4 matches

@c15rโ€ขUpdated 5 days ago
12- **๐Ÿ“ฑ Fullscreen Mode** - Toggle fullscreen for better viewing of large files
13- **๐Ÿ”„ Smart Caching** - Caches fetched content for 5 minutes to improve performance
14- **๐Ÿ” Retry Mechanism** - Automatic retry functionality when resource fetching fails
15- **๐Ÿ“‹ Metadata Display** - Shows file type, content type, and source server information
16- **๐ŸŽฏ Adaptive Rendering** - Chooses optimal rendering mode based on file type and hints
231## Implementation Notes
232
233- ResourceViewer is integrated into the Message component's `renderAnthropicBlocks()` function
234- Detection happens in the `mcp_tool_result` case after NextSteps and before HTML detection
235- CodeMirror extensions are loaded dynamically based on file type
242- **Stable Reference Management** - MCP clients array is memoized in the parent hook to prevent reload loops
243- **Simplified Dependency Chains** - Reduced nested useCallback dependencies to minimize effect re-executions
244- **Optimized useEffect Dependencies** - Removed function dependencies that caused infinite reload loops
245
246## Dependencies
254- **Binary File Support** - Display images, PDFs, etc.
255- **Diff Viewer** - Compare file versions
256- **Search/Find** - In-file search functionality
257- **Download Support** - Save resources locally
258- **Collaborative Editing** - Real-time editing capabilities

capsidemailsmain.js3 matches

@yawnxyzโ€ขUpdated 5 days ago
198 const errorText = document.getElementById('errorText');
199
200 function showSuccess(message) {
201 successText.textContent = message;
202 successMessage.classList.remove('hidden');
204 }
205
206 function showError(message) {
207 errorText.textContent = message;
208 errorMessage.classList.remove('hidden');
210 }
211
212 function hideMessages() {
213 successMessage.classList.add('hidden');
214 errorMessage.classList.add('hidden');

capsidemailsemail.js2 matches

@yawnxyzโ€ขUpdated 5 days ago
5// =============================================================================
6
7// Email handler function for Val.Town
8export async function emailHandler(email) {
9 const rawContent = email.html || email.text || "No content";
10 const cleanedContent = await cleanEmailContent(rawContent);
tuna

tuna9 file matches

@jxnblkโ€ขUpdated 2 weeks ago
Simple functional CSS library for Val Town

getFileEmail4 file matches

@shouserโ€ขUpdated 2 months 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.