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/$%7Bart_info.art.src%7D?q=function&page=25&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 18135 results for "function"(1396ms)

a55fa86a2ad_populateCreatedBy.ts1 match

@vtTestLocal•Updated 22 hours 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

a55fa86a2ad_README.md2 matches

@vtTestLocal•Updated 22 hours 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

a55fa86a2ad_README.md2 matches

@vtTestLocal•Updated 22 hours 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.

a55fa86a2ad_queries.ts4 matches

@vtTestLocal•Updated 22 hours ago
6const tableName = "memories_demo";
7
8export async function getAllMemories(): Promise<Memory[]> {
9 const result = await sqlite.execute(
10 `SELECT id, date, text, createdBy, createdDate, tags FROM ${tableName}
23}
24
25export async function createMemory(
26 memory: Omit<Memory, "id">
27): Promise<Memory> {
51}
52
53export async function updateMemory(
54 id: string,
55 memory: Partial<Omit<Memory, "id">>
70}
71
72export async function deleteMemory(id: string): Promise<void> {
73 await sqlite.execute(`DELETE FROM ${tableName} WHERE id = ?`, [id]);
74}

a55fa86a2ad_NotebookView.tsx1 match

@vtTestLocal•Updated 22 hours ago
54}
55
56export function NotebookView({ onClose, avatarUrl }: NotebookViewProps) {
57 const [memories, setMemories] = useState<Memory[]>([]);
58 const [loading, setLoading] = useState(true);

a55fa86a2ad_App.tsx2 matches

@vtTestLocal•Updated 22 hours 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;

a221c7cb8ae_handleUSPSEmail.ts3 matches

@vtTestLocal•Updated 22 hours ago
4const RECIPIENTS = ["Geoffrey", "Maggie"] as const;
5
6function parseDateFromSubject(subject: string): string | null {
7 const match = subject.match(/(\w{3}), (\d{1,2}\/\d{1,2})/);
8 if (match) {
19};
20
21async function analyzeHtmlContent(
22 anthropic: Anthropic,
23 htmlContent: string,
80}
81
82export default async function (e: Email) {
83 console.log("email content");
84 console.log(e.html);

a221c7cb8ae_getWeather.ts5 matches

@vtTestLocal•Updated 22 hours ago
8const TABLE_NAME = `memories`;
9
10function summarizeWeather(weather: WeatherResponse) {
11 const summarizeDay = (day: WeatherResponse["weather"][number]) => ({
12 date: day.date,
25}
26
27async function generateConciseWeatherSummary(weatherDay) {
28 try {
29 // Get API key from environment
83}
84
85async function deleteExistingForecast(date: string) {
86 await sqlite.execute(
87 `
93}
94
95async function insertForecast(date: string, forecast: string) {
96 const { nanoid } = await import("https://esm.sh/nanoid@5.0.5");
97
112}
113
114export default async function getWeatherForecast(interval: number) {
115 const weather = await getWeather("Washington, DC");
116 console.log({ weather });

a221c7cb8ae_handleTelegramMessage.ts5 matches

@vtTestLocal•Updated 22 hours 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) {

a221c7cb8ae_generateFunFacts.ts8 matches

@vtTestLocal•Updated 22 hours 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();

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 2 weeks ago
Simple functional CSS library for Val Town
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
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": "*",