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/$2?q=function&page=35&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 29176 results for "function"(5647ms)

voicemessagesDashboard.tsx1 match

@michaelwschultzUpdated 21 hours ago
3import type { VoiceNote } from "../../shared/types.ts";
4
5export default function Dashboard() {
6 const [voiceNotes, setVoiceNotes] = useState<VoiceNote[]>([]);
7 const [loading, setLoading] = useState(true);

voicemessagesApp.tsx1 match

@michaelwschultzUpdated 21 hours ago
11}
12
13export default function App() {
14 const [currentView, setCurrentView] = useState<"recorder" | "player" | "dashboard">("recorder");
15 const voiceNoteId = window.__VOICE_NOTE_ID__;

wakatime-readme-chartmain.tsx7 matches

@loadingUpdated 22 hours ago
40}
41
42function App() {
43 const [chartUrl, setChartUrl] = useState<string | null>(null);
44
57}
58
59function client() {
60 createRoot(document.getElementById("root")!).render(<App />);
61}
65}
66
67async function fetchWakaTimeData(): Promise<DataPoint[]> {
68 const response = await fetch("https://wakatime.com/share/@load1n9/899abefd-d814-4e99-b603-e94af0305d4a.json");
69 const data = await response.json();
82};
83
84async function generateChart(data: DataPoint[]): Promise<string> {
85 const width = 1000;
86 const height = 600;
164}
165
166function roundRect(
167 ctx: CanvasRenderingContext2D,
168 x: number,
190}
191
192function roundRectTop(
193 ctx: CanvasRenderingContext2D,
194 x: number,
219}
220
221export default async function server(request: Request): Promise<Response> {
222 const url = new URL(request.url);
223

base2getNewsBatches.js1 match

@tehaUpdated 22 hours ago
3import { sqlite } from "https://esm.town/v/YOUR_USERNAME/database"; // ⚠️ CHANGE YOUR_USERNAME
4
5export default async function(req: Request) {
6 const results = await sqlite.execute(`
7 SELECT batch_id, MIN(fetched_at) as fetch_time, COUNT(*) as article_count

base2getNewsByBatch.js1 match

@tehaUpdated 22 hours ago
4import { sqlite } from "https://esm.town/v/YOUR_USERNAME/database"; // ⚠️ CHANGE YOUR_USERNAME
5
6export default async function(req: Request) {
7 const url = new URL(req.url);
8 const batchId = url.pathname.split("/").pop(); // Get batchId from path

base2getLatestNews.js1 match

@tehaUpdated 22 hours ago
3import { sqlite } from "https://esm.town/v/YOUR_USERNAME/database"; // ⚠️ CHANGE YOUR_USERNAME
4
5export default async function(req: Request) {
6 const latestBatch = await sqlite.execute(`SELECT batch_id FROM news ORDER BY fetched_at DESC LIMIT 1`);
7 if (latestBatch.rows.length === 0) {

base2fetchAndStoreNews.js5 matches

@tehaUpdated 22 hours ago
1// Val Name: fetchAndStoreNews.js
2// Type: Scheduled Function (e.g., every 3 hours)
3
4import { blob } from "https://esm.town/v/std/blob";
9const GNEWS_API_KEY = "973de7360b49225b484c14a98fcc0a7f"; // It's better to store this as an environment variable in Val Town
10
11// Function to generate TTS and save it to blob storage
12async function generateTtsAudio(text, newsId) {
13 // Check if audio already exists
14 const existing = await sqlite.execute({
46}
47
48// Main function to be scheduled
49export default async function fetchAndStoreNews() {
50 console.log("Fetching fresh news...");
51 const response = await fetch(

base2database.js2 matches

@tehaUpdated 22 hours ago
2import { sqlite } from "https://esm.town/v/std/sqlite";
3
4// This function runs only once to set up the tables if they don't exist.
5async function initialize() {
6 await sqlite.execute(`
7 CREATE TABLE IF NOT EXISTS news (

base2index.html37 matches

@tehaUpdated 22 hours ago
211 const API_NEWS_BY_BATCH = '/api/news/batch/';
212
213 async function init() {
214 await lucide.createIcons();
215
251 }
252
253 function setupEventListeners() {
254 prevBtn.addEventListener('click', goToPrevious);
255 nextBtn.addEventListener('click', goToNext);
282 }
283
284 function handleAudioEnded() {
285 audioEnded = true;
286 console.log("Audio ended");
297
298
299 function speakNewsItem() {
300 audioEnded = false;
301 ttsAbortController.abort();
424
425
426 function stopSpeaking() {
427 ttsAbortController.abort();
428 ttsAudio.pause();
437
438
439 function userActive() {
440 carouselContainer.classList.remove('user-inactive');
441 carouselContainer.classList.add('user-active');
450 }
451
452 function startUserActivityMonitor() {
453 userActive();
454 }
455
456 function updateHeadline() {
457 if (newsItems.length === 0) {
458 headline.textContent = 'No news available.';
463 }
464
465 function updateFullContent() {
466 if (newsItems.length === 0) return;
467
489 }
490
491 async function goToNext() {
492 if (isTransitioning) return;
493 isTransitioning = true;
497 }
498
499 async function goToPrevious() {
500 if (isTransitioning) return;
501 isTransitioning = true;
505 }
506
507 function updateCarousel() {
508 updateHeadline();
509 updateFullContent();
515
516
517 async function restartVideo() {
518 stopSpeaking();
519 audioEnded = false;
535 }
536
537 function togglePlayPause() {
538 isPlaying = !isPlaying;
539
559
560
561 function updatePlayPauseIcon() {
562 const btn = document.getElementById('play-pause-btn');
563 btn.innerHTML = `<i data-lucide="${isPlaying ? 'pause' : 'play'}"></i>`;
565 }
566
567 function startAutoAdvance() {
568 stopAutoAdvance();
569 if (isPlaying) {
576 }
577
578 function stopAutoAdvance() {
579 if (autoAdvanceInterval) {
580 clearInterval(autoAdvanceInterval);
583 }
584
585 function toggleMute() {
586 if (video.volume > 0) {
587 lastVolume = video.volume;
597 userActive();
598 }
599 function updateVolume() {
600 const volume = parseFloat(volumeSlider.value);
601 video.volume = volume;
610 }
611 }
612 function updateVolumeIcon(volume) {
613 const btn = document.getElementById('mute-btn');
614 let iconName = 'volume-x';
620 }
621
622 function updateProgressBar() {
623 if (video.duration) {
624 const progress = (video.currentTime / video.duration) * 100;
628 }
629
630 function seekVideo(e) {
631 const rect = progressContainer.getBoundingClientRect();
632 const percent = (e.clientX - rect.left) / rect.width;
637 }
638
639 function updateTimeDisplay() {
640 if (video.duration) {
641 const currentTime = formatTime(video.currentTime);
645 }
646
647 function updateVideoDurationDisplay() {
648 if (video.duration) {
649 timeDisplay.textContent = `0:00 / ${formatTime(video.duration)}`;
653 }
654
655 function formatTime(seconds) {
656 if (!seconds || isNaN(seconds)) return '0:00';
657
661 }
662
663 function handleVideoEnded() {
664 // Let the audio ended event handle navigation
665 }
666
667 function showContentPanel() {
668 contentVisible = true;
669 newsContent.classList.add('active');
676 }
677
678 function hideContentPanel() {
679 contentVisible = false;
680 newsContent.classList.remove('active');
682 }
683
684 async function openHistoryPanel() {
685 loadingOverlay.style.display = 'flex';
686 loadingOverlay.querySelector('.loading-text').textContent = 'Loading news history...';
707 }
708
709 function populateHistoryPanel() {
710 historyList.innerHTML = '';
711
741 }
742
743 async function loadNewsBatch(batchId) {
744 loadingOverlay.style.display = 'flex';
745 loadingOverlay.querySelector('.loading-text').textContent = 'Loading news batch...';
777 }
778
779 function closeHistoryPanel() {
780 historyPanel.classList.remove('active');
781 userActive();
782 }
783
784 function toggleFullscreen() {
785 if (!document.fullscreenElement) {
786 document.querySelector('.carousel-container').requestFullscreen().catch(err => {
793 }
794
795 function updateFullscreenIcon() {
796 const icon = document.fullscreenElement ? 'minimize' : 'maximize';
797 fullscreenBtn.innerHTML = `<i data-lucide="${icon}"></i>`;
799 }
800
801 function handleMediaError(e) {
802 console.error('Media error:', e);
803 const mediaElement = e.target;
813 }
814
815 function showError(message) {
816 errorMessage.textContent = message;
817 errorMessage.classList.add('active');
822 }
823
824 function handleKeyboardShortcuts(e) {
825 if (e.code === 'Space') {
826 e.preventDefault();

base2main.tsx1 match

@tehaUpdated 22 hours ago
1export default async function (req: Request): Promise<Response> {
2 return Response.json({ ok: true })
3}
tuna

tuna9 file matches

@jxnblkUpdated 1 day ago
Simple functional CSS library for Val Town

getFileEmail4 file matches

@shouserUpdated 1 month 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.