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/image-url.jpg%20%22Image%20title%22?q=function&page=87&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 20174 results for "function"(1137ms)

stevensDemogenerateFunFacts.ts8 matches

@Fewlโ€ขUpdated 2 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();

stevensDemo.cursorrules15 matches

@Fewlโ€ขUpdated 2 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

@Fewlโ€ขUpdated 2 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

@Fewlโ€ขUpdated 2 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;

Townieicons.tsx16 matches

@valdottownโ€ขUpdated 2 days ago
1/** @jsxImportSource https://esm.sh/react@18.2.0?dev */
2
3export function TownieIcon({
4 size = 24,
5 color = "currentColor",
50}
51
52export function Circle ({
53 filled,
54}: {
74}
75
76export function Square ({
77 size = 24,
78}: {
98
99// icons from https://lucide.dev
100export function SquarePenIcon () {
101 return (
102 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-square-pen-icon lucide-square-pen"><path d="M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"/></svg>
104}
105
106export function FileCode2Icon () {
107 return (
108 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-file-code2-icon lucide-file-code-2"><path d="M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="m5 12-3 3 3 3"/><path d="m9 18 3-3-3-3"/></svg>
110}
111
112export function SparklesIcon () {
113 return (
114 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-sparkles-icon lucide-sparkles"><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/><path d="M20 3v4"/><path d="M22 5h-4"/><path d="M4 17v2"/><path d="M5 18H3"/></svg>
116}
117
118export function EyeIcon () {
119 return (
120 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-eye-icon lucide-eye"><path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"/><circle cx="12" cy="12" r="3"/></svg>
122}
123
124export function ExternalLinkIcon () {
125 return (
126 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-external-link-icon lucide-external-link"><path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/></svg>
128}
129
130export function KeyRoundIcon () {
131 return (
132 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-key-round-icon lucide-key-round"><path d="M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z"/><circle cx="16.5" cy="7.5" r=".5" fill="currentColor"/></svg>
134}
135
136export function LockKeyholeIcon () {
137 return (
138 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-lock-keyhole-icon lucide-lock-keyhole"><circle cx="12" cy="16" r="1"/><rect x="3" y="10" width="18" height="12" rx="2"/><path d="M7 10V7a5 5 0 0 1 10 0v3"/></svg>
140}
141
142export function PlusIcon () {
143 return (
144 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-plus-icon lucide-plus"><path d="M5 12h14"/><path d="M12 5v14"/></svg>
146}
147
148export function ArrowUpIcon () {
149 return (
150 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-arrow-up-icon lucide-arrow-up"><path d="m5 12 7-7 7 7"/><path d="M12 19V5"/></svg>
152}
153
154export function RefreshIcon ({ size = 24 }: { size: number }) {
155 return (
156 <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-rotate-cw-icon lucide-rotate-cw"><path d="M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/></svg>
158}
159
160export function XIcon ({ size = 24 }: {
161 size?: number;
162}) {
166}
167
168export function VolumeOffIcon ({ size = 24 }) {
169 return (
170 <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-volume-off-icon lucide-volume-off"><path d="M16 9a5 5 0 0 1 .95 2.293"/><path d="M19.364 5.636a9 9 0 0 1 1.889 9.96"/><path d="m2 2 20 20"/><path d="m7 7-.587.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298V11"/><path d="M9.828 4.172A.686.686 0 0 1 11 4.657v.686"/></svg>
172}
173
174export function Volume2Icon ({ size = 24 }) {
175 return (
176 <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-volume2-icon lucide-volume-2"><path d="M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z"/><path d="M16 9a5 5 0 0 1 0 6"/><path d="M19.364 18.364a9 9 0 0 0 0-12.728"/></svg>

untitled-5703README.md1 match

@angelaphiriโ€ขUpdated 2 days ago
19โ”‚ โ”œโ”€โ”€ database/
20โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
21โ”‚ โ”‚ โ””โ”€โ”€ queries.ts # DB query functions
22โ”‚ โ”œโ”€โ”€ index.ts # Main API entry point
23โ”œโ”€โ”€ frontend/

hdindex.html3 matches

@quartexโ€ขUpdated 2 days ago
1export default function(req) {
2 return new Response(
3 `<!DOCTYPE html>
421
422 <script>
423 document.addEventListener('DOMContentLoaded', function() {
424 const faqQuestions = document.querySelectorAll('.faq-question');
425
426 faqQuestions.forEach(question => {
427 question.addEventListener('click', function() {
428 const faqItem = this.parentElement;
429 const isActive = faqItem.classList.contains('active');

test-multiembedt.tsx2 matches

@temptempโ€ขUpdated 2 days ago
7 "Accept-Language": "en-US,en;q=0.9"
8};
9export default async function(req: Request): Promise<Response> {
10 const API_URL: string = "https://api.val.town";
11 async function proxiedFetch(input: string | URL, requestInit?: RequestInit) {
12 let query = new URLSearchParams({
13 url: input.toString(),

untitled-5703index.js21 matches

@angelaphiriโ€ขUpdated 2 days ago
56
57// Tab switching
58function switchTab(tabName) {
59 // Update active tab
60 state.activeTab = tabName;
85
86// Authentication
87function login() {
88 const username = elements.usernameInput.value.trim();
89 if (username) {
99}
100
101function logout() {
102 state.currentUsername = '';
103 localStorage.removeItem('username');
110}
111
112function updateAuthUI() {
113 if (state.currentUsername) {
114 elements.loginSection.classList.add('hidden');
131}
132
133// Jobs functionality
134async function fetchJobs() {
135 try {
136 const response = await fetch('/api/jobs');
145}
146
147function renderJobs() {
148 if (state.jobs.length === 0) {
149 elements.jobsList.innerHTML = '<p class="text-gray-500">No jobs available. Be the first to post one!</p>';
168}
169
170async function submitJob(event) {
171 event.preventDefault();
172
221}
222
223// Chat functionality
224function enableChat() {
225 elements.chatInput.disabled = false;
226 elements.sendMessageButton.disabled = false;
228}
229
230function disableChat() {
231 elements.chatInput.disabled = true;
232 elements.sendMessageButton.disabled = true;
234}
235
236async function fetchMessages() {
237 try {
238 const response = await fetch('/api/messages');
253}
254
255function renderMessages() {
256 if (state.messages.length === 0) {
257 elements.chatMessages.innerHTML = '<p class="text-center text-gray-500">No messages yet. Start the conversation!</p>';
278}
279
280function scrollChatToBottom() {
281 elements.chatMessages.scrollTop = elements.chatMessages.scrollHeight;
282}
283
284async function sendMessage() {
285 const content = elements.chatInput.value.trim();
286 if (!content || !state.currentUsername) return;
313}
314
315// Utility functions
316function formatDate(dateString) {
317 const date = new Date(dateString);
318 return date.toLocaleString();
319}
320
321function escapeHtml(unsafe) {
322 return unsafe
323 .replace(/&/g, "&amp;")
329
330// Setup polling for chat messages
331function setupMessagePolling() {
332 // Initial fetch
333 fetchMessages();
338
339// Event listeners
340function setupEventListeners() {
341 // Tab switching
342 elements.jobsTab.addEventListener('click', () => switchTab('jobs'));
362
363// Initialize the app
364function init() {
365 // Setup event listeners
366 setupEventListeners();

untitled-5703queries.ts5 matches

@angelaphiriโ€ขUpdated 2 days ago
32
33// Job queries
34export async function getAllJobs(): Promise<Job[]> {
35 const result = await sqlite.execute(
36 `SELECT * FROM ${JOBS_TABLE} ORDER BY created_at DESC`
39}
40
41export async function getJob(id: number): Promise<Job | null> {
42 const result = await sqlite.execute(
43 `SELECT * FROM ${JOBS_TABLE} WHERE id = ?`,
47}
48
49export async function createJob(job: JobInput): Promise<Job> {
50 const created_at = new Date().toISOString();
51 const result = await sqlite.execute(
59
60// Message queries
61export async function getMessages(limit = 50): Promise<Message[]> {
62 const result = await sqlite.execute(
63 `SELECT * FROM ${MESSAGES_TABLE} ORDER BY created_at DESC LIMIT ?`,
67}
68
69export async function createMessage(message: MessageInput): Promise<Message> {
70 const created_at = new Date().toISOString();
71 const result = await sqlite.execute(

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.