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=58&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 8274 results for "function"(376ms)

stevensDemo.cursorrules15 matches

@arawlinsโ€ขUpdated 6 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

stevensDemocronDailyBrief.ts1 match

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

stevensDemoApp.tsx2 matches

@arawlinsโ€ขUpdated 6 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;

getVideoInfogetVideoTitle.ts1 match

@nbbaierโ€ขUpdated 6 days ago
1import { getVideoInfo } from "https://esm.town/v/nbbaier/getVideoInfo/main.tsx";
2
3export async function getVideoTitle(videoURL: string, key: string) {
4 const { title } = await getVideoInfo(videoURL, key);
5 return title;

getVideoInfomain.tsx1 match

@nbbaierโ€ขUpdated 6 days ago
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
2
3export async function getVideoInfo(videoURL: string, key: string) {
4 if (!videoURL) {
5 console.error("No URL Provided");

stevensDemoNotebookView.tsx1 match

@swriddleโ€ขUpdated 6 days ago
54}
55
56export function NotebookView({ onClose, avatarUrl }: NotebookViewProps) {
57 const [memories, setMemories] = useState<Memory[]>([]);
58 const [loading, setLoading] = useState(true);

stevensDemoApp.tsx2 matches

@swriddleโ€ขUpdated 6 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;

stevensDemohandleTelegramMessage.ts5 matches

@swriddleโ€ขUpdated 6 days ago
36 * Store a chat message in the database
37 */
38export async function storeChatMessage(
39 chatId,
40 senderId,
69 * Retrieve chat history for a specific chat
70 */
71export async function getChatHistory(chatId, limit = 50) {
72 try {
73 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
94 * Format chat history for Anthropic API
95 */
96function formatChatHistoryForAI(history) {
97 const messages = [];
98
118 * Analyze a Telegram message and extract memories from it
119 */
120async function analyzeMessageContent(
121 anthropic,
122 username,
499
500// Handle webhook requests
501export default async function (req: Request): Promise<Response> {
502 // Set webhook if it is not set yet
503 if (!isEndpointSet) {

stevensDemosendDailyBrief.ts6 matches

@swriddleโ€ขUpdated 6 days ago
13} from "../memoryUtils.ts";
14
15async function generateBriefingContent(anthropic, memories, today, isSunday) {
16 try {
17 const weekdaysHelp = generateWeekDays(today);
96}
97
98export async function sendDailyBriefing(chatId?: string, today?: DateTime) {
99 // Get API keys from environment
100 const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
135 const lastSunday = today.startOf("week").minus({ days: 1 });
136
137 // Fetch relevant memories using the utility function
138 const memories = await getRelevantMemories();
139
216}
217
218function generateWeekDays(today) {
219 let output = [];
220
239// console.log(weekDays);
240
241// Export a function that calls sendDailyBriefing with no parameters
242// This maintains backward compatibility with existing cron jobs
243export default async function (overrideToday?: DateTime) {
244 return await sendDailyBriefing(undefined, overrideToday);
245}

twitterCardstwitterCards.tsx1 match

@nbbaierโ€ขUpdated 1 week ago
17}
18
19export default async function(req: Request): Promise<Response> {
20 return html(`<html lang="en">
21 <head>

getFileEmail4 file matches

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

TwilioHelperFunctions

@vawogbemiโ€ขUpdated 2 months ago