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//%22?q=function&page=3&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 40461 results for "function"(811ms)

untitled-8264Main2.ts12 matches

@ziggyware•Updated 7 hours ago
1export default async function (req: Request): Promise<Response> {
2 const html = `<!DOCTYPE html>
3<html lang="en">
54 const errorBox = document.getElementById("errorBox");
55
56 function showError(e) {
57 console.error(e);
58 errorBox.style.display = "block";
61
62 // DPR-aware resize
63 function resize() {
64 const dpr = Math.min(window.devicePixelRatio || 1, 2);
65 const w = Math.floor(window.innerWidth * dpr);
173 \`;
174
175 function compileShader(type, src) {
176 const s = gl.createShader(type);
177 gl.shaderSource(s, src);
199 gl.bindVertexArray(vao);
200
201 function createAttrib(data, attribName, usage) {
202 const loc = gl.getAttribLocation(program, attribName);
203 if (loc === -1) throw new Error("Attrib not found or optimized out: " + attribName);
225
226 // Matrices
227 function mat4Perspective(fovDeg, aspect, near, far) {
228 const f = 1.0 / Math.tan((fovDeg * Math.PI) / 360);
229 const nf = 1 / (near - far);
236 return out;
237 }
238 function subtract(a, b) { return [a[0]-b[0], a[1]-b[1], a[2]-b[2]]; }
239 function normalize(v) {
240 const l = Math.hypot(v[0], v[1], v[2]) || 1;
241 return [v[0]/l, v[1]/l, v[2]/l];
242 }
243 function cross(a, b) {
244 return [a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]];
245 }
246 function dot(a, b) { return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; }
247 function mat4LookAt(eye, target, up) {
248 const z = normalize(subtract(eye, target));
249 const x = normalize(cross(up, z));
284
285 // Render loop
286 function render(ts) {
287 // Update audio only if ready
288 if (analyser) {

qbatindex.tsx2 matches

@wilhelm•Updated 8 hours ago
2import * as THREE from "three";
3
4// Import Bluesky OAuth functionality
5import { LoginComponent } from "./login-component.ts";
6import { blueskyAuth, type BlueskySession, type SavedGame } from "./bluesky-oauth.ts";
1535 }
1536
1537 // Save game functionality
1538 private async saveGame() {
1539 if (!this.blueskySession) {

chatterchatterApp.js6 matches

@yawnxyz•Updated 9 hours ago
90} from './contentRenderers.js';
91
92export default function chatterApp() {
93 return {
94 // Page routing
626 const combo = parts.join('+');
627 const handler = this.keyBindings && this.keyBindings[combo];
628 if (typeof handler === 'function') {
629 e.preventDefault();
630 handler(this);
637 try {
638 const handler = this.keyBindings && this.keyBindings[combo];
639 if (typeof handler === 'function') handler(this);
640 else if (combo === 'mod+shift+b') this.toggleChatSettings();
641 } catch (_) { /* ignore */ }
691 try {
692 const el = document.querySelector('textarea');
693 if (el && typeof el.focus === 'function') {
694 el.focus();
695 // Put caret at end
1530 const doScroll = () => {
1531 try {
1532 if (scrollerEl && typeof scrollerEl.scrollTo === 'function') {
1533 scrollerEl.scrollTop = scrollerEl.scrollHeight;
1534 } else if (scrollerEl) {
1540 } catch (_) {}
1541 };
1542 if (typeof this.$nextTick === 'function') this.$nextTick(doScroll); else requestAnimationFrame(doScroll);
1543 } catch (_) {}
1544 },

chatterdataIO.js5 matches

@yawnxyz•Updated 9 hours ago
7} from './core/chatCore.js';
8
9export async function onExportData(ctx) {
10 try {
11 ctx.dataStatusText = 'preparing export...';
31}
32
33export async function copyCurrentChatJson(ctx) {
34 try {
35 if (!ctx.db) return;
59}
60
61export function onClickImportReplace(ctx) {
62 try {
63 ctx.pendingImportMode = 'replace';
67}
68
69export function onClickImportAppend(ctx) {
70 try {
71 ctx.pendingImportMode = 'append';
75}
76
77export async function onImportFileChange(ctx, e) {
78 try {
79 const files = e && e.target && e.target.files ? e.target.files : null;

chatterchatCore.js32 matches

@yawnxyz•Updated 9 hours ago
1// Core chat + DB helpers extracted from chatterApp
2
3export async function initDb(state) {
4 try {
5 state.db = new window.Dexie('chat_db');
58}
59
60export async function loadChats(state) {
61 try {
62 const rows = await state.db.chats.orderBy('createdAt').reverse().toArray();
65}
66
67export async function loadFolders(state) {
68 try {
69 const rows = await state.db.folders.orderBy('order').toArray();
72}
73
74export async function createFolder(state) {
75 try {
76 const createdAt = Date.now();
84}
85
86export function startEditingFolder(state, id, currentName) {
87 state.editingFolderId = id;
88 state.editingFolderName = currentName || '';
95}
96
97export async function commitEditingFolder(state) {
98 const rawId = state.editingFolderId;
99 const id = typeof rawId === 'string' ? Number(rawId) : rawId;
109}
110
111export function cancelEditingFolder(state) {
112 state.editingFolderId = null;
113 state.editingFolderName = '';
114}
115
116export async function toggleFolderCollapsed(state, id) {
117 try {
118 const f = await state.db.folders.get(id);
123}
124
125export async function moveChatToFolder(state, chatId, folderId) {
126 try {
127 if (!chatId) return;
134}
135
136export function baseChats(state) {
137 try {
138 const list = (state.chats || []).filter(c => !c.folderId);
141}
142
143export function chatsInFolder(state, folderId) {
144 try { return (state.chats || []).filter(c => c.folderId === folderId); } catch (_) { return []; }
145}
146
147export async function createNewChat(state) {
148 const input = (state.chatInput || '').trim();
149 // If no content, do NOT create a persisted chat. Switch to ephemeral new chat.
175}
176
177export async function selectChat(state, id) {
178 if (id === state.ephemeralChatId) {
179 state.currentChatId = null;
414 state.sidebarOpen = false;
415 state.$nextTick && state.$nextTick(() => state.scrollToBottom && state.scrollToBottom());
416 try { typeof state.updateDocumentTitle === 'function' && state.updateDocumentTitle(); } catch (_) { /* ignore */ }
417}
418
419export function startEditingChat(state, id, currentTitle) {
420 state.editingChatId = id;
421 state.editingChatTitle = currentTitle || '';
428}
429
430export async function commitEditingChat(state) {
431 const rawId = state.editingChatId;
432 const id = typeof rawId === 'string' ? Number(rawId) : rawId;
445 state.editingChatId = null;
446 state.editingChatTitle = '';
447 try { typeof state.updateDocumentTitle === 'function' && state.updateDocumentTitle(); } catch (_) { /* ignore */ }
448}
449
450export function cancelEditingChat(state) {
451 state.editingChatId = null;
452 state.editingChatTitle = '';
453}
454
455export async function deleteChat(state, id) {
456 try {
457 if (!state.db) return;
473}
474
475export async function duplicateChat(state, id) {
476 try {
477 if (!state || !state.db) return;
498}
499
500export async function ensureChatExistsForEdits(state, opts = {}) {
501 try {
502 const force = !!opts.force;
515 state.currentChatId = id;
516 state.activeSearchId = id;
517 try { typeof state.updateDocumentTitle === 'function' && state.updateDocumentTitle(); } catch (_) { /* ignore */ }
518 // Initialize per-chat prompt defaults
519 try { await state.db.chats.update(id, { systemPromptId: null, systemPromptText: '' }); } catch (_) { /* ignore */ }
522}
523
524export async function ensureMessagePersisted(state, idx) {
525 try {
526 const m = state.messages?.[idx];
555}
556
557export async function persistMessageAtIndex(state, idx) {
558 try {
559 const m = state.messages?.[idx];
575}
576
577export async function deleteMessage(state, idx) {
578 try {
579 if (!Array.isArray(state.messages) || idx == null || idx < 0 || idx >= state.messages.length) return;
606}
607
608export async function deleteMessagesBelow(state, idx) {
609 try {
610 if (!Array.isArray(state.messages) || idx == null || idx < 0 || idx >= state.messages.length) return;
652}
653
654export async function rerunFromUser(state, idx) {
655 try {
656 if (state.isStreamingForCurrent) return;
686}
687
688export async function sendMessage(state) {
689 const text = (state.chatInput || '').trim();
690 if (!text) return;
720}
721
722function slugifyTitle(title) {
723 try {
724 const s = String(title || '').toLowerCase();
732// --- Data export/import helpers ---
733
734export async function exportAllData(state) {
735 try {
736 if (!state || !state.db) {
757}
758
759export async function importDataReplace(state, input) {
760 const parsed = (() => {
761 try {
810}
811
812export async function importDataAppend(state, input) {
813 const parsed = (() => {
814 try {

chatterindex.html2 matches

@yawnxyz•Updated 9 hours ago
17 <meta property="twitter:image" content="https://imagedelivery.net/TysXuIP7qbyd6gh5m_zQIQ/1764955c-dd1f-4745-2aed-3b59717e3d00/medium">
18 <script>
19 window.deferLoadingAlpine = function (start) { window._startAlpine = start; };
20 </script>
21 <!-- Offline-first vendor (populated by deno task vendor:fetch) -->
33 <script>
34 // Minimal theme bootstrap: uses localStorage 'theme' = 'light' | 'dark' | 'auto'
35 (function() {
36 try {
37 var pref = localStorage.getItem('theme') || 'auto';

qbatbluesky-oauth.ts1 match

@wilhelm•Updated 9 hours ago
1// Bluesky OAuth functionality for QBAT game
2import {
3 BrowserOAuthClient,

boombox-generatorscad.ts1 match

@danfishgold•Updated 10 hours ago
1import { boomboxData } from "./boombox.js";
2
3export function generateScadCode(code: string | undefined) {
4 const bb = boomboxData();
5 if (code) {

boombox-generatorboombox.js5 matches

@danfishgold•Updated 10 hours ago
1import LZString from "https://esm.sh/lz-string";
2
3export function boomboxData() {
4 const data = {
5 showDragHandles: false,
369}
370
371function svgPolygonPath([firstPoint, ...restPoints]) {
372 return [
373 `M${firstPoint[0]},${firstPoint[1]}`,
377}
378
379function clamp(min, val, max) {
380 return Math.min(Math.max(val, min), max);
381}
382
383function random(min, max, n = 1) {
384 const arr = new Array(n).fill(0).map(() => Math.random());
385 return min + average(arr) * (max - min);
386}
387
388function average(arr) {
389 return arr.reduce((a, b) => a + b, 0) / arr.length;
390}

weatherAppmain.tsx4 matches

@dcm31•Updated 10 hours ago
10];
11
12function App() {
13 const [city, setCity] = useState(cities[0]);
14 const [weather, setWeather] = useState(null);
15
16 useEffect(() => {
17 async function fetchWeather() {
18 const url = `https://api.open-meteo.com/v1/forecast?latitude=${city.lat}&longitude=${city.lon}&current_weather=true`;
19 const res = await fetch(url);
49}
50
51function client() {
52 createRoot(document.getElementById("root")).render(<App />);
53}
54if (typeof document !== "undefined") client();
55
56export default async function server(request: Request): Promise<Response> {
57 return new Response(`<!DOCTYPE html>
58<html>

ratelimit4 file matches

@unkey•Updated 1 month ago
Rate limit your serverless functions

discordWebhook2 file matches

@stevekrouse•Updated 2 months ago
Helper function to send Discord messages
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.