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=37&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 7402 results for "function"(354ms)

JimeluStevensREADME.md2 matches

@luke_fโ€ขUpdated 4 days ago
16In a normal server environment, you would likely use a middleware [like this one](https://hono.dev/docs/getting-started/nodejs#serve-static-files) to serve static files. Some frameworks or deployment platforms automatically make any content inside a `public/` folder public.
17
18However in Val Town you need to handle this yourself, and it can be suprisingly difficult to read and serve files in a Val Town Project. This template uses helper functions from [stevekrouse/utils/serve-public](https://www.val.town/x/stevekrouse/utils/branch/main/code/serve-public/README.md), which handle reading project files in a way that will work across branches and forks, automatically transpiles typescript to javascript, and assigns content-types based on the file's extension.
19
20### `index.html`
26## CRUD API Routes
27
28This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
29
30## Errors

JimeluStevensREADME.md2 matches

@luke_fโ€ขUpdated 4 days ago
4
5* `migrations.ts` - code to set up the database tables the app needs
6* `queries.ts` - functions to run queries against those tables, which are imported and used in the main Hono server in `/backend/index.ts`
7
8## Migrations
18The queries file is where running the migrations happen in this app. It'd also be reasonable for that to happen in index.ts, or as is said above, for that line to be commented out, and only run when actual changes are made to your database schema.
19
20The queries file exports functions to get and write data. It relies on shared types and data imported from the `/shared` directory.

JimeluStevenspopulateMemoryIds.ts1 match

@luke_fโ€ขUpdated 4 days ago
4import { nanoid } from "https://esm.sh/nanoid@5.0.5";
5
6export default async function populateMemoryIds() {
7 try {
8 // Import SQLite module

JimeluStevenspopulateDemo.ts5 matches

@luke_fโ€ขUpdated 4 days ago
5
6// Create the memories_demo table
7async function createMemoriesDemoTable() {
8 try {
9 await sqlite.execute(`
25
26// Create a fake memory with proper ID and timestamps
27function createMemory(date, text, createdBy, tags, createdDateOffset = 0) {
28 const id = nanoid(10);
29 // Base date is April 5, 2025
375
376// Insert memories into the database
377async function insertDemoMemories() {
378 try {
379 // Clear existing data if any
406}
407
408// Main function to populate demo data
409export default async function populateDemo() {
410 try {
411 // Create the table

JimeluStevenspopulateCreatedBy.ts1 match

@luke_fโ€ขUpdated 4 days ago
2// Run this script manually to set createdBy based on memory content
3
4export default async function populateCreatedBy() {
5 try {
6 // Import SQLite module

JimeluStevensNotebookView.tsx1 match

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

JimeluStevensmigrateMemoriesDb.ts1 match

@luke_fโ€ขUpdated 4 days ago
2// Run this script manually to add new columns to the memories table
3
4export default async function migrateMemoriesDb() {
5 try {
6 // Import SQLite module

JimeluStevens.cursorrules15 matches

@luke_fโ€ขUpdated 4 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

JimeluStevenscronDailyBrief.ts1 match

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

JimeluStevensApp.tsx2 matches

@luke_fโ€ขUpdated 4 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;

getFileEmail4 file matches

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

TwilioHelperFunctions

@vawogbemiโ€ขUpdated 2 months ago